2 Sonoff to replicate the state of each other

I have 2 rooms, from which a wall was taken down so it is now 1 room. Each room had one light that is operated by wall switches. I installed 1 tasmota sonoff device in each wall box and hooked up the gpio14 wires to the actual switch. What I am trying to do, is when one switch is turned on, the other one turns on, same with being turned off. I have it working for the most part, but sometime if you hit the switch just right and it click on and off again quickly the state of one light triggers a automaton and then I get a nice strobe light on off affect from both lights. Basically one action of one automation is triggering the other automation, and they go back and forth. I hope that makes sense. Is there something I can do to to my automation, so that will not do that? I am somewhat new and still learning how to do automation. Below is what I currently have.

- alias: Kitchen Light ON
  trigger:
  - entity_id: switch.kitchen_light_switch
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: switch.kitchen_light_switch_2
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.kitchen_light_switch
    service: switch.turn_on
  - data:
      entity_id: switch.kitchen_light_switch_2
    service: switch.turn_on

    
- alias: Kitchen Light OFF
  trigger:
  - entity_id: switch.kitchen_light_switch
    from: 'on'
    platform: state
    to: 'off'
  - entity_id: switch.kitchen_light_switch_2
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      entity_id: switch.kitchen_light_switch
    service: switch.turn_off
  - data:
      entity_id: switch.kitchen_light_switch_2
    service: switch.turn_off

you could try to put a slight delay in your triggers that requires the light to be on for 1 second (or whatever works for you) before the automation switches the other one.

like:

trigger:
  - entity_id: switch.kitchen_light_switch
    from: 'off'
    platform: state
    to: 'on'
    for:
      seconds: 1
  - entity_id: switch.kitchen_light_switch_2
    from: 'off'
    platform: state
    to: 'on'
    for:
      seconds: 1

Then you could do the same for the ‘off’ automation.

you would have a slight delay (1 second) between the lights operating which would be noticable but not too bad. Not the perfect solution but a workable solution.

While that would probably work, putting the delay in the trigger would cause one light to lag by a second when switching.

Alternatively your first action for the on automation could be to disable the off automation. Then add a wait template after switching the lights on to check they have changed to the on state before re-enabling the off automation.

Likewise for the off automation actions, disable the on automation as your first action. Add a wait template after turning the light s off to check they have turned off before re-enabling the on automation.

Thanks Tom_I,
I got the code figured out on how to implement the wait template. I will do some further testing, but in theory it should work. I am now curious what will happen if they come out of sync for example, only one light turned on. I imagine both automation would end up being shut off, where I then would need to manually turn back on (Which is better then it being a strobe light).

They shouldn’t ever get out of sync if you are switching both lights with each of the on or off automations.

There may be some residual effect due to the way your (assuming) mqtt switches are defined. Can I see the config for these two switches? And possibly a few sample payloads if you have them handy (if not, there are tons of examples of Tasmota payloads I can look up).

My line of thinking is that when the switch turns on (or off) it causes a state change in the already on (or off) switch. Also… when they start the seizure inducing mode… can you tell if they are going on and off at the same time… or if one is on while the other is off, and then that alternates? Or is it too fast to tell?

An alternate plan to implement this is using Tasmota’s GROUPING functionality.

By going to the console of the two devices you can issue a command “GroupTopic kitchen” to have them both listen to the kitchen group topic. Then, you could change the action of your automation to be:

-service: mqtt.publish
 data:
   topic: sonoff/cmnd/kitchen/POWER   #or whatever is right for your devices
   payload: "ON"   #or "OFF" if you're trying to turn them off 

This will serve to bypass whatever Home Assistant is doing and tell the devices directly to be ON or OFF. Then they’ll report state back to Home Assistant, of course.

Another option… since you have switches on your Sonoffs (I don’t have any like that, so this is all in theory)… you can again use the console… issue “SwitchMode 7” on both, (which I imaging you’ve already done… and this assumes you’re using a “regular” light switch the flips up and down and stays there). Then issue “SwitchTopic kitchen” on both (this tells Tasmota to not have the switch control the relay directly, but, instead to send an MQTT command to that topic). Then issue “GroupTopic kitchen”. This will, effectively, link the two switches together using the Tasmota software. However, I think with “SwitchMode 7” it sends a “TOGGLE” command (not an “ON” or an “OFF”) which means, if somehow the two lights get out of sync (one on and one off) then flipping the switch will result in the on one going off and the off one going on. Some testing will be needed there.But, to help make sure they don’t get out of sync, you could remove your two switches in HASS (or just hide them in case you ever do need to control them separately) and create a new switch for the group topic.

Another option would be to add an “if” in your action to only turn off/on the OTHER light, if sending an “on” command to an already “on” light is causing an issue … because I’m not sure if homeassistant will send the “ON” payload to the device when it knows the device is already on.

Yet another option would be to put the two lights in a group and switch the group on to see if that makes any difference.

Sorry for the “wall of text”. Problems like this are intriguing to me.

That’s a neat solution. I didn’t realise they could do that.

Sorry swiftlyfalling I have meant to get what you asked for to you, but got some things going on and I have not had time yet. I was able to implement the solution tom_i suggested last week and it has actually worked out well. I will get the other info to you when I can in the next day or two as I do like to learn more about this as well.

I think I have both sonoff’s on Switchmode0 1 , which is toggle. Another note in regards to what you suggested, which was to use mqtt command to control the Relay. I thought about that and have them implemented in my living room. if Home-assistant is down or the WiFi is down, then the light would not work at all.

In my living room, I have the wire from the breaker panel into the switch box, and bypassing the actual switch all together, and going straight to my Ceiling fan/light. This way the son-off on the switch tells another sonoff in the light to turn on. I have it this way so I can independently control the light and the fan. I have 2 sonoff’s wired inside my fan. One for the light and the other for the fan. Later I will swap it with a sonoff dual, but didn’t have one at the time. the downside to that setup is, when WiFi or Home-assistant is down, that light and fan won’t toggle on or off.

1 Like

No worries at all. I’m glad you managed to get it working.

Hi there

I have the same issue, 2 wall switch that controls the same lamp… My main issue is if my HA is down, I can’t control the lights (it seams that is this, but correct me if I’m wrong) and that is not an opinion to my wife.
Although I found this relays that can be installed inside wall and use the old switches…
I bought a couple, then I must install tasmota and controlthe light.

https://shelly.cloud

That way, I think, you continue to control the light, installing one of this in each switch, manually and remotely…

Again this in theory…i’m still a noob in this world of HA. :joy:

You could do the following

Rewire the lighting so both lights run off one switch is both lights powered by one switch.

The other switch is a dummy switch that just send an mqtt toggle light command and the funny switch doesn’t work when the WiFi/ha is down. The actual relay in the switch does nothing.