New Timer option - explain how duration can be dynamic please

Hopefully this is going in the right place. I just upgraded to 57.2 and was excited about the timer option. After setting it up, however, I am getting some undesirable results.

I have an input_number, which is setup as a slider so that I can configure a timer duration for how long to have our bedroom motion detector off for.

  name: Hours
  icon: mdi:timer
  initial: 2
  min: 1
  max: 5
  step: 1
  mode: slider
  unit_of_measurement: Hours

I have a timer configured as:

  name: Bedroom Motion Disabled
  icon: 'mdi:close-circle'

I have a script, which is:

  alias: Bedroom motion off
    - service: homeassistant.turn_off
        entity_id: group.bedroom_lights
    - service: timer.start
        entity_id: timer.bedroom_motion_disabled
        duration: '{{ states.input_number.disable_motion_timer.state | int }}:00:00'

When I fire the script, the duration errors and says that it cannot figure out the value.

if I replace

- service: timer.start
            entity_id: timer.bedroom_motion_disabled
            duration: '{{ states.input_number.disable_motion_timer.state | int }}:00:00'


- delay: '{{ states.input_number.disable_motion_timer.state | int }}:00:00'

It works. But this does not give me control over cancelling the “timer”, as it is a delay that keeps the script excecuting until delay completes. Why does it not work when setting the duration on the timer start?

Also, when displaying a timer on the front-end. It doesn’t display the timer time? As in, there is no way to see how much time is left on the timer?

Is there a way to disable the timer from the front-end, without creating another script that calls the cancel option?

Thanks for all the great work you guys do! Been with the software since like .30, and I am amazed where it is today. Love love love!!

The frontend part has not been done yet. It is planned to allow control over the timer at some point in the future. So setting durations, pause, start, pretty much anything will be doable via UI.

Regarding the question about your automation:
I’m no expert when it comes to automations and templating, but whenever I use templates, I don’t use data. Instead I use data_template like mentioned in the Automation Templating Docs. Maybe that’s part of the issue?

Thanks danielperna84,

you were correct. Changing it to the below now works like a champ! Thanks for the help and will keep an eye out for future updates to the timer.

- service: timer.start
            entity_id: timer.bedroom_motion_disabled
            duration: '{{ states.input_number.disable_motion_timer.state | int }}:00:00'
1 Like

I got this working, but had to change the single quotes to double, my example to set a timer on a pool pump.

  - alias: 'Pool Pump timer On'
    id: 'poolTimerstart'
    # Timer is started when the pool pump is set to on.
      - platform: state
        entity_id: input_select.pool_pump
        to: 'On'
      - service: timer.start
          entity_id: timer.pool_pump
          duration: "00:{{ states.input_number.pool_pump_timer.state | int }}:00"
1 Like

Hi Adam,
Is this method of dynamic timer duration still working for you? For me it seems to not work anymore in June 2020.

Mine is still working fine on 0.111.4

Cool. Now see why my automation didn’t work. I needed to replace the ‘data:’ tag with ‘data_template:’.
Thanks for your help.