Combine switches

Hello,

Probably this already exists, but I created a blueprint to combine 2 switches. If one goes on, the other one follows.

Probably this can be improved to add more switches, but for now this is it.

blueprint:
  name: Combine switches so they turn on/off together
  description: Combine switches so they turn on/off together
  domain: automation
  input:
    switch_1:
      name: switch_1
      description: switch_1
      selector:
        entity:
          domain: switch
    switch_2:
      name: switch_2
      description: switch_2
      selector:
        entity:
          domain: switch

trigger:
  - platform: state
    entity_id:
      - !input switch_1
      - !input switch_2
    to:
      - "on"
      - "off"
action:
  - variables:
      modified_state: "{{ trigger.to_state.state }}"
  - if:
      - condition: and
        conditions:
          - condition: template
            value_template: '{{ modified_state == "on" }}'
    then:
      - if:
          - condition: and
            conditions:
              - condition: state
                entity_id: !input switch_1
                state: "off"
        then:
          - service: switch.turn_on
            entity_id: !input switch_1
      - if:
          - condition: and
            conditions:
              - condition: state
                entity_id: !input switch_2
                state: "off"
        then:
          - service: switch.turn_on
            entity_id: !input switch_2
    else:
      - if:
          - condition: and
            conditions:
              - condition: state
                entity_id: !input switch_1
                state: "on"
        then:
          - service: switch.turn_off
            entity_id: !input switch_1
      - if:
          - condition: and
            conditions:
              - condition: state
                entity_id: !input switch_2
                state: "on"
        then:
          - service: switch.turn_off
            entity_id: !input switch_2

1 Like