Automation to Mirror two Smart Switches

I have a smart switch controlling some outdoor lighting at my house. It’s located in the dayroom. However, my wife has now instructed me that she wants a switch inside the house.

So, last night I installed a smart switch at another location and did not connect the switch leg – think dumb smart switch.

So basically when you hit the inside switch, it enables the outdoor switch.

I’m trying to figure out what is the best method (I use automations as well as node-red) to make both switches mirror each other. When one is pressed, it’s off. When the other is pressed it’s on and vica-versa. The only “issue” I see is I have rules setup to cut off those lights programmatically if motion isn’t detected, a door wasn’t opened for some time, etc.

Should I just create multiple rules? Am I overthinking this?

alias: Indoor Backyard Switch (Fan) ON
description: ''
trigger:
  - platform: device
    type: turned_on
    device_id: 21eeb1b32de9da92d4edf70722b27837
    entity_id: light.backyard_virtual
    domain: light
condition: []
action:
  - type: turn_on
    device_id: 0140600cc9e91b544f8a2f284677c50d
    entity_id: switch.backyard_lights_led
    domain: switch
mode: single

This cuts on the outdoor lights from indoor switch (enables the switch) but if it was done in reverse, cut on the switch from the dayroom, I need to poll the state of the indoor switch and change the value based on that.

Thanks in advance!

Not “dumb”, “detached”.

This will make the dayroom switch follow the indoor switch (on and off):

alias: Indoor sw controlling dayroom sw
description: ''
trigger:
  - platform: state
    entity_id: switch.your_indoor_switch_here
condition: []
action:
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: switch.your_dayroom_sw_here
mode: single

However this does not allow the dayroom switch to alter the indoor switch. Adding another automation to do the reverse (dayrrom switch to control the indoor switch) gets a bit loopy (literally) without a condition in both automations:

alias: Indoor sw controlling dayroom sw
description: ''
trigger:
  - platform: state
    entity_id: switch.your_indoor_switch_here
condition:
  condition: template
  value_template: "{{ states('switch.your_dayroom_sw_here') != trigger.to_state.state }}"
action:
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: switch.your_dayroom_sw_here
mode: single
alias: Dayroom sw controlling indoor sw 
description: ''
trigger:
  - platform: state
    entity_id: switch.your_dayroom_switch_here
condition:
  condition: template
  value_template: "{{ states('switch.your_indoor_sw_here') != trigger.to_state.state }}"
action:
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: switch.your_indoor_sw_here
mode: single

With these two automations whatever you do to one switch will be reflected by the other and you can keep your existing motion and door automations.

1 Like

Why not make it simple and use light.toggle, that way it doesn’t matter which switch triggers it will change state.

Maybe, it depends how they are doing these things:

and if they are using the switch state in any conditions, e.g. movement to turn the lights back on if the switch is on.

If they are then the switch states need to be synchronised.

1 Like

Thanks for the help guys. I’m going to be adding an outdoor motion to the mix soon. However, I do want to know more about the light.toggle you speak off. The only issue I saw with toggle is I have an autoamtion now that cuts the light off (based on the outdoor switch). The indoor switch remained on. I guess I can add an action to cut off both switches at the same time. Can a group be used here?

No, you can’t use a group. Turning an individual switch on in a group won’t affect any other switches in the group, just the group state.

If you want to use the switch state as a condition, use the two automations I posted above to sync the switches if either is changed.

Thank you. I did this with Node-Red last night, but will redo in HA automations to see if I can get it to function like I would like. Thanks again for your time.

You can use a group: use the group’s state as a trigger in an automation to set the state of all the switches in the automation.

So for example, an “Outdoor Light” group would have the two switches and the light as members, and when the group’s state is ON (meaning that one of the members is ON), the automation sets all members to on, and viceversa when it’s off.

This allows all the group’s members to be in sync, even for example if you have a smart light that you can turn on via app (without the switches): when you turn on the light via a mobile app, the two switches would reflect the light’s state.

I just completed the installation of 12 Sonoff TX3 switches in my house, and I was about to implement exactly this automation because I have many ways to turn on a light/appliance from several switches, and I wanted all to be in sync.

Yes I specified what I meant in the first phrase: you can use the group as a trigger.

And you must use homeassistant.turn_on (or turn_off / toggle) with group as entity_id so that all members (being lights/switches/etc.) transition their state.

It works perfectly:

Group definition with two switches and the controlled light:

groups:
  luce_bagno_ospiti:
    name: Luce Bagno Ospiti
    entities:
      - switch.sonoff_100139d758_1
      - switch.sonoff_100139cda6_2
      - light.luce_bagno_ospiti

And then this to control the status of all members of the group:

service: homeassistant.turn_on
target:
  entity_id:
    - group.luce_bagno_ospiti

Works perfectly. Now it’s just a matter of defining the groups and creating an automation for each group.

It would be great to have an automation that covers all groups…I’ll think about it…

One thing: unfortunately the GROUP logic is OR only for the ON state (if ANY member is ON, the group is ON), but it is AND for the OFF state (ALL members have to be OFF in order for the group to be OFF). So the automation unfortunately won’t be simple as it could be. It would be good if this logic could be configurable, but it isn’t.

It isn’t configurable for the OFF state.

I think you missed this part of what I wrote, when I was referring to the configurability of the OFF state.

Nope, in that post I was referring obviously to the OFF state, and that is not configurable. The context is important. :slight_smile:

That was your original sin: I was not saying Tom was wrong, I only integrated what he said. Context…:slight_smile:

Nope, context alert! :sweat_smile:

And you insist on implying I said he was wrong…when I didn’t. Try to read my first post objectively (I’ll underline the critical part for you), or don’t, I don’t care much, you have the right to have your opinion, not your own facts.

My last post on this OT discussion. Cheers.

Wrong. It can (and should) be used as a trigger, but since the group logic for OFF state is limited and not configurable, it only makes the automation not simple as it could be, you need to expand() the group and check if one of the members’ state is off to determine the OFF condition, basically replicating the default behaviour of the group’s ON state. So you need at least two triggers, one for the ON state and one for the OFF state. Sending homeassistant.action commands to the group is more efficient and logic for the scope of mirroring switches and it allows to keep the members’ state in sync.

Since you are an expert on these things, the fact that you say it’s not possible really surprises me, you are not acknowledging this proposed solution only for the sake of trying to prove I’m wrong.

So now you’re acknowleding it can be done…interesting…I thought you said I was wrong, and it couldn’t be done. Glad you changed your opinion.

I will, don’t worry, I’m still in the middle of mounting the new switches all over the house, when they’re installed, I’ll need to mirror some of them and will implement this.

The mere fact that you are saying it’s not possible is astonishing. You perfectly know it can be done, you’ve done one-liner expansion of groups more complex than this, the fact that you don’t acknowledge it can be done surprises me.

When I’ll work on it I will let you know, and if I find your same issues I’ll tell you and maybe, if you want, we could talk about possible solutions/workarounds, because ultimately I really need this to be working, I have 15 3-gang switches (Sonoff TX T3US) to install and at least 5-6 of them will have to mirror others.

Learned a lot from you during last year, while developing my Nuki Card, so I’ll be more than happy to share my findings and ask for your support. :slight_smile:

BTW: I will tasmotize them, and I know that with Tasmota’s Device Groups functionality this could be easily done, but I want to try with HA first to see if we can overcome the group’s current limitations.

Thanks.