Forked from aderusha/link_multiple_devices.yaml
Last active
February 15, 2025 11:49
-
-
Save inakianduaga/cde4c325f92da47b3f86c66fbfc872d7 to your computer and use it in GitHub Desktop.
Split conditions to handle color_mode properly
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 a Light to Another Light | |
description: | | |
Synchronize the on/off state, brightness, and color settings of a source light to a target light. | |
domain: automation | |
input: | |
source_light: | |
name: Source Light | |
selector: | |
entity: | |
domain: light | |
target_light: | |
name: Target Light | |
selector: | |
entity: | |
domain: light | |
mode: queued | |
max_exceeded: silent | |
variables: | |
source_light: !input 'source_light' | |
target_light: !input 'target_light' | |
trigger: | |
- platform: state | |
entity_id: !input 'source_light' | |
condition: | |
- condition: template | |
value_template: > | |
{{ trigger.to_state.state != trigger.from_state.state or | |
trigger.to_state.attributes.brightness != trigger.from_state.attributes.brightness or | |
trigger.to_state.attributes.rgb_color != trigger.from_state.attributes.rgb_color or | |
trigger.to_state.attributes.color_temp != trigger.from_state.attributes.color_temp }} | |
action: | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ trigger.to_state.state == 'on' }}" | |
sequence: | |
- service: light.turn_on | |
target: | |
entity_id: "{{ target_light }}" | |
data: | |
brightness: "{{ state_attr(source_light, 'brightness') | default(255) }}" | |
- conditions: | |
- condition: template | |
value_template: "{{ trigger.to_state.state == 'off' }}" | |
sequence: | |
- service: light.turn_off | |
target: | |
entity_id: "{{ target_light }}" | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ trigger.to_state.attributes.color_mode != 'color_temp' }}" | |
sequence: | |
- service: light.turn_on | |
target: | |
entity_id: "{{ target_light }}" | |
data: | |
rgb_color: "{{ state_attr(source_light, 'rgb_color') }}" | |
- conditions: | |
- condition: template | |
value_template: "{{ trigger.to_state.attributes.color_mode == 'color_temp' }}" | |
sequence: | |
- service: light.turn_on | |
target: | |
entity_id: "{{ target_light }}" | |
data: | |
color_temp: "{{ state_attr(source_light, 'color_temp') }}" | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: > | |
{{ trigger.to_state.attributes.brightness != trigger.from_state.attributes.brightness }} | |
sequence: | |
- service: light.turn_on | |
target: | |
entity_id: "{{ target_light }}" | |
data: | |
brightness: > | |
{% set source_brightness = state_attr(source_light, 'brightness') | default(255) %} | |
{% if source_brightness <= 5 %} | |
3 | |
{% else %} | |
{{ source_brightness }} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment