Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual on does not respect manual watering time set #45

Open
schneemaier opened this issue May 24, 2023 · 3 comments
Open

Manual on does not respect manual watering time set #45

schneemaier opened this issue May 24, 2023 · 3 comments

Comments

@schneemaier
Copy link

Hi,

I am trying to turn on a zone manually to run it for the set manual watering time. I am able to push the manual watering time (10 minutes), but when I turn the zone on the second left value is 5+ hours.

This is the code I am using

#!/usr/bin/python

import asyncio
from time import sleep
from bleak import BleakScanner  # type: ignore - bleak has bad export types

from melnor_bluetooth.device import Device

ADDRESS = "XX:XX:XX:XX:XX:XX"  # fill with your device mac address

async def main():
    ble_device = await BleakScanner.find_device_by_address(ADDRESS)
    if ble_device is not None:
        device = Device(ble_device)
        await device.connect()
        await device.fetch_state()

        print(device)

        await device.zone1.set_manual_watering_minutes(10)
        await device.zone1.set_is_watering(True)
        await device.push_state()

        sleep(10)

        await device.fetch_state()

        print(device)

        await device.disconnect()

asyncio.run(main())

And here is the result:

Device(
    battery=96
    valves=(
      Valve(id=0|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)
Device(
    battery=89
    valves=(
      Valve(id=0|is_watering=True|manual_minutes=10|seconds_left=1684886359)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)
Disconnected from XX:XX:XX:XX:XX:XX

Not sure what I am doing wrong.

I wrote another script to test how the seconds_left field value changes if I start the timer from the melnor app. It seems that the value is "random" and does not change during the time of the timer.

Example this is what I get when the timer is set to 1 minute (reading is done every 1 second with await device.fetch_state()):

Device(
    battery=80
    valves=(
      Valve(id=0|is_watering=True|manual_minutes=1|seconds_left=1684868920)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)
Device(
    battery=80
    valves=(
      Valve(id=0|is_watering=True|manual_minutes=1|seconds_left=1684868920)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)
Device(
    battery=80
    valves=(
      Valve(id=0|is_watering=True|manual_minutes=1|seconds_left=1684868920)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)
## Timer expired here ...
Device(
    battery=89
    valves=(
      Valve(id=0|is_watering=False|manual_minutes=1|seconds_left=0)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)

@schneemaier
Copy link
Author

So it seems that the seconds_left value is the unix epoch when the watering will end, the label is a bit misleading.

If I convert the epoch back to date from the first script it shows the 10 minutes as end time. However in the Menlor app I still see 5+ hours. Not sure what is going wrong there

@vanstinator
Copy link
Owner

Is the machine you're running the script on and the device running the Melnor app set to the same timezone?

The device clock is a simple monotonic timer, and the app converts the value back to a localized date using some complex logic. I've reverse engineered the logic as best I can, but I wouldn't be surprised if there are bugs.

The seconds_left field is definitely labeled incorrectly. Since we're still shipping pre-release builds I'll ship an updated field and deprecate the current one. Sorry for the confusion there!

@schneemaier
Copy link
Author

schneemaier commented Jun 2, 2023

Thanks for the update.

I am not sure how to set the timezone for the device. I guess it syncs to the phone where the app is installed. Both the computer and the phone are in the same timezone (EDT)

Just to confirm:

  1. When I send a manual 10 minute on command it is on for 10 minutes. However I get weird time display in the melnor app, see attached picture
i@RaspiZeroW:~/Workspace/melnor-bluetooth $ ./zone.py 
Current time:  2023-06-01 20:01:23.784697   End time:  2023-06-01 20:11:12
Device(
    battery=89
    valves=(
      Valve(id=0|is_watering=True|manual_minutes=10|seconds_left=1685664672)
      Valve(id=1|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=2|is_watering=False|manual_minutes=20|seconds_left=0)
      Valve(id=3|is_watering=False|manual_minutes=20|seconds_left=0)
    )
)
Disconnected from XXXXXXXXXXXXXXXX
pi@RaspiZeroW:~/Workspace/melnor-bluetooth $

Screenshot_20230601-200232
BTW 300 minutes is 5 hours, which is the current time difference between GMT and EDT
2. When I send a manual command it turns off the program for every valve. Maybe this is intentional, but I am not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants