2 Switches - 1 Light

I’ve got a scenario: I have 2 light switches - one on each end of the hallway. Master is wired to the light and Slave is not wired to anything.

What I want is when either of the switches is turned on the other one reflects the state.
Right now I achieved it with 4 automations:

  1. when Master is ON: turn on Slave
  2. when Master is OFF: turn off Slave
  3. when Slave is ON: turn on Master
  4. when Slave is OFF: turn off Master

Is there a more elegant way to achieve it?

I tried to put them in the Group and use without automations but it didn’t seem to work: If I started with everything off, then turned on Slave - it would change state of Slave and Group to ON but it wouldn’t affect the Master.

Do you have any suggestions?

Cheers
Kostya

You could do all that in one automation using trigger ids and the choose action.

1 Like

Haven’t really worked with trigger ids yet, but that’s how I keep my XMas lights in sync:

alias: Switch - Sync XMas Lights
trigger:
  - platform: state
    entity_id: >-
      switch.xmas_living_room,switch.xmas_lobby,switch.outdoor_1,switch.outdoor_2
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: >-
      switch.xmas_living_room,switch.xmas_lobby,switch.outdoor_1,switch.outdoor_2
    from: 'off'
    to: 'on'
action:
  - service: switch.turn_{{ trigger.to_state.state }}
    target:
      entity_id:
        - switch.xmas_lobby
        - switch.xmas_living_room
        - switch.outdoor_1
        - switch.outdoor_2
mode: single

You might even be able to skip the second trigger if you also remove the ‘from’ and ‘to’ from the first one - not sure what it would do when the state changes e.g. from ‘unavailable’ to ‘on’ or from ‘off’ to ‘unavailable’, though.

3 Likes

thanks a lot I really like that solution. I’ll give it a go later!

1 Like

Because my switches show up as lights, I had to make a small modification (btw, this code goes into the automations.yaml file):

- alias: Breezeway Light 3-Way Soft Switch
  trigger:
  - platform: state
    entity_id: >-
      light.breezeway_indoor_switch,light.breezeway_outdoor_switch
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: >-
      light.breezeway_indoor_switch,light.breezeway_outdoor_switch
    from: 'off'
    to: 'on'
  action:
    - service: switch.turn_{{ trigger.to_state.state }}
      target:
        entity_id:
          - switch.breezeway_light
    - service: light.turn_{{ trigger.to_state.state }}
      target:
        entity_id:
          - light.breezeway_indoor_switch
          - light.breezeway_outdoor_switch
  mode: single
2 Likes

I was looking for a more elegant solution to link/sync my lights and switches. This works, thank you.

However, i get multiple warnings in my log file each time it’s triggered:

I got the same warnings with my previous solution (using scenes/automations). I think what happens is that when you press SWITCH 1, SWITCH 2 and 3 will change state but they themself trigger the same automation, hence the warning ‘automation already running’.

It works well but i’m afraid my logfile will be quite large in a few years and bloated with these warnings. I’m no expert in HA so i’m not sure how to proceed from here.

Anyone else getting these warnings?

[edit] i changed ‘mode: single’ to ‘mode: restart’ and the warnings stopped. it doesn’t seem to affect the automation so i think i keep it this way.

Looks like your switch might be bouncing a bit.

Add this to the automation to suppress the warnings:

.
.
.
mode: single
max_exceeded: silent ### Add this ###
2 Likes