I have an automation that reacts on a state. “If state changes to ON, do this”. Works fine. But I also have conditions for that trigger.
For example: if I’m not home, it won’t actually trigger it. But… if I return home, I do want it to start working. But it won’t, because it only triggers at “if state changes”.
How do you guys work around that?
The easiest is with a timer: trigger every x seconds/minutes and do it (or don’t do it) based on conditions.
But I feel this might put too much unnecessary strain on the system to check for this every x seconds.
But yes, it’s normal to have lots of triggers for more complicated setups. My hall light “on” automation, for example, has this trigger section with a bunch of conditions below it:
trigger:
- platform: state
entity_id: sun.sun
from: 'above_horizon'
to: 'below_horizon'
- platform: homeassistant
event: start
- platform: state
entity_id: binary_sensor.occupied
- platform: state
entity_id: binary_sensor.wfh_solo
- platform: state
entity_id: binary_sensor.hall_light
to: 'on'
for:
minutes: 2
Switching it on can depend on the sun, the house occupation (anyone home, and whether it’s just me working from home) and the light level; and it also checks it’s in the right state after an HA restart.