In general terms, I had a switch and a light.
With the switch, I would like to control this light.
To make it not too simple, this light can be turned on by other ways and when it is turned on, I would like to set the switch to the appropriate state.
And this is where the automation starts to get complicated, because it either starts to loop, or every time you have to check whether the state is already set or not.
Conceptually simplest: two automations, and ditch those horrible device triggers and actions. I haven’t included the light transitions here, but you can easily add that back in to the first automation once you’re sure it’s working.
alias: Switch to light
trigger:
- platform: state
entity_id: switch.SWITCH_ID
to:
- 'on'
- 'off'
condition:
- "{{ trigger.to_state.state != states('light.salon') }}"
action:
- service: light.turn_{{ trigger.to_state.state }}
entity_id: light.salon
alias: Light to switch
trigger:
- platform: state
entity_id: light.salon
to:
- 'on'
- 'off'
condition:
- "{{ trigger.to_state.state != states('switch.SWITCH_ID') }}"
action:
- service: switch.turn_{{ trigger.to_state.state }}
entity_id: switch.SWITCH_ID
Unfortunately, splitting into 2 will not be a good solution for me (I have 3 switches, each with 3 buttons. That would make 18 automations together ) But thanks for the tip with the conditions. This will solve the looping problem.
Why is that a problem? You have a complex system there, so the solution is either going to be complicated or lengthy. I’d go for simple and repetitive every time.
Maybe not a problem, but for purely aesthetic reasons, I assumed that for each room there is one automation for lighting and one for heating, rather than dozens of separate ones (which really deal with one task).
Maybe if the automations could be grouped, it would be more convenient for me?
p.s. filtering by area does not work at all, filtering by device does not see devices used in templates
If you give each automation an id, you can assign them to an area in the UI; and you can group them conceptually by using a prefix on the name. Example:
I can see the “issue” with a bunch of “simpler” automations, but in the end that’s as you say an aesthetic problem, in the file-struckture, which btw noone sees
i also try to keep my automations as simple as possible , for ones, it’s more easy to troubleshoot, secondly it’s easier to add / make changes in a simple, rather than in a complex.
i.e Lets say you want to add another task/action when it’s the switch which is the trigger, rather than the light ( when turn on the light by the switch, do something else also, i.e send a notification, or trigger a template-sensor( light turned on by switch ), whatever ) or you want to add a motion-sensor to turn on the light (for 1 minute) as lead-light (i.e in and out of the room) etc.