I read hundreds of topics and I didn’t find a simple answer for a simple question!..How can I set the duration for a timer !
I’ve set up the timer with a fixed duration and everything works great. Now I want to be able to set up the duration in lovelace. Just that …how can I do it? Easy way please.
I tried with a helper for time and then I the I set the timer duration equal to the helper entity_id, but that gives the following error
What am i doing wrong? Why the helper is note in the wright format?!
Please don’t share pictures of text. Paste and format the text. See point 11 here.
Now I’m going to ignore that advice to show you this:
See how the documentation for the timer option duration says “integer or time”?
That means no templates, and no helpers.
However, what you want to do could be accomplished with an automation as the timer start service does allow templating of the duration. However this will start the timer whenever the duration is changed. If you don’t want that you could pause or cancel the timer right after using the timer.start service.
There’s another problem though. The duration has to be in the format HH:MM:SS and your input_datetime appears to have a date and time. So it will need formatting in the template. You could use an input_number that contains the number of seconds (or minutes or hours) for the timer to run. Much easier.
e.g.
trigger:
- platform: state
entity_id: input_number.duration_in_seconds # this will trigger on any change of the input number
action:
- service: timer.start
entity_id: timer.your_timer_here # I could have cut and paste your timer entity id here but you posed an image and I'm too lazy to write all that with correct spelling. See why pasting images of text is bad?
data:
duration: "{{ states('input_number.duration_in_seconds') }}" # this template could be adjusted for minutes or hours, you could use an input_datetime but that takes more formatting than I'm prepared to do right now as I'm late for bed.
- service: timer.cancel
entity_id: timer.your_timer_here # you only need this if you dont want the timer to start whenever you change the duration.
Sorry for breaking the best practices…it’s wasn’t my intention.
I guess there is no easy way …it should be possible to store a value in the desired format to use it whenever needed. I thought the helpers would achieve this.
Maybe this will be available in future releases. Thanks a lot for your patience Tom.
The only reason that occurs to me is because the timers are part of the configuration.yaml . Is that correct? Otherwise why it would be possible to use templates for the duration in some cases and others not?
Correct. You can use templates in the services but not the configuration. You’ll find most configuration options do not accept templates, yet (nearly?) all services do.