Skip to content

Instantly share code, notes, and snippets.

@creedda
Forked from fireboy1919/light-state-sync.yaml
Last active April 13, 2024 09:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save creedda/31d391e007b978aed3879fcc1d0fb22c to your computer and use it in GitHub Desktop.
Save creedda/31d391e007b978aed3879fcc1d0fb22c to your computer and use it in GitHub Desktop.
Synchronize States Between Two Lights
blueprint:
name: Synchronize brightness states and rgb 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/creedda/31d391e007b978aed3879fcc1d0fb22c
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_1
attribute: rgb_color
- platform: state
entity_id: !input entity_2
- platform: state
entity_id: !input entity_2
attribute: brightness
- platform: state
entity_id: !input entity_2
attribute: rgb_color
condition: []
action:
- choose:
- conditions:
condition: template
value_template: "{{ is_state(trigger.to_state.entity_id, 'on') }}"
sequence:
- service: light.turn_on
data:
rgb_color: '{{ state_attr(trigger.to_state.entity_id, "rgb_color") }}'
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 %}'
default:
- service: light.turn_off
target:
entity_id: '{% if trigger.from_state.entity_id == entity_1 %} {{ entity_2 }} {% else %} {{ entity_1 }} {% endif %}'
@creedda
Copy link
Author

creedda commented Dec 28, 2023

Also created a Volume Version for Media Players:
https://gist.github.com/creedda/a346d0c1ef3a883caeb7207e83ecf58c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment