I have my outside lights automated by 3 automations, which I would like to reduce to one if possible.
The first one turnes on the lights if either sunset or my Pir registers it is dark - on condition of that the outside lights are already off in the first place:
If power save (input boolean) is on then run more or less same automation just at 22:30 instead of in the morning.
alias: Udendørslys sluk energispare
description: Udendørslys sluk energispare
trigger:
- platform: time
at: "22:30:00"
condition:
- condition: state
entity_id: input_boolean.power_saving
state: "on"
- condition: state
entity_id: light.udendorslys
state: "on"
action:
- service: light.turn_off
data: {}
target:
entity_id: light.udendorslys
mode: single
Can those somehow be combined into one automation perhaps using trigger id’s or something else? I haven’t found a way where the conditions is only valid for some scenarios in one automation (for instance the power save boolean)
It would be worthwhile to consolidate the two ‘turn off’ automations if their conditions were identical. However, they’re not; both check if the light is off but only the second one also checks if an input_boolean is on. Therefore, in order to consolidate the two automations, the second condition must be moved out of condition and into a choose (or if-then) within action (that also checks which trigger occurred using trigger.id). The end-result of this consolidation isn’t necessarily better than two separate automations.
Consolidating all three automations requires a slightly longer choose because now it must also differentiate between `turn on’ and ‘turn off’ actions.
Moving the decision-making from condition to action has other consequences. In Home Assistant, an automation’s last_triggered property is updated when its action is executed. Let’s use your third automation as an example of what that means. Assume its Time Trigger fires at 22:30. It proceeds to process the two State Conditions. If the input_boolean is on but the light is off, the automation stops. Because its action wasn’t executed, its last_triggered isn’t updated. Basically, it’s like saying “I’m not recording this because no actual work (action) was done”.
By moving the decision-making into the action, last_triggered will be updated even when the automation’s choose determines that nothing should be done (i.e. none of its conditions are fulfilled in order to turn the light on or off).
If none of what I have explained deters you from wanting to consolidate the automations, I can show you how to do it but, like I said previously, the final product won’t be better than what you currently have.
Thanks for the replies - coming from Appdaemon my head has been around the logic for the outside lights, which I previously had in one “app”, and now have it split in 3. The main reason for combining them into one was for not having a lot of automations during close to the same. If I have 3 for just the outside lights then I will end up having a lot of automations and I could be skeptical for how to manage the overview?