Last active
July 20, 2022 11:41
-
-
Save Links2004/3d1a21aee70909deae4561bb35b2674f to your computer and use it in GitHub Desktop.
Home Assistant blueprint - Link Multiple Switches and Lights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Link Multiple Switches and Lights | |
description: | | |
## Link multiple switches and Lights together v1.1.0 | |
Select multiple switch and Lights entities to link their on/off state. If any selected switch entity is turned on or off, the other selected entities will be sent a matching on or off command. | |
Requires Home Assistant 2022.5.0 or newer. | |
Based on @aderusha https://gist.github.com/aderusha/4f25658dbb855675b5b5ccf296fd801b | |
domain: automation | |
homeassistant: | |
min_version: 2022.5.0 | |
input: | |
lights: | |
name: Light Entites | |
selector: | |
entity: | |
domain: | |
- light | |
multiple: true | |
switches: | |
name: Switch Entites | |
selector: | |
entity: | |
domain: | |
- switch | |
multiple: true | |
sync_lights: | |
name: Sync Lights (Light to Light) | |
default: false | |
selector: | |
boolean: | |
source_url: https://gist.github.com/Links2004/3d1a21aee70909deae4561bb35b2674f | |
variables: | |
switches: !input switches | |
lights: !input lights | |
sync_lights: !input sync_lights | |
trigger: | |
- platform: state | |
entity_id: !input switches | |
- platform: state | |
entity_id: !input lights | |
mode: queued | |
max_exceeded: silent | |
condition: | |
- 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: switch.turn_{{ trigger.to_state.state }} | |
target: | |
entity_id: | |
'{{ expand(switches) | selectattr("entity_id", "!=", trigger.entity_id) | |
| map(attribute="entity_id") | list }}' | |
- service: light.turn_{{ trigger.to_state.state }} | |
target: | |
entity_id: | |
'{% if trigger.entity_id.split(".")[0] == "switch" or sync_lights %}{{ expand(lights) | selectattr("entity_id", "!=", trigger.entity_id) | |
| map(attribute="entity_id") | list }}{% else %}[]{% endif %}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment