I was tearing my hair out for a while this afternoon, because I had coded something that should have been super-simple, and suddenly my OpenSprinkler binding was behaving super weirdly. However, I think I’ve figured out what was causing it - or at least how to cause it to misbehave and therefore how to avoid triggering the misbehaviour. However, in the hope of avoiding others having to follow in my footsteps, I hope posting this can be useful in fixing whatever is going on behind the scenes.
I have three active stations on my OpenSprinkler - one that does a lawn and veggie beds, and two that do all the garden beds. The lawn and veggie beds station runs on different logic to the other two, but the other two I always want to run in sequence. Therefore, I had coded the following rule:
rule "run front yard after running garden beds"
when
Item waterGardenBeds changed from ON to OFF
then
waterFrontYard.sendCommand(ON)
end
I have a separate rule to create a timer to turn the stations off a certain amount of time after they are turned on, but that was working fine. However, the behaviour I was seeing was:
- after starting the system from fresh (originally on 3.1.0, but updated in my frustration to 3.2.0.M5), using an individual toggle switch in the OH interface to turn on (for example) the lawn watering would work as expected, and appear in the log as:
15:32:04.554 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'waterVeggiesLawn' received command ON
15:32:04.554 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'waterVeggiesLawn' predicted to become ON
15:32:04.556 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'waterVeggiesLawn' changed from OFF to ON
15:32:04.556 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gWateringStations' changed from OFF to ON through waterVeggiesLawn
15:32:04.557 [INFO ] [nhab.core.model.script.watering.rules] - Watering turned on - timer set for: 15 minutes.
- I could then manually turn off that station, and manually turn on the first of the other stations - again, responding as expected:
15:32:36.709 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'waterVeggiesLawn' received command OFF
15:32:36.710 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'waterVeggiesLawn' predicted to become OFF
15:32:36.710 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'waterVeggiesLawn' changed from ON to OFF
15:32:36.711 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gWateringStations' changed from ON to OFF through waterVeggiesLawn
15:32:51.092 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'waterGardenBeds' received command ON
15:32:51.093 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'waterGardenBeds' predicted to become ON
15:32:51.094 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'waterGardenBeds' changed from OFF to ON
15:32:51.094 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gWateringStations' changed from OFF to ON through waterGardenBeds
15:32:51.095 [INFO ] [nhab.core.model.script.watering.rules] - Watering turned on - timer set for: 15 minutes.
- However, here’s where it gets weird. If I turned off the
waterGardenBeds
item, it would trigger the rule given above, but not with the expected results:
15:33:12.852 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'waterGardenBeds' received command OFF
15:33:12.853 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'waterGardenBeds' predicted to become OFF
15:33:12.854 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'waterGardenBeds' changed from ON to OFF
15:33:12.854 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gWateringStations' changed from ON to OFF through waterGardenBeds
15:33:12.855 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'waterFrontYard' received command ON
15:33:12.856 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'waterFrontYard' predicted to become ON
15:33:12.856 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'waterFrontYard' changed from OFF to ON
15:33:12.857 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gWateringStations' changed from OFF to ON through waterFrontYard
15:33:12.858 [INFO ] [nhab.core.model.script.watering.rules] - Watering turned on - timer set for: 15 minutes.
15:33:16.360 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'waterFrontYard' changed from ON to OFF
15:33:16.361 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gWateringStations' changed from ON to OFF through waterFrontYard
As you can see, the station that was meant to be turned on by the above rule did initially turn on, but then turned off again within a matter of seconds. Once this had happened, any attempt to turn on any station manually (through OH) would receive the same results - on, then back off again almost immediately.
When checking the OpenSprinkler interface after this happened, I discovered a weird thing on the display: the stations weren’t all just on or off - they were in a “Scheduled” state (I’ve tried to attach a screenshot here, but it didn’t work - I might try in a reply).
After using the OpenSprinkler app to send a “stop all stations” command (returning them all to the normal “off” state), I could once again turn on individual stations through the OH interface, but as soon as I triggered the rule at the start of this post, I got the OFF->ON->OFF behaviour again, along with the “Scheduled” state in the OpenSprinkler interface.
In the end, I decided that a likely culprit was the rapid sequence of commands (possibly even overlapping?) through the OpenSprinkler API, so I added a 5 second delay to the rule as follows:
rule "run front yard after running garden beds"
when
Item waterGardenBeds changed from ON to OFF
then
Thread::sleep(5000)
waterFrontYard.sendCommand(ON)
end
Having done that (and reset all the stations in OpenSprinkler), it now seems to work as expected, without creating any odd on-off behaviour. However, it seems to me that it could be worth adding something to the OpenSprinkler binding to prevent this behaviour occurring if anyone else tries to code it to turn one station off and another station on in immediate series.