How to bind multiple switches to one light

Sorry team I’m a little confused on how to achieve this.

I have 3 (well even 4 and up to 8) switches with multiple gangs each.
Each of them has one gang that should switch on and off a light (light.1).
Let’s say that switch.gang is the name
I need to have 1.3 - 2.2 - 3.1 that all switch on/off light.1
My expectation is that if press 1.3 then 2.2 andf 3.1 get pressed too and light.1 is turned on
If I press 2.2 and the light is on… then light.1 is turned off and 1.3 and 2.2 are off too

is there an easy way to achieve it?

no one solved this???

I’m not sure what you mean. Multiple switches can operate the same light. The state of the light will be shown in HA. But the switches have no state in Home assistant, so they do not change when another switch is operated.

If you want each switch to toggle the light, then each change of the button should call the service light.toggle:

service: light.toggle
target:
  entity_id: light.mylight

I do not know what type of buttons you use, so I cannot tell what triggers they have.

If you want to achieve this though electrical wiring though, you should check the manual to see if the switch supports it and how it should be wired.

Thank you @Edwin_D
maybe I did some confusion on the terms and this is why I’m a little lost…

I have smart switches with a led on them, the led is on when the switch is “closed”.
They are sonoff TX-3C

My wiring is something like:
0.01 - 1 → phisically connect to bulb
0.02 -1 → not connected phisically

what should happen is:

  1. I press 0.01 - 1 → light is on (due to physical connection) and I have to switch on 0.02 – 1
  2. I press 0.02 – 1 → I have to switch on 0.01 – 1 so that the light is on (due to physical connection)
    Obviously the same works with off.

I need a simple way to do it as, in some cases, I have 8 switches to control the same light

As for the light itself and keeping the toggles in sync, I assume 0.01 is physically connected to the light. So if you switch that from HA the light should react. Other switches should have an automation to toggle that entity in HA to make the light react, and the automation should sync the states of all switches in HA to reflect the proper state. Don’t know what that will do to the led.

It should look something like this:

alias: Synced switches
description: ''
mode: single
trigger:
  - platform: state
    entity_id: 
      - switch.0.01-1
      - switch.0.02-1
      - switch.0.03-1
condition: []
action:
  - service: "homeassistant.turn_{{ trigger.to_state.state }}"
    target:
      entity_id:
        - switch.0.01-1
        - switch.0.02-1
        - switch.0.03-1
5 Likes

Wait: I was thinking way too complicated. Just adjusted the code above. All switches must mimic each other, and if is not a problem to switch the same switch again. As all switches always go to the same state, the risk of this endlessly looping is gone. But keep it in single mode though so it won’t run too often by triggering itself again. Just tested and it works. Also adjusted it a little bit so it works on anything you can turn on and off.

Amazing thank you!

1 Like

What a great solution you had given. Thank you so much

1 Like

Where would I put something like this?

I tried making light_switches.yaml then calling it from the configuration.yaml but it is saying “Integration error: light_switches - Integration ‘light_switches’ not found”.

Any tips appreciated, first time messing around with yaml and your solution is exactly what I need for my multiple switches toggling a single light.

It is an automation. If you create a new auto ation in the automation editor, switch to yaml mode in the menu on the top right menu, you can replace the contents with this. You should of course replace the entity id’s with your own.

Ahh much appreciated, I was able to change it. Though it seems to cause a loop with my lights now haha. Can you see anything wrong with this below?

alias: Hallway Light Switches
description: Hallway Light Switches
trigger:
  - platform: state
    entity_id:
      - switch.0x3410f4fffe72ab0d
      - switch.zb_switch_office_left
condition: []
action:
  - service: homeassistant.turn_{{ trigger.to_state.state }}
    target:
      entity_id:
        - switch.0x3410f4fffe72ab0d
        - switch.zb_switch_office_left
mode: single

A light that is already on should not do anything when already on, and thus not cause a loop. If it is, it might be the integration changes an attribute and trigger again. If it does, a loop may occur. Try changing it to:

alias: Hallway Light Switches
description: Hallway Light Switches
trigger:
  - platform: state
    entity_id:
      - switch.0x3410f4fffe72ab0d
      - switch.zb_switch_office_left
    from:
      - "on"
      - "off"
    to:
      - "on"
      - "off"
condition: []
action:
  - service: homeassistant.turn_{{ trigger.to_state.state }}
    target:
      entity_id:
        - switch.0x3410f4fffe72ab0d
        - switch.zb_switch_office_left
mode: single

If it does not help, let me know. there are other ways to stop it, but they are a bit more elaborate.

2 Likes

That works perfectly, you are an absolute legend! I have been scratching my head for months over this issue.

1 Like

There are greater legends here, but I kindly take the compliment. :slight_smile: Thank you.

Edit: note this may fire as many times as there are entities in the trigger. The way it is now, all switches will try to sync the others, until they are all set the same. If only one switch should trigger them all (and not the other way around), you can limit the trigger to just that one switch.

Thanks for posting this. Works perfectly to sync a few zigbee switches to control the same light here on my setup.

1 Like

Great yaml, it helped me as well!

Would you mind explaining the logic, so I can better understand what the yaml is doing?

The “from” and “to” is mainly what through me off

The from says: it must come from either on or off (so do not respond when a light was unavailable and comes back online)
The to says: it is turned either on or off (so do not respond when a light goes unavailable)

{{ trigger.to_state.state }} is what the new state of the light is, so either on or off. I use it as the end of name of the service that is called on each light. So I get turn_on or turn_off as the service. One of the lights is already in that state, but that does not matter.

You can do this with as many lights as you want, they will always stay in sync, no matter what.

2 Likes

Legends … I had tried different techniques but compared to this… they were all amateur and clunky!
Thank you Thank you Thank you… this is true brilliance!

1 Like

Hi,

Recently I’ve tried code as stated by Edwin_D. In my case everything seems to work OK until it doesn’t. By unknown reason my switches start oscilating until I restart my HA.

My code based on Edwin’s example below:

automation klatka_dolna:
- alias: Klatka_Sterowanie_Lampa_Dolna
  description: Sterowanie schodowe_Klatka_Lampa dolna
  mode: single
  trigger:
    - platform: state
      entity_id:
        - switch.osw_klatka_7a_7b_l1
        - switch.osw_klatka_7a_b_schodowy_l1
      from:
        - 'on'
        - 'off'
      to:
        - 'on'
        - 'off'
  condition: []
  action:
    - service: homeassistant.turn_{{ trigger.to_state.state }}
      target:
        entity_id:
          - switch.osw_klatka_7a_7b_l1
          - switch.osw_klatka_7a_b_schodowy_l1

switch.osw_klatka_7a_7b_l1 is physically connected to light.

I’m running Tuya OXT switches:

Zigbee coordinator Sonoff dongle E and Zigbee2MQTT ver 1.40.2-1.

Have no idea what might be the problem. I hope someone can point me in the right direction :slight_smile:

Your loop scenario should only occur if your master switch changes state twice (on-off-on or off-on-off) while your slave switch is still processing the first command.

There could be multiple causes of this:

  • Your switch is set to momentary mode, where push & release send different commands.

  • Your slave switch is lagging (ZigBee network issues causing a delay).

  • Both of the above.

Unfortunately you didn’t provide any logbook history when this started to occur, so I can’t help more at this point