donavanbecker / homebridge-rainbird

The Homebridge RainBird plugin allows you to access your RainBird Controller from HomeKit with Homebridge.
ISC License
20 stars 0 forks source link

Feature Request: Correctly show Manual/Automatic program state #423

Closed dacarson closed 1 year ago

dacarson commented 1 year ago

Problem

In the Eve app, the irrigation system is always shown as Manual, even when there are program scheduled.

Solution

The ESP-ME3 physical unit only has two operating modes, Auto and Off. I suspect all physical Rainbirds units to have these two modes. The user can initiate a manual irrigation cycle while in Auto mode, but once that finishes, it reverts back to Auto. At startup, the plugin currently detects to see if the physical unit is Off and logs an error message. 
I propose that the plugin default the ProgramMode to PROGRAM_SCHEDULED, and when it detects a user initiated manual cycle running it switches ProgramMode to PROGRAM_SCHEDULED_MANUALMODE. When that finishes, default back to PROGRAM_SCHEDULED.

Alternatives

No response

Additional context

No response

mantorok1 commented 1 year ago

Hi @dacarson, I've started to take a look at this enhancement. Initially I was thinking I could determine that the RainBird is in "manual" mode by checking if a zone is currently running but there is no program running. However, this is not going to work as it's possible to start a program manually too. Do you know a way using the RainBird API to determine if a zone and/or program was started manually?

dacarson commented 1 year ago

In my opinion, I think the default mode should be automatic mode. The physical unit only has Off and Auto. The plugin detects if the unit is in the Off mode only at startup, in RainBirdService.ts: https://github.com/donavanbecker/homebridge-rainbird/blob/fea6244b3ead791ed26583ee5fe0b8254d7ea188/src/RainBird/RainBirdService.ts#L108 (BTW, I have not tested to see what happens if you manually switch the unit to Off after the plugin has been initialised) So the rest of the time the unit is in Auto mode - meaning that it will run defined PGMs.

The unit switches to Manual only when it is manually running a zone or program. We know that it is running manually as we noted here: https://github.com/donavanbecker/homebridge-rainbird/issues/395#issuecomment-1335961736 When I manually run a zone or program via their app or via the physical unit, I get the same PGM 4 response at least on my ESP-ME3.

So I think we should default to PROGRAM_SCHEDULED, unless we manually start or detect that a manual run is happening and then switch to PROGRAM_SCHEDULED_MANUALMODE. When completed, we should switch back to PROGRAM_SCHEDULED.

At this point, I don't know how to query the RainBird to see if it has any programs set and therefore use NO_PROGRAM_SCHEDULED, but I think it is safe to assume that there is at least one program set.

allenporter commented 1 year ago

@dacarson I've done some work in https://github.com/allenporter/pyrainbird/issues/92 to expose schedules, though only tested on TM2. Happy to share what i've discovered. It's fairly involved.

dacarson commented 1 year ago

@allenporter Thanks. For this particular feature, I think we just need to know if a schedule exists and not what the actual schedule is. If a schedule does not exist, it should use NO_PROGRAM_SCHEDULED, if a schedule does exist then the mode should be PROGRAM_SCHEDULED, and if a manual run is currently executing then the mode should be PROGRAM_SCHEDULED_MANUALMODE.

allenporter commented 1 year ago

Ok, I am familiar with the tm2 schedule response for program based controllers and there are basically 3 sets of commands:

So perhaps you can get away with only looking at one of the first two sets of commands. The PRs linked from the issue have lots of examples with tests and sample data if you are interested in looking closer.

My impression is there are non program based controllers that still have some kind of a schedule but I don't have one to know all the details.

mantorok1 commented 1 year ago

@allenporter, thanks so much for that info. Looks like you've put quite a bit of effort into it. Well done!

@dacarson, can you please confirm that for your ME3 if you manually start say program 0 (ie. A) then the the API will report it as program 4 is running. If so that's quite different to how my TM2 works.

Here's the CurrentZoneState response (BB) I see when I start program A manually:

