Got an automation that turns on the lights based on motion sensors and sets the brightness_pct depending of time of day(sensor). I get the brightness to work using data_template that reads the sensor but I also want the duration to be set depending of time of day, 2 minutes during day and 10 seconds during evening/night. But I can’t get the timer to work. I can start the timer with different duration from the GUI but not from the automation. What am I doing wrong?
Try removing the quotes around your times (in your duration template only). It’s possible that the template is resolving a double quote. I.E. "'00:00:00'". That would result in an invalid time format.
I’m curious if this automation works as intended. I’ve personally never tried the " - service: timer.start" but have a few automations with “action:- delay:”
The problem is that the timer doesn’t reset. if I use a motion sensor, it doesn’t matter if it sense motion, it will turn off at the exact amount of time after it first saw motion. does this implementation fix that issue?
No. In my opinion, using a delay is the best way to have a motion timer. Have the delay in a script and cancel the script before calling it. It acts like a timer in the way you expect:
You can or you can just add a second service after the light to turn off a switch. Or make a service_template that switches between switch or light based on the provided entity_id.
I really like this implementation. I’ve had several timers that resets before going on again, but having only one script to make the delay, and canceling it in any automation, it will cancel the delays for others lights as well?
If I write multiple automations for different lights (as in your example above), you are saying that it will only cancel the delay script for the corresponding light (even though you don’t specify the entity_id during script.turn_off)? If that’s really the case curious how it tracks the association.
As it is it works, but wouldn’t correctly reset the timer when new motion is detected (however, due to my light off condition, I don’t think this would work as I want it to either ways).
However, I am trying to understand how the script.turn_off works as you described. I.e. if I enable the commented lines the script.turn_off seems to cancel (randomly) one of the other three paralell running light_auto_off scripts, and also wait for whatever light_auto_off script is already running. Seems like some race conditions are happening. But the main point is that script.light_auto_off refers to any other instance of that script running in parallal for both the turn_off and the wait template, which shouldn’t be the case if I understand your comment correctly.
Is it correct that each script is only identified by its name/id and thus stopping it would just stop an arbitrary instance of it independently of where it’s called from?