Last active
December 28, 2024 17:26
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 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.state != "unavailable" }}' | |
- condition: template | |
value_template: '{{ trigger.from_state.state != "unknown" }}' | |
- 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) }}' | |
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 }}' |
This blueprint works great. It creates a great deal of log errors because to_state
and from_state
can't always be found. So, I am checking for their availability in my fork: https://gist.github.com/shageman/dbc21d5d50095053c6d0616076a0d76b
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of this:
wouldn't it be better to do this?
There might be more states (other than unavailable/unknown) in the future that could cause errors, so instead of checking against all possible negatives, we should only validate allowed states/attributes?