Hey guys,
I’m using HA for quite some time and was able to find all answers simply by searching here.
But I can’t find a solution for this problem:
I have 3 mqtt devices in a room. All of them have a light and a switch. All of them should work together.
E.g.:
push switch 1 → turn on light 1,2,3
push switch 3 → turn of light 1,2,3
Inital approach, two simple rules with multi trigger and multi aciton:
- alias: dev2_4_14_on initial_state: True hide_entity: False trigger: - platform: state entity_id: light.dev2 to: 'on' - platform: state entity_id: light.dev4 to: 'on' - platform: state entity_id: light.dev14 to: 'on' action: - service: light.turn_on entity_id: - light.dev2 - light.dev4 - light.dev14
Same for off … that sort of works … but its important to notice what happens under the hood:
(1) Push switch 1 → send mqtt status “dev1/status: ON”
(2) Automation trigger → send mqtt: “dev1/switch: ON” “dev2/switch: ON” “dev3/switch: ON”
(3) dev1 will ignore the message as the light was already on
(4) dev2 will send mqtt status “dev2/status: ON”
lets assume that dev3 is a bit slower or that the messages are in some kind of queue
(5) Automation trigger based on dev2 change → send mqtt: “dev1/switch: ON” “dev2/switch: ON” “dev3/switch: ON”
(6) dev1,2 will ignore the message as the light was already on
(7) dev3 will send mqtt status “dev3/status: ON”
(8) Automation trigger based on dev3 change → send mqtt: “dev1/switch: ON” “dev2/switch: ON” “dev3/switch: ON”
(9) dev1,2,3 will ignore the message as the light was already on
So there is quite some traffic.
Now image that there are 100 units in a room … each unit will trigger this automation so 100 x 100 messages will be send out. That will take some time, but thats alright, it will all happen under the hood and I don’t have 100 lights anyway.
But what happens if another switch changes to “off” during this processing time? This will send out an “off” and trigger the 2nd automaition, which will start a wave of messages in parallel. Ultimatly some lights will received a ON followed by an OFF by an ON by an OFF … and retrigger the automation. It’ll start to blink and eventually crash the system at some point.
Again, I don’t have 100 lights but the same problem happened to me with a bouncing switch. ON + OFF was triggered for the same switch within 200ms and the first automation wasn’t finished within the first 200ms. Result was a blinking room. Caught in a infinity-loop …
TLDR:
How do I connect many lights with many switches to act as group?
Put them in a group an turn-on/off the group will have the same effect, each light will trigger the group.
This must be a typical problem, right?
Thanks for your input
JKW