blueprint: name: Link On/Off State of Multiple Devices description: | ## Link On/Off State of Multiple Devices v1.0.0 Select multiple entities to link their on/off state. If any selected entity is turned on or off, the other selected entities will be sent a matching on or off command. You can select any entity, but only entities supported by the `homeassistant.turn_on` or `homeassistant.turn_off` service calls will work. This blueprint allows you to select multiple groups of entities, to combine the link automations into one ### Requirements * All selected entities MUST suport `homeassistant.turn_on` and `homeassistant.turn_off` or errors will be logged and the blueprint will not work. * Requires Home Assistant 2022.5.0 or newer. ### Credits * [@adchevrier](https://community.home-assistant.io/u/adchevrier) for the [initial blueprint](https://community.home-assistant.io/t/synchronize-the-on-off-state-of-2-entities/259010) * [@hebus](https://community.home-assistant.io/u/hebus) for [this fantastic template](https://community.home-assistant.io/t/synchronize-the-on-off-state-of-2-entities/259010/38) * [@luma](https://community.home-assistant.io/u/luma) for [the updated blueprint](https://community.home-assistant.io/t/link-on-off-state-of-multiple-devices/460310) domain: automation homeassistant: min_version: 2022.5.0 input: linked_entities_1: name: Entities to link 1 default: {} selector: entity: multiple: true linked_entities_2: name: Entities to link 2 default: {} selector: entity: multiple: true linked_entities_3: name: Entities to link 3 default: {} selector: entity: multiple: true linked_entities_4: name: Entities to link 4 default: {} selector: entity: multiple: true linked_entities_5: name: Entities to link 5 default: {} selector: entity: multiple: true linked_entities_6: name: Entities to link 6 default: {} selector: entity: multiple: true linked_entities_7: name: Entities to link 7 default: {} selector: entity: multiple: true linked_entities_8: name: Entities to link 8 default: {} selector: entity: multiple: true mode: restart max_exceeded: silent variables: linked_entities_1: !input 'linked_entities_1' linked_entities_2: !input 'linked_entities_2' linked_entities_3: !input 'linked_entities_3' linked_entities_4: !input 'linked_entities_4' linked_entities_5: !input 'linked_entities_5' linked_entities_6: !input 'linked_entities_6' linked_entities_7: !input 'linked_entities_7' linked_entities_8: !input 'linked_entities_8' trigger: - platform: state entity_id: !input 'linked_entities_1' id: trigger_1 - platform: state entity_id: !input 'linked_entities_2' id: trigger_2 - platform: state entity_id: !input 'linked_entities_3' id: trigger_3 - platform: state entity_id: !input 'linked_entities_4' id: trigger_4 - platform: state entity_id: !input 'linked_entities_5' id: trigger_5 - platform: state entity_id: !input 'linked_entities_6' id: trigger_6 - platform: state entity_id: !input 'linked_entities_7' id: trigger_7 - platform: state entity_id: !input 'linked_entities_8' id: trigger_8 action: - choose: - conditions: - condition: trigger id: trigger_1 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_1) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_2 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_2) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_3 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_3) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_4 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_4) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_5 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_5) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_6 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_6) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_7 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_7) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}' - conditions: - condition: trigger id: trigger_8 - condition: template value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' - condition: template value_template: '{{ (trigger.to_state.state == "on") or (trigger.to_state.state == "off") }}' - condition: template value_template: '{{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id != this.context.id and trigger.to_state.context.parent_id != this.context.id) }}' sequence: - service: homeassistant.turn_{{ trigger.to_state.state }} target: entity_id: '{{ expand(linked_entities_8) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}'