Skip to content

Instantly share code, notes, and snippets.

@RJNY
Created June 11, 2023 03:25
Show Gist options
  • Save RJNY/129a64048a331b17b9addea92bc41e07 to your computer and use it in GitHub Desktop.
Save RJNY/129a64048a331b17b9addea92bc41e07 to your computer and use it in GitHub Desktop.
Shared On/Off Entities Blueprint for HomeAssistant
blueprint:
name: Shared On/Off State
description: "# Shared On/Off State\n
**v0.01**\n\n
## Disclaimer:\n
This is my first attempt at writing a blueprint. Let me know if you have any feedback or edits I should make.\n
## Description:\n
This automation shares the state of selected entities.\n
If you turn On/Off any entity in this group, either through software or physically,
every other entity in this group will share the same state.\n
## Example Usage:\n
- 3-way switch (or more!)\n
- Shared state On/Off groups\n
## Shout Out\n
Special thanks to Petro for
[his comment](https://community.home-assistant.io/t/emulate-a-three-way-switch/167863/9)
from which I took heavy inspiration from. \n
I was trying to emulate a 3-way switch and couldn't find any good examples until I stumbled upon his comment.
I couldn't find any blueprints that worked as well as him comment, so I created one. Thanks Petro!\n
"
domain: automation
input:
switch_entities:
name: Select the On/Off entities you'd like to share state.
selector:
entity:
domain:
- switch
- fan
- light
multiple: true
mode: single
max_exceeded: silent
trigger:
platform: state
entity_id: !input switch_entities
from: &states
- "on"
- "off"
to: *states
variables:
entities: !input switch_entities
value: >
{{ trigger.to_state.state }}
targets: >
{{ expand(entities) | rejectattr('entity_id','eq', trigger.entity_id) | selectattr('state','!=', value) | map(attribute='entity_id') | list }}
condition:
- condition: template
value_template: >
{{ targets not in ([], none) }}
action:
- service: homeassistant.turn_{{ value }}
target:
entity_id: "{{ targets }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment