- Platform information:
- Hardware: Raspberry PI 3b+
- OS: openhabian
- Java Runtime Environment:
- openjdk version “1.8.0_222”
- OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
- OpenJDK Client VM (Zulu8.40.0.178-CA-linux_aarch32hf) (build 25.222-b178, mixed mode, Evaluation)
- openHAB version: 2.5.0-1
I’m trying to set up a group of switches, where I want to turn all switches on or off by sending commands to the group. The member items are linked via MQTT to a bunch of tasmota smart plugs.
I notice that when I send the OFF command to the group when more than 1 of the member items are ON, the state of the group changes to OFF, then ON again briefly, and finally OFF again. If I have any rules that trigger on this group state going from ON to OFF, they will be triggered twice.
From looking at the logs, I can see why. With all items ON, when I set the group to OFF from the basic ui:
- the group state goes from ON to OFF
- the individual items are sent the OFF command
- the first item receives the OFF command, it transitions to OFF
- the groups’ OR aggregate function evaluates to ON since the other items are still in ON state, so the group state goes from OFF to ON
- finally, when all items have received the OFF command and transitioned to the OFF state, the aggregate OR evaluates to OFF and the group state goes from ON to OFF again
I think this is expected behaviour, yet it causes me some problems. When I have rules triggering on the group state going from ON to OFF, these rules will trigger twice. For example, I have a rule that turns on some things when all my lights go off. Due to it firing twice, the things that are switched in response are switched ON, OFF, ON again quickly. That is not really how I want to treat my equipment , let alone the havoc this creates on my AC mains supply.
I’ve seen some topics here discussing similar issues, and they go into complicated setups with timers to debounce things and/or locks. While carefully crafting such solutions would certainly be possible, it is fraught with the possibilities of race conditions and dead-locks, which I hope to avoid by keeping things simple.
It seems to me that if I had a way to have the group state not change based on the sendCommand, but only on the basis of one of its members changing (ie, the group state would directly reflect the aggregate function result, not change state by itself on receiving a command), I would avoid this particular issue. Is this possible?
I’m sure i’m missing something obvious here, how do others deal with this issue?
My test.items:
Group:Switch:OR(ON,OFF) Test_Group
Switch Test1 "Test 1" <lightbulb> (Test_Group) { channel="mqtt:topic:plug009:switch", autoupdate="false" }
Switch Test2 "Test 2" <lightbulb> (Test_Group) { channel="mqtt:topic:plug010:switch", autoupdate="false" }
Switch Test3 "Test 3" <lightbulb> (Test_Group) { channel="mqtt:topic:plug011:switch", autoupdate="false" }
I also have a test.sitemap to be able to see what happens and send ON/OFF commands to the group:
sitemap test label="Test"
{
Switch item=Test_Group label="All Test"
Switch item=Test1 label="Test1"
Switch item=Test2 label="Test2"
Switch item=Test3 label="Test3"
}
The log for sending an OFF command when all items are ON:
2019-12-22 10:38:05.158 [ome.event.ItemCommandEvent] - Item 'Test_Group' received command OFF
2019-12-22 10:38:05.186 [ome.event.ItemCommandEvent] - Item 'Test1' received command OFF
2019-12-22 10:38:05.211 [ome.event.ItemCommandEvent] - Item 'Test2' received command OFF
2019-12-22 10:38:05.238 [ome.event.ItemCommandEvent] - Item 'Test3' received command OFF
2019-12-22 10:38:05.346 [GroupItemStateChangedEvent] - Test_Group changed from OFF to ON through Test2
2019-12-22 10:38:05.351 [vent.ItemStateChangedEvent] - Test2 changed from ON to OFF
2019-12-22 10:38:05.355 [vent.ItemStateChangedEvent] - mqtt_topic_plug010_switch changed from ON to OFF
2019-12-22 10:38:05.363 [vent.ItemStateChangedEvent] - mqtt_topic_plug009_switch changed from ON to OFF
2019-12-22 10:38:05.366 [vent.ItemStateChangedEvent] - Test1 changed from ON to OFF
2019-12-22 10:38:05.377 [vent.ItemStateChangedEvent] - mqtt_topic_plug011_switch changed from ON to OFF
2019-12-22 10:38:05.380 [GroupItemStateChangedEvent] - Test_Group changed from ON to OFF through Test3
2019-12-22 10:38:05.387 [vent.ItemStateChangedEvent] - Test3 changed from ON to OFF
The things are set up via paper ui: