ON-OFF Automation - Toggle

I have set up the following Automation with one switch (Front) as a “controller” and other switches as “Slaves”. The purpose is that when Front is ON, then the others are ON and when Front is OFF then the others are OFF.
This generally works well, but if HA is temporarily not working (I may be updating an Integration, HA Firmware, etc), and the Front is activated, then the Automation reverses itself whereby IF Front is ON then the “Slaves” are OFF. I must then turn the “Slaves” ON in the HA Dashboard to make the Automation work again as intended.
I could replace this Automation with 2 Automations, one for setting ON and another for setting OFF, but I wonder if this can be achieved in one Automation.
This is what I have now:

alias: "#15-1 Bathroom ON-OFF"
description: ""
trigger:
  - platform: device
    type: changed_states
    device_id: 4dd533902242c1f3931ede67869ab91e
    entity_id: 904a2e1c7b3ed2d861f70a80fafbe4c7
    domain: switch
condition: []
action:
  - service: switch.toggle
    data: {}
    target:
      entity_id:
        - switch.15_2_bath_mini
        - switch.15_3_bath_back
mode: restart

Is restart the issue ?

If these switches should always function together, setup a switch group. If you need to maintain individual control of the switches for other purposes you can accomplish your goal as follows:


alias: "#15-1 Bathroom ON-OFF"
description: ""
trigger:
  - platform: state
    entity_id: 904a2e1c7b3ed2d861f70a80fafbe4c7
    to:
      - 'on'
      - 'off'
condition: []
action:
  - service: switch.turn_{{ trigger.to_state.state }}
    data: {}
    target:
      entity_id:
        - switch.15_2_bath_mini
        - switch.15_3_bath_back
mode: restart
1 Like

Thanks !!! I copied your Yaml and it works.

Have you considered a switch Group?

Yes but @Didgeridrew suggested that if I need to maintain individual control of the switches then his blueprint would be better.

That’s because I’m an idiot sometimes… When using a group you can still turn individual members of the groups on and off by themselves. Just make sure you read and understand the group behavior setting documentation so you can have the switch group entity show up in your UI the way you expect.

If I understand your case correctly, “Front” is a physical device. The problem with a switch group in that situation is that a switch group does not give Controller status/powers to the physical device. Controller status goes to the virtual switch while the entities that represent the physical devices remain agents. So, you would have to set up an automation anyway.

Idiots are those who never recognize they got it wrong.
In my book you are far from an idiot :slight_smile:

You were in fact right the first time. With the Group suggestion, when I click on the Front switch the other two switches do not go ON or OFF, because precisely they can be controlled individually. With your first suggestion when A is clicked, B and C react. When I click on B or C, they react only individually. THAT is exactly what I want.

1 Like