[1/29/2023, 6:33:56 AM] [RainBird] [192.168.1.105] Response: [187,0,4,0,4,56,0,0,1,0,8,1] [CurrentZoneStateResponse]

And here is what it looks like if program A is started via a RainBird schedule:

[1/29/2023, 6:45:56 AM] [RainBird] [192.168.1.105] Response: [187,0,0,4,4,20,0,0,1,0,128,1] [CurrentZoneStateResponse]

The time remaining is in the 5th & 6th numbers, the current zone is the 9th number, the current program is the 10th number and the 12th (last) number indicates that it's running. I'm not sure which one shows that a program was started manually or via a schedule. It could the 3rd, 4th or 11th number which are different but I'm not sure.

dacarson commented 1 year ago

Checking the logs from last night when it ran a scheduled program start, I see these responses (for page 0 and then page 1):

[1/28/2023, 6:04:17 PM] [RainBird] [192.168.1.157] Request:  [59,0] [CurrentZoneStateRequest]
[1/28/2023, 6:04:17 PM] [RainBird] [192.168.1.157] Response: [187,0,0,1,2,0,0] [CurrentZoneStateResponse]
[1/28/2023, 6:04:17 PM] [RainBird] [192.168.1.157] Request:  [59,1] [CurrentZoneStateRequest]
[1/28/2023, 6:04:17 PM] [RainBird] [192.168.1.157] Response: [187,1,1,1,176,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] [CurrentZoneStateResponse]
[1/28/2023, 6:04:17 PM] [RainBird] Program A: Running
[1/28/2023, 6:04:17 PM] [RainBird] Zone 1: Running

When I open the app, go to the manual page, and under '-- Or Run a program -- ' tap on 'PGM A' to manually start program 0, I get this:

[1/29/2023, 9:06:17 AM] [RainBird] [192.168.1.157] Request:  [59,0] [CurrentZoneStateRequest]
[1/29/2023, 9:06:17 AM] [RainBird] [192.168.1.157] Response: [187,0,0,1,2,0,0] [CurrentZoneStateResponse]
[1/29/2023, 9:06:17 AM] [RainBird] [192.168.1.157] Request:  [59,1] [CurrentZoneStateRequest]
[1/29/2023, 9:06:17 AM] [RainBird] [192.168.1.157] Response: [187,1,1,1,238,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] [CurrentZoneStateResponse]
[1/29/2023, 9:06:17 AM] [RainBird] Program A: Running
[1/29/2023, 9:06:17 AM] [RainBird] Zone 1: Running 

Similar to your unit, it looks like there is no difference between a manually started PGM run and a schedule started PGM run.

This is different to when I do a 'Quick Run' or a '-- Or Set Custom Watering --' which reports that it is running program 4 / PGM E. Below is a 'Quick Run' that does all zones.

[1/29/2023, 9:32:17 AM] [RainBird] [192.168.1.157] Request:  [59,0] [CurrentZoneStateRequest]
[1/29/2023, 9:32:17 AM] [RainBird] [192.168.1.157] Response: [187,0,4,1,2,0,0] [CurrentZoneStateResponse]
[1/29/2023, 9:32:17 AM] [RainBird] [192.168.1.157] Request:  [59,1] [CurrentZoneStateRequest]
[1/29/2023, 9:32:17 AM] [RainBird] [192.168.1.157] Response: [187,1,0,1,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] [CurrentZoneStateResponse]
[1/29/2023, 9:32:17 AM] [RainBird] Zone 1: Running

What is interesting to me here is page 0, 3rd number is the program (program 4 / PGM E) and from page 1, I see that the 3rd number reports a 0. From above, when running PGM A, page 1 response's 3rd number is a 1. So I suspect that:

BB 01 xx zn s2 s1
xx = running a program (1) or running custom run (0)
zn = current zone
s2 = seconds
s1 = seconds

Though I think I need to create a second program, PGM B, to really test this out.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This issue has been closed as no further activity has occurred.