Created
April 24, 2022 10:50
-
-
Save thatdoogieguy/589312a0e9fd06267cf04862118a4e40 to your computer and use it in GitHub Desktop.
Sync Four Switches in Home Assistant
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: Sync four switch entities | |
description: Mirror four switches by updating the status of the other linked switches to match the triggered switch state | |
# Credit to https://github.com/bmaehr for original script logic | |
domain: automation | |
input: | |
switch_object1: | |
name: Switch 1 | |
selector: | |
entity: | |
domain: switch | |
switch_object2: | |
name: Switch 2 | |
selector: | |
entity: | |
domain: switch | |
switch_object3: | |
name: Switch 3 | |
selector: | |
entity: | |
domain: switch | |
switch_object4: | |
name: Switch 4 | |
selector: | |
entity: | |
domain: switch | |
variables: | |
switch_object1: !input switch_object1 | |
switch_object2: !input switch_object2 | |
switch_object3: !input switch_object3 | |
switch_object4: !input switch_object4 | |
switch_object123: | |
- !input switch_object1 | |
- !input switch_object2 | |
- !input switch_object3 | |
switch_object134: | |
- !input switch_object1 | |
- !input switch_object3 | |
- !input switch_object4 | |
switch_object234: | |
- !input switch_object2 | |
- !input switch_object3 | |
- !input switch_object4 | |
switch_object124: | |
- !input switch_object1 | |
- !input switch_object2 | |
- !input switch_object4 | |
trigger: | |
- platform: state | |
entity_id: | |
- !input switch_object1 | |
- !input switch_object2 | |
- !input switch_object3 | |
- !input switch_object4 | |
from: 'on' | |
to: 'off' | |
- platform: state | |
entity_id: | |
- !input switch_object1 | |
- !input switch_object2 | |
- !input switch_object3 | |
- !input switch_object4 | |
from: 'off' | |
to: 'on' | |
condition: "{{ trigger.to_state.context.parent_id == none }}" | |
action: | |
- wait_template: "{{ (as_timestamp(now()) - as_timestamp(this.attributes.last_triggered | default(0)) | int > 2) }}" | |
timeout: 2 | |
- service_template: > | |
{% if trigger.to_state.state == 'on' %} | |
switch.turn_on | |
{% elif trigger.to_state.state == 'off' %} | |
switch.turn_off | |
{% endif %} | |
data_template: | |
entity_id: > | |
{% if trigger.entity_id == switch_object1 %} | |
{{ switch_object234 }} | |
{% elif trigger.entity_id == switch_object2 %} | |
{{ switch_object134 }} | |
{% elif trigger.entity_id == switch_object3 %} | |
{{ switch_object124 }} | |
{% elif trigger.entity_id == switch_object4 %} | |
{{ switch_object123 }} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment