Last active
August 3, 2024 14:28
-
-
Save rdeangel/566cd635bd645853f8ec8f14ec406f11 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint
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: Only One Switch "On" At Any One Time | |
description: '## It ensures "only one" entity (from the linked entities) is "On" | |
at any given time (v1.0.2) | |
Select multiple entities to link their single "On" exclusive state. | |
If any selected entity is turned on, all the other entities in the group are turned | |
off (allowing only one entity to be on at any one time) | |
You can select any entity, but only entities supported by the `homeassistant.turn_on` | |
or `homeassistant.turn_off` service calls will 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 | |
* [@luma](https://community.home-assistant.io/u/luma) for the [improved/fixed | |
blueprint I used to created this variant](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) | |
### Change Log | |
#### v1.0.1 | |
* fixed a mistake where I forgot to change `switch.turn_off` back to the generic | |
`homeassistant.turn_off`. | |
* fixed an issue where entities that were already off where being switched off | |
again, causing unnecessary triggered actions. | |
#### v1.0.2 | |
* added input to define the wait time before actioning the turning off of other | |
entities after moment of trigger. | |
* added input to define action turn off type `Consider State` and `Ignore State`' | |
domain: automation | |
homeassistant: | |
min_version: 2022.5.0 | |
input: | |
action_mode: | |
name: Action Turn Off Type | |
description: "This defines if the automation issues a turn off action for all | |
other entities \nregardless of state, or if state is considered and only On | |
entities are \nissued a turn off.\n" | |
default: Consider State (Turn Off Only if On) | |
selector: | |
select: | |
options: | |
- Consider State (Turn Off Only if On) | |
- Ignore State (Turn Off Again even if Off) | |
multiple: false | |
sort: false | |
custom_value: false | |
wait_time: | |
name: Wait time before turning off other entities (seconds) | |
description: Time to wait before turning off other entities, to ensure states | |
are updated | |
default: 0 | |
selector: | |
number: | |
min: 0.0 | |
max: 60.0 | |
unit_of_measurement: seconds | |
step: 1.0 | |
mode: slider | |
linked_entities: | |
name: Entities to link | |
selector: | |
entity: | |
multiple: true | |
source_url: https://gist.github.com/rdeangel/566cd635bd645853f8ec8f14ec406f11 | |
mode: queued | |
max_exceeded: silent | |
variables: | |
action_mode: !input action_mode | |
linked_entities: !input linked_entities | |
wait_time: !input wait_time | |
trigger: | |
- platform: state | |
entity_id: !input linked_entities | |
to: 'on' | |
action: | |
- delay: '{{ wait_time }}' | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: '{{ action_mode == ''Consider State (Turn Off Only if On)'' | |
}}' | |
sequence: | |
- service: homeassistant.turn_off | |
target: | |
entity_id: '{{ expand(linked_entities) | selectattr(''state'', ''=='', ''on'') | |
| selectattr(''entity_id'', ''!='', trigger.entity_id) | map(attribute=''entity_id'') | |
| list }} | |
' | |
- conditions: | |
- condition: template | |
value_template: '{{ action_mode == ''Ignore State (Turn Off Again even if Off)'' | |
}}' | |
sequence: | |
- service: homeassistant.turn_off | |
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