Skip to content

Instantly share code, notes, and snippets.

@cdchris12
Forked from fireboy1919/light-state-sync.yaml
Last active November 19, 2023 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cdchris12/b3c3546bf446c265adb681088b2623e5 to your computer and use it in GitHub Desktop.
Save cdchris12/b3c3546bf446c265adb681088b2623e5 to your computer and use it in GitHub Desktop.
Synchronize States Between Two Lights
blueprint:
name: Synchronize brightness states
description: Synchronize the on/off state of 2 entities
domain: automation
input:
entity_1:
name: First entity
selector:
entity: {}
entity_2:
name: Second entity
selector:
entity: {}
source_url: https://gist.github.com/cdchris12/b3c3546bf446c265adb681088b2623e5
mode: restart
max_exceeded: silent
variables:
entity_1: !input entity_1
entity_2: !input entity_2
trigger:
- platform: state
entity_id: !input entity_1
- platform: state
entity_id: !input entity_1
attribute: brightness
- platform: state
entity_id: !input entity_2
- platform: state
entity_id: !input entity_2
attribute: brightness
condition: []
action:
- choose:
- conditions:
condition: template
value_template: "{{ is_state(trigger.to_state.entity_id, 'on') }}"
sequence:
- service: light.turn_on
data:
entity_id: '{% if trigger.from_state.entity_id == entity_1 %} {{ entity_2 }} {% else %} {{ entity_1 }} {% endif %}'
- service: light.turn_on
data:
brightness: '{{ state_attr(trigger.to_state.entity_id, "brightness") }}'
entity_id: '{% if trigger.from_state.entity_id == entity_1 %} {{ entity_2 }} {% else %} {{ entity_1 }} {% endif %}'
- conditions:
condition: template
value_template: "{{ is_state(trigger.to_state.entity_id, 'off') }}"
sequence:
- service: light.turn_off
data:
entity_id: '{% if trigger.from_state.entity_id == entity_1 %} {{ entity_2 }} {% else %} {{ entity_1 }} {% endif %}'
default:
- service: light.turn_on
target:
entity_id: '{% if trigger.from_state.entity_id == entity_1 %} {{ entity_2 }} {% else %} {{ entity_1 }} {% endif %}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment