Timer duration from lovelace UI

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

image

What am i doing wrong? Why the helper is note in the wright format?!

Thanks

4 Likes

We can’t help unless you share the configuration you tried to use to set the timer duration.

OK…here goes

image

thanks

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:

Screenshot_2021-05-17 Timer

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.
1 Like

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.

Sorry to return, but shouldn’t this work?!

  termoacumulador_temporizador:
    duration: "{{ states('input_number.teste_auxiliar_de_numero') | int }}"

This works and returns a number in the Template testing on the Developer Tools, but I always get an error in the config! Why?

thanks,

Because as I said in my last post, you can’t put a template there.

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.

1 Like

Thanks again

Old topic, but I came along and to this thread. after some spent time I have to admit:

you must not (!) use timer.cancel after you set the duration via a templated value, because that resets the timer to the default value.

if you use timer.stop instead the dynamic/templated value will be kept

1 Like