-
-
Save luuquangvu/d2500908ed6b5a636fbcef3525ac854d 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.0.2 | |
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. | |
You can select any entity, but only entities supported by the `homeassistant.turn_on` or `homeassistant.turn_off` action calls will work. | |
Use The Time Options (Optional) | |
### Requirements | |
* All selected entities MUST suport `homeassistant.turn_on` and `homeassistant.turn_off` or errors will be logged and the blueprint will not work. | |
* Requires Home Assistant 2024.10.0 or newer. | |
### Credits | |
* [@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: 2024.10.0 | |
input: | |
linked_entities: | |
name: Entities to link | |
selector: | |
entity: | |
multiple: true | |
time_settings: | |
name: Time | |
icon: mdi:clock-outline | |
collapsed: true | |
input: | |
include_time: | |
name: Use The Time Options (Optional) | |
default: time_disabled | |
selector: | |
select: | |
options: | |
- label: Enable the time options | |
value: time_enabled | |
- label: Disable the time options | |
value: time_disabled | |
after_time: | |
name: Start Time | |
description: > | |
Set the start time. | |
default: 00:00:00 | |
selector: | |
time: | |
before_time: | |
name: End Time | |
description: > | |
Set the end time. | |
default: 00:00:00 | |
selector: | |
time: | |
weekday_options: | |
name: Weekdays | |
description: > | |
Select the days of the week you would like the automation to run. | |
You must select "Enable the time options" above for the weekday selections to work. | |
default: | |
- mon | |
- tue | |
- wed | |
- thu | |
- fri | |
- sat | |
- sun | |
selector: | |
select: | |
multiple: true | |
mode: list | |
options: | |
- label: Monday | |
value: mon | |
- label: Tuesday | |
value: tue | |
- label: Wednesday | |
value: wed | |
- label: Thursday | |
value: thu | |
- label: Friday | |
value: fri | |
- label: Saturday | |
value: sat | |
- label: Sunday | |
value: sun | |
mode: restart | |
max_exceeded: silent | |
variables: | |
linked_entities: !input linked_entities | |
include_time: !input include_time | |
after_time: !input after_time | |
before_time: !input before_time | |
weekday_options: !input weekday_options | |
triggers: | |
- trigger: state | |
entity_id: !input linked_entities | |
from: | |
- 'on' | |
- 'off' | |
to: | |
- 'off' | |
- 'on' | |
conditions: | |
- condition: or | |
conditions: | |
- condition: template | |
value_template: "{{ include_time == 'time_disabled' }}" | |
- condition: and | |
conditions: | |
- condition: template | |
value_template: "{{ include_time == 'time_enabled' }}" | |
- condition: time | |
after: !input after_time | |
before: !input before_time | |
weekday: !input weekday_options | |
- 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.id != this.context.parent_id and | |
trigger.to_state.context.parent_id != this.context.parent_id | |
) or | |
( | |
trigger.to_state.context.id == this.context.id and | |
trigger.to_state.context.id == trigger.from_state.context.id and | |
trigger.to_state.context.parent_id == this.context.parent_id and | |
trigger.to_state.context.parent_id == trigger.from_state.context.parent_id | |
) or | |
( | |
trigger.to_state.context.id == this.context.parent_id and | |
trigger.to_state.context.id == trigger.from_state.context.id and | |
trigger.to_state.context.parent_id == trigger.from_state.context.parent_id | |
) | |
}} | |
actions: | |
- action: 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