I’m setting up my first timer-based automation, and can’t figure out why what seems to be straight forward isn’t working.
I’ve got a simple automation set up that turns on a light, starts a timer, and exits. Then I’ve set up a second automation that I intend to trigger on when that timer finishes to turn the light off. Here’s the YAML for the two automations:
alias: Back light timer test
trigger:
- type: opened
platform: device
device_id: 54e3095bb400961e32fa07828423fffe
entity_id: binary_sensor.back_porch_door
domain: binary_sensor
condition: []
action:
- type: turn_on
device_id: 5499ad46dcdcd9a2dcde58f4349d575b
entity_id: switch.back_porch_lights
domain: switch
- service: timer.start
data:
duration: '00:00:30'
target:
entity_id: timer.back_porch_lights
mode: single
alias: Back porch lights off when timer finished
trigger:
- platform: event
event_type: timer.finished
event_data:
data:
entity id: timer.back_porch_lights
action:
- type: turn_off
device_id: 5499ad46dcdcd9a2dcde58f4349d575b
entity_id: switch.back_porch_lights
domain: switch
mode: single
I’ve watched the first automation start the timer then as it counts down. But the second automation never triggers.
Is there some magic pixie dust I need to sprinkle about?
Or does anyone have suggestions for where to look in logs to find the system response to the timer.finished event?
The timer will restart if the door is opened again within those 30 seconds. Whereas yours will turn off the light 30 seconds after the door is first opened regardless of whether the door keeps being used
In your approach, if HA happens to restart or if you make a change to any automation in the 30 seconds after the door is opened then the light will just never go off. A timer still has this risk but only if you happen to change an automation exactly 30 seconds after the door was opened. Less likely and also handles restarts without issue (since timers restore after restart now).
Maybe not an issue for the author but just an FYI, delay and timer aren’t quite the same thing. Particularly when it comes to restart/reload resilience.
Your are right, however the intention might be different
Agree, the reload of automation when any automation is changed is a problem (and on restart, even it is a much more limited problem)
Personally I do my lights with 2 automations. One for turn on, triggering on “motion on” The other automation is triggering on “motion off” for 10 minutes.
@khvej8 the code I’ve included here is test code to figure out why the timer.finished event isn’t triggering an automation. I won’t go into all of the details, but using a delay isn’t sufficient for my use case.
(I do use the delay method in simpler automatons.)
there is a difference between the “timer.finished” event and the “timer.finish” service call.
(two letters at the end ). the former can be used as a trigger but the latter can’t. the OP is using the former so it’s fine.
It is most likely the thing that vdrainer posted above (extra “data:” line).
I have the same issue just that it works on one automation and doesn’t on another
I even tried to remake the one it doesn’t work with into an oversimplified version for troubleshooting