-
-
Save bthuree/a494ad7dfd5133d3a2bf4b29f9ed68e9 to your computer and use it in GitHub Desktop.
Select multiple entities to link their on/off and brightness 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/Brightness State of Multiple Devices | |
description: > | |
## Synchronize Entities for On, Off, and Brightness Control | |
This blueprint allows you to synchronize multiple entities for controlling their on/off state and brightness level. It simplifies the experience of managing devices by ensuring they respond consistently, regardless of which entity you use. | |
### Overview | |
Imagine you have two wall switches in your corridor. Turning on the first one will also indicate the light's status on the second switch. You can adjust brightness from any device, whether it's a mobile app or a physical switch. | |
### Key Features | |
- When one entity is turned on or off, the others will follow suit. | |
- Changing brightness on one entity will update the brightness for all linked entities. | |
### Requirements | |
- Brightness attribute must be a numeric brightness value, not a step up/down indicator. | |
- All selected entities MUST support `homeassistant.turn_on` and `homeassistant.turn_off`. | |
- Tested on Home Assistant version 2023.09. | |
### Tested Devices | |
- Moes wall smart switch (non-dimmer) | |
- Moes wall smart switch with dimmer functionality | |
- Shelly Dimmer 2 | |
### Credits | |
- Inspiration and starting point from @aderusha's [Link On/Off State of Multiple Devices](https://gist.github.com/aderusha/4d2c8600a2e4771b91b8efc555946413) | |
domain: automation | |
author: Bengt Thuree | |
source_url: https://gist.github.com/bthuree/a494ad7dfd5133d3a2bf4b29f9ed68e9 | |
input: | |
linked_entities: | |
name: Entities to link | |
description: Entity to be syncronized/linked | |
selector: | |
entity: | |
multiple: true | |
mode: single | |
max_exceeded: silent | |
variables: | |
linked_entities: !input linked_entities | |
initiating_automation_id: null | |
trigger: | |
- platform: state | |
entity_id: !input linked_entities | |
id: linked_entities_trigger | |
condition: | |
condition: and | |
conditions: | |
- alias: Verify valid to states (on, off) | |
condition: template | |
value_template: "{{ trigger.to_state.state in ['on', 'off'] }}" | |
- condition: or | |
conditions: | |
- alias: Either on/off has changed | |
condition: template | |
value_template: "{{ trigger.to_state.state != trigger.from_state.state }}" | |
- alias: or brightness has changed | |
condition: template | |
value_template: "{{ trigger.to_state.attributes.brightness|int != trigger.from_state.attributes.brightness|int }}" | |
action: | |
- if: | |
- alias: If action is to turn on the lights | |
condition: template | |
value_template: '{{ (trigger.to_state.state == "on") }}' | |
then: | |
- if: | |
- alias: then, also check if brightness is present | |
condition: template | |
value_template: "{{ trigger.to_state.attributes.brightness is defined }}" | |
then: | |
- alias: if so, turn on lights and set brightness | |
service: homeassistant.turn_on | |
target: | |
entity_id: "{{ linked_entities | reject('eq', trigger.entity_id) | list }}" | |
data: | |
brightness: "{{ trigger.to_state.attributes.brightness }}" | |
else: | |
- alias: otherwise turn on lights (skip brightness) | |
service: homeassistant.turn_on | |
target: | |
entity_id: "{{ linked_entities | reject('eq', trigger.entity_id) | list }}" | |
else: | |
- alias: else turn of lights only | |
service: homeassistant.turn_off | |
target: | |
entity_id: "{{ linked_entities | reject('eq', trigger.entity_id) | list }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment