Skip to content

Instantly share code, notes, and snippets.

@goncalossilva
Last active June 4, 2024 20:26
Show Gist options
  • Save goncalossilva/2524cf2bb9f1907238f74754385005f3 to your computer and use it in GitHub Desktop.
Save goncalossilva/2524cf2bb9f1907238f74754385005f3 to your computer and use it in GitHub Desktop.
blueprint:
name: Sync Multiple Switches
description: Sync the On/Off state of multiple switches
domain: automation
input:
switch:
name: Switches to Control
selector:
entity:
multiple: true
domain:
- switch
- light
variables:
switches: !input switch
trigger:
- platform: state
entity_id: !input switch
mode: restart
max_exceeded: silent
condition:
- condition: template
value_template: '{{ trigger.to_state.state == ''on'' or trigger.to_state.state == ''off'' }}'
- condition: template
value_template: '{{ trigger.to_state.state != trigger.from_state.state }}'
- 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
) }}
action:
- service: 'homeassistant.turn_{{ trigger.to_state.state }}'
target:
entity_id: '{{ expand(switches) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment