#Not sure how to ask how to mirror the state of two switches

36 messages · Page 1 of 1 (latest)

lucid nimbus
#

I've got two smart switches setup. I'd like to be able to turn on switch 1, and have switch 2 turn on as well. And if I turn on 2 it also turns on 1. The same for turning off.
How would I setup an automation for this?

fossil halo
#

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.)

placid breach
#

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
fossil halo
#

oh okay.. so it's not four automations, its one

placid breach
#

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

fossil halo
#

as long as it's not repeating endlessly and locking the lights on

placid breach
#

it won't. a light that's on turning on doesn't generate a state change

fossil halo
#

good to know

cursive berry
#

This does trigger twice though - once when you turn one switch on, once when it turns the other one on.

placid breach
#

sure, but that's it

lucid nimbus
#

ok, let's see if I can figure out where and how to do this

cursive berry
#

Yup it's not the end of the world, and you could ignore the 2nd one with a context condition

placid breach
#

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

cursive berry
#

If you really don't want to turn an on switch on - label them and filter out the ones in to_state

fossil halo
#

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

lucid nimbus
#

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

fossil halo
#

'''

#

er ```

lucid nimbus
#

thanks

fossil halo
#

sorry.. three backticks

placid breach
#

does it work?

lucid nimbus
#

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?

fossil halo
#

yeah, it should be light.turn

lucid nimbus
#

that was it!

#

it works! cool

#

Thanks guys!

blissful glade
#

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