Trigger on state change and inverse that state in an action?

Hello

I need to inverse the state between two Z-Wave switches. Is there a way to define a trigger or another function that reacts on changes between states e.g. “on/off” and then, in the action sets the opposite state.

Jonas_Wikstrom,

I have been thinking about this all day and every step I take to accomplish this leads me to a loop condition. I guess that would be ok if you were having a rave at your house.

I will keep brain storming…

Hopefully someone smarter than me can figure it out or has done it.

Regards

The description of what you want is not exactly clear in your explanation, so I want to be sure of exactly what it is you want.

Do you want to have 2 ZWave switches that are opposite of each other? So that when one turns off the other turns on and vice versa?

Or are you saying that you want both ZWave switches to turn off once they are turned on, or turned on once they are turned off?

Sorry for my bad explanation. I’m totally a Home Assistant beginner,

I have a binary switch on my upper floor that I want to control using a binary switch on the ground floor. Both switches can be in on/off state. If the switch on the ground floor changes state either ‘on/off’ the switch on the upper floor should inverse its state if on to off and vice versa.

and both switches can be actioned?

meaning: you can action the one on the ground floor so you’ll see reaction in the upper floor and if you action the upper floor the reaction should be seen in the ground floor?

No it is just the upper floor I care about…

Starting point?

automation:
- alias: turn off upstairs switch when downstairs switch is on
  trigger:
    platform: state
    entity_id: switch.zwave_downstairs     #Your entity_id here
    from: 'off'
    to: 'on'
  action:
    service: switch.turn_off
    entity_id: switch.zwave_upstairs     #Your entity_id here

- alias: turn on upstairs switch when downstairs switch is off
  trigger:
    platform: state
    entity_id: switch.zwave_downstairs     #Your entity_id here
    from: 'on'
    to: 'off'
  action:
    service: switch.turn_on
    entity_id: switch.zwave_upstairs     #Your entity_id here

The same thing can be achieved with this.

  - alias: switch the switch
    trigger:
      platform: state
      entity_id: switch.zwave_a
    action:
      service_template: >
         {%- if states('switch.zwave_a') == 'off' -%}
           switch.turn_on
         {%- else -%}
           switch.turn_off
         {%- endif -%}
       entity_id: switch.zwave_b
3 Likes