Skip to content

Instantly share code, notes, and snippets.

@JoshBello
Last active February 5, 2025 13:31
Show Gist options
  • Save JoshBello/aa02862492b6b94a106235221510462f to your computer and use it in GitHub Desktop.
Save JoshBello/aa02862492b6b94a106235221510462f to your computer and use it in GitHub Desktop.
blueprint:
name: Two Light Sync
description: >
Complete bidirectional sync between two lights with brightness control and state matching.
domain: automation
input:
switch_light:
name: Switch Light
description: The switch that appears as a light entity
selector:
entity:
domain: light
target_light:
name: Target Light
description: The light or light group to control
selector:
entity:
domain: light
transition_time:
name: Transition Time
description: Time in seconds for smooth transitions (0.0 to 2.0)
default: 0.5
selector:
number:
min: 0.0
max: 2.0
step: 0.1
mode: single
trigger:
# Watch both state and brightness changes for switch
- platform: state
entity_id: !input switch_light
- platform: state
entity_id: !input switch_light
attribute: brightness
# Watch both for target light
- platform: state
entity_id: !input target_light
- platform: state
entity_id: !input target_light
attribute: brightness
variables:
switch_light: !input switch_light
target_light: !input target_light
transition_time: !input transition_time
action:
- variables:
is_switch_trigger: "{{ trigger.entity_id == switch_light }}"
source_brightness: "{{ state_attr(trigger.entity_id, 'brightness') | default(0) }}"
target_light_brightness: "{{ state_attr(target_light, 'brightness') | default(0) }}"
- choose:
# When switch changes
- conditions:
- condition: template
value_template: "{{ is_switch_trigger }}"
sequence:
- choose:
# Handle turning off (either by state or brightness)
- conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ states(switch_light) == 'off' }}"
- condition: template
value_template: "{{ source_brightness | int == 0 }}"
sequence:
- service: light.turn_off
data:
entity_id: "{{ target_light }}"
transition: "{{ transition_time }}"
# Handle turning on or brightness changes
- conditions:
- condition: template
value_template: "{{ states(switch_light) == 'on' }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ target_light }}"
brightness: "{{ source_brightness }}"
transition: "{{ transition_time }}"
# When target light changes
- conditions:
- condition: template
value_template: "{{ not is_switch_trigger }}"
sequence:
- choose:
# When target light turns off
- conditions:
- condition: template
value_template: "{{ states(target_light) == 'off' }}"
sequence:
- delay:
milliseconds: 100
- service: light.turn_off
data:
entity_id: "{{ switch_light }}"
transition: "{{ transition_time }}"
# When target light brightness changes
- conditions:
- condition: template
value_template: "{{ states(target_light) == 'on' }}"
- condition: template
value_template: >
{{ target_light_brightness | int !=
state_attr(switch_light, 'brightness') | default(0) | int }}
sequence:
- service: light.turn_on
data:
entity_id: "{{ switch_light }}"
brightness: "{{ target_light_brightness }}"
transition: "{{ transition_time }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment