#Not sure how to ask how to mirror the state of two switches
36 messages · Page 1 of 1 (latest)
I'm curious how to do this, too. My initial thought would be to set up a series of automations (if switch 1 turns on, turn on switch 2, same for off, same for 2 to 1, etc.) but I'd hope there was a better way to mirror states. I would also be worried about a race condition (switch 1 tells switch 2 to turn on, which tells switch 1 to turn on, etc.)
The simplest way is this:
trigger:
platform: state
entity_id:
- switch.one
- switch.two
action:
service: switch.turn_{{ trigger.to_state.state }}
entity_id:
- switch.one
- switch.two
oh okay.. so it's not four automations, its one
a more verbose way is to have a trigger for each switch and state transition, each with a trigger ID, and then use a choose: action to turn the switches on or off
you could have four automations
that's just the smallest version of it
it also repeats the "on" or "off" for the one you just turned on or off, which isn't ideal, but probably doesn't matter
as long as it's not repeating endlessly and locking the lights on
it won't. a light that's on turning on doesn't generate a state change
good to know
This does trigger twice though - once when you turn one switch on, once when it turns the other one on.
sure, but that's it
ok, let's see if I can figure out where and how to do this
Yup it's not the end of the world, and you could ignore the 2nd one with a context condition
you could also make four automations handling each case separately and avoid that. Or the more complicated one automation with mulitiple triggers and trigger IDs
add another light and you'll find that it's not really scalable, though
yes, you can could also add if/then statements to only affect the one that isn't in the desired state
100000 ways to do it
Nah, condition to prevent the automation acting a 2nd time, not to change the entities it's acting on
If you really don't want to turn an on switch on - label them and filter out the ones in to_state
so @lucid nimbus basically you want to go into Settings > Automations & Scenes, click New Automation, then go through the wizard to set the triggers and actions. Triggers should be the two switches, with "Light turned on or off" as the value, as for the actions, I'd add both switches and set them to 'toggle' temporarily. It looks like you'll have to switch to the YAML editor to properly set the value that RobC posted above. Do that with the three dots at the upper right. Using the UI editor first will get the YAML most of the way there for you, which makes it easier to fill in the last values
I did it in yaml, the editor modified the script to this. It doesn't appear to be working tho.:
alias: KitchenMirror
description: Mirror Kitchen/Island
triggers:
- entity_id:
- light.island_lights
- light.kitchen
trigger: state
conditions: []
actions:
- entity_id:
- light.island_lights
- light.kitchen
action: switch.turn_{{ trigger.to_state.state}}
mode: single
oh shoot, I forgot the tag for code
thanks
sorry.. three backticks
does it work?
no. I think it's because they are entity light and not switch? But they are switches. Maybe wrong trigger
for action, should it be light.turn?
yeah, it should be light.turn
Also you might want to only mirror valid states or the automation will generate errors: trigger: platform: state entity_id: - switch.one - switch.two not_to: - unknown - unavailable