Last active
June 20, 2023 05:29
-
-
Save djorr5/36f9b3504a2094449af60a4e3720f193 to your computer and use it in GitHub Desktop.
Test Gist
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 with a time and day condition | |
description: | | |
## Link On/Off State of Multiple Devices with Time and Day Condition v1.0.0 | |
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` service calls will work. | |
You can also select the time and days that this should work. | |
### 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 2022.5.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: 2022.5.0 | |
input: | |
schedule_start: | |
name: Schedule start time | |
description: Automation only runs after this time. | |
selector: | |
time: | |
schedule_stop: | |
name: Schedule stop time | |
description: Automation does not run after this time. | |
selector: | |
time: | |
schedule_days: | |
name: Run on these days | |
description: > | |
Days on which the automation will run. | |
Write days in short form, seperates by comma's and/or spaces. | |
(i.e.: mon,tue,wed OR thu fri OR sat, sun) | |
selector: | |
text: | |
linked_entities: | |
name: Entities to link | |
selector: | |
entity: | |
multiple: true | |
mode: queued | |
max_exceeded: silent | |
variables: | |
linked_entities: !input 'linked_entities' | |
days: !input schedule_days | |
trigger: | |
- platform: state | |
entity_id: !input 'linked_entities' | |
condition: | |
- condition: time | |
after: !input schedule_start | |
before: !input schedule_stop | |
- condition: template | |
value_template: "{{ now().strftime('%a') | lower in days }}" | |
- 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 }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment