I am newish to HA, have been playing with it for 1 month automating various parts of my home but I did not dabble yet in YAML and used mostly the graphical mode.
For one automation, I have been trying a lot of options, browsing all forums for possible solution but cannot seem to find a reliable one for this automation so posting for your help and insights.
In my bathroom, I have 2 lights (mirror and ceiling) each with their own physical switch (at different place of the bathroom) and I connected each of these switches to a Sonoff ZBMINIL2, with the idea of lighting up or switching off both lights, whatever button/switch I use.
It works with 2 simple automations and it is ok in 80-90% of cases:
Automation 1: if mirror light switch OR ceiling light switch is turned ON, then turn ON ceiling light + mirror light
Automation 2: if mirror light switch OR ceiling light switch is turned OFF, then turn OFF ceiling light + mirror light
The issue I often encounter is that, due to automation & Zigbee connectivity latency, a few fast switching action on 1 switch OR fast opposite actions on the 2 switches, leads to both automation going in a mad loop and my lights blinking indefinitely and only to stop it is to disable the 2 automations in HA…
I already tried to:
Separate each button’s automation (ending up with 4 automation instead of 2) so that for example, the mirror switch trigger only acts on the ceiling light, since the mirror light already had the physical command (by the physical switch) hence is already on
Have a single automation so use toggle condition in the trigger (instead of on/off) and toggle in the lights action (but automation fails as the physically connected light is already in the desired state so it does not work at all)
Add a “and if” condition that checks the state of the other automation (to make sure the called up automation only starts if the other one has finished to run
Same as above but added a “state time length” after the automation
Different automation mode (single, restart, etc…)
etc…
I did not try to group the ZBMINIL2 as I do not think it will help (as each drive a separate light).
So far, nothing does it and I still get these glitches…
See below my more advanced automation (OFF variant) with the “running automation” status check.
Thanks a lot for these tips… I will give it a try and come back to you.
Do you recommend I keep the “and if” check to see if the other automation is still running or is that no longer necessary now with this delay?
Here is an automation that I use in owner bath to turn on and off shower light when I turn on sconce lighting. The switches are in two different locations. I use one automation to turn on and off the light. I will explain my logic: if the sconce switch goes for off to on, sconce is on, so turn on shower light. If sconce switch goes from on to off, sconce lighting is off so turn off shower light. thus the two triggers and two actions based on conditions. Hope this helps.
- id: 'shower switch on off'
alias: Shower - Turn on-off Light when owner bath light turned on/off
description: ''
trigger:
- platform: state
entity_id: switch.owner_bath_sconces
from: 'off'
to: 'on'
- platform: state
entity_id: switch.owner_bath_sconces
from: 'on'
to: 'off'
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: switch.owner_bath_sconces
state: 'on'
sequence:
- service: switch.turn_on
target:
entity_id: switch.shower_light
- conditions:
- condition: state
entity_id: switch.owner_bath_sconces
state: 'off'
sequence:
- service: switch.turn_off
target:
entity_id: switch.shower_light
default: []
mode: single
Tried it and while it helped (I get less issues), the ping-ponging between the 2 automations is still happening (tried also with longer values) from time to time…
tks a lot for that… not being an expert, I am wondering if I would apply this approach to my situation (2 physical light switches driving its own light), it would become a lot more complex?
In effect, I would have to check the states of 2 switches and take multiple actions depending on to 4 possible states of the 2 switches.
Which light is the one you turn on as you walk into the Bathroom? I would expect it to be the ceiling light. If you want them to work as a pair forget about the mirror light and use the ceiling light to turn on and off the mirror light. The ceiling light will always be controlled by the switch. You can also group the lights and use the group to turn on/off all the lights.
Thanks for this idea and indeed I had thought about removing the 2nd switch completly and put a blanking plate, but unfortuantely, this ensuite bathroom is very small (2x3m) so while the logical switch is the ceiling one at the entrance of the bathroom, we often enter the bathroom, forget to press the entrance switch and press the mirror one instead (hence the idea to group and automate them).
Yes, that is a possibility but I would like to avoid buying one more element (in fact 2 as I have 2 bathrooms with the same config) to circonvene a problem that should be able to be solved with a programming trick OR better algorythm.
To give it one more go, I tried to reverse engineer your program (I am not a coder ) and applied it to my needs. After many trials and erros, I managed to make it work, so I am very happy about that!!
Unfortuantely, it seems that it is has the exact same issue as before. Now that I understand it… it is pretty much the same concept of a “dual automation” but packaged differently (using a variable), so the two automation actions (on and off) can ping pong each other if one switch is pressed twice/three times too fast OR one switch is pressed just after was pressed before…
I have one more - separate the triggers so they only operate on one entity. You will have two on and two off trigger . Make the new trigger ids Bathroom_on1 and and bathroom off1. Then only turn on/off the other light so you will have 4 actions 2 on and 2 off.
Thanks a lot for your help and additional suggestion.
After posting my last message, I tried one more thing using the new program (where the on/off actions are in the same automation) but leveraging the earlier suggestion from FrancisP (adding a delay).
Adding the delay on the On and Off individual actions (at the end) still did not work (ping pong effect was still there), but then I added it as an extra action after the on / off actions (as a separate action) and it worked!!!
I guess this delay, as an extra action after both on/off action branches, prevents the automation to re-start (also changed the automation mode to single). This would not have been possible on the previous approach (2 separate automations: on / off) as the 2 programs would bounce off each other, but, with the on/off automation now in the same program, that was no longer possible.
I am very happy and want to thank you all for your quick and very kind support!
I am pasting here my code (I still need to fix my entity ID issue => next step) + flow diagram, if it can help some others who may be in the same situation as I was:
Yes
But I think you misunderstood. You can actually configure the device to detach the switch from the relay. This is called detached mode.
I am only not 100% sure it supports it (shelly does for sure)
But then it would look like this:
Very interesting (I did not know) and I would have another automation case where that would be useful… I will dig into that to see if Sonoff ZBMINL2 supports this mode.