Created
April 24, 2022 10:50
-
-
Save thatdoogieguy/1e357622a8a2396da63abdb6afaff517 to your computer and use it in GitHub Desktop.
Sync Two Switches (Inverted) 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 two switch entities with inverted states | |
description: Mirror two switches by updating the status of the other linked switch to be opposite the triggered switch state. Useful for odd two way switching circumstances. | |
# 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 | |
variables: | |
switch_object1: !input switch_object1 | |
switch_object2: !input switch_object2 | |
trigger: | |
- platform: state | |
entity_id: | |
- !input switch_object1 | |
- !input switch_object2 | |
from: 'on' | |
to: 'off' | |
- platform: state | |
entity_id: | |
- !input switch_object1 | |
- !input switch_object2 | |
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 | |
# Switch logic is inverted to allow for a permanent on & off pairing of switches. | |
# This is suitable for scenarios with off wiring requirements or where you are wanting to create a permanent OR logic. | |
- service_template: > | |
{% if trigger.to_state.state == 'on' %} | |
switch.turn_off | |
{% elif trigger.to_state.state == 'off' %} | |
switch.turn_on | |
{% endif %} | |
data_template: | |
entity_id: > | |
{% if trigger.entity_id == switch_object1 %} | |
{{ switch_object2 }} | |
{% elif trigger.entity_id == switch_object2 %} | |
{{ switch_object1 }} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment