Last active
January 9, 2025 23:01
-
-
Save aderusha/4f25658dbb855675b5b5ccf296fd801b to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Link Multiple Switches v1.0.1
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 | |
description: | | |
## Link multiple switches together v1.0.1 | |
Select multiple switch 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. | |
Credit to @adchevrier for the initial blueprint: https://community.home-assistant.io/t/synchronize-the-on-off-state-of-2-entities/259010 | |
Credit to @Hebus for this fantastic template: https://community.home-assistant.io/t/synchronize-the-on-off-state-of-2-entities/259010/38 | |
domain: automation | |
homeassistant: | |
min_version: 2022.5.0 | |
input: | |
switches: | |
name: Switch Entites | |
selector: | |
entity: | |
domain: switch | |
multiple: true | |
source_url: https://gist.github.com/aderusha/4f25658dbb855675b5b5ccf296fd801b | |
mode: queued | |
max_exceeded: silent | |
variables: | |
switches: !input 'switches' | |
trigger: | |
- platform: state | |
entity_id: !input 'switches' | |
condition: | |
- condition: template | |
value_template: '{{ trigger.to_state.state != trigger.from_state.state }}' | |
- condition: template | |
value_template: '{{ trigger.to_state.state != "unknown" }}' | |
- 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 }}' |
Can i suggest updating the domain filter to allow binding a switch to a light state aswell - basically allows a physical switch to control the state of the light and the state of the light to switch - so it doesnt matter which entity is switched
domain:
- switch
- light
This one too to prevent unavailable states
trigger:
- platform: state
entity_id: !input switches
to:
- 'off'
- 'on'
The last condition for me causes a 30% of failures in the sync of the entities. I think is not usefull and when removed everything works fine becasue the save exist if on the state
Could someone explain what the last condition meant to do? I can't understand the intent..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last condition for me causes a 30% of failures in the sync of the entities.
I think is not usefull and when removed everything works fine becasue the save exist if on the state