Forked from dankarization/link_multiple_devices_v1.1.yaml
Last active
December 28, 2024 14:38
-
-
Save shageman/dbc21d5d50095053c6d0616076a0d76b to your computer and use it in GitHub Desktop.
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.
This file contains hidden or 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 On/Off State of Multiple Devices | |
description: | | |
## Link On/Off State of Multiple Devices v1.3 | |
1) It triggers not only on a state change, but also every minute, to eliminate a problem with very fast changes on/off with last one not triggering anything and entities become unsincronized. | |
2) It does not trigger when initial entity state is unavailable or unknown. It solves the problem with a ton of zigbee devices firstly sending this status after HA reboot, then sending their real one, trigerring all automations based on the v1 template. | |
3) Fixed log errors | |
### Credits | |
* [@luma](https://community.home-assistant.io/u/luma) for [v1 template](https://community.home-assistant.io/t/link-on-off-state-of-multiple-devices/460310) | |
* [@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) | |
domain: automation | |
homeassistant: | |
min_version: 2022.5.0 | |
input: | |
linked_entities: | |
name: Entities to link | |
selector: | |
entity: | |
multiple: true | |
mode: restart | |
max_exceeded: silent | |
variables: | |
linked_entities: !input 'linked_entities' | |
trigger: | |
- platform: state | |
entity_id: !input 'linked_entities' | |
- platform: time_pattern | |
minutes: /1 | |
condition: | |
- condition: template | |
value_template: > | |
{{ trigger.from_state is defined and trigger.from_state.state != "unavailable" }} | |
- condition: template | |
value_template: > | |
{{ trigger.from_state is defined and trigger.from_state.state != "unknown" }} | |
- condition: template | |
value_template: > | |
{{ trigger.to_state is defined and trigger.from_state is defined and trigger.to_state.state != trigger.from_state.state }} | |
- condition: template | |
value_template: > | |
{{ trigger.to_state is defined and (trigger.to_state.state == "on" or trigger.to_state.state == "off") }} | |
- condition: template | |
value_template: > | |
{{ trigger.to_state is defined and (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(linked_entities) | 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