Timer using input_number that is dynamically updated

I want to use input_number (slider) as a dynamically updated timer - meaning:

  1. I set it to 30min
  2. Every minute the slider is decreased by 1min
  3. After the slider is 0min an automation is run (this one is easy)
  4. At any point in time I can change the value of the slider manually to increase/decrease the timer

Any ideas how to achieve it the simplest way? I don’t know how to distinct when the slider is updated manually by the user.

Why? This over complicates the solution a ton. Without it, it’s a single automation. With it, it’s a chicken egg scenario with a feedback loop. Trying to counter said feedback loop would be painful.

I want to have visual representation of how much time is left and to be able to extend it easily (just increasing the time left of the slider). I know it overcomplicates things, but it would make things very understandable for the users (aka my wife and kids).

Welp, I doubt anyone will write the code for you in this circumstance. You might as well try this on your own first.

  • integrate sensor.time
  • make an automation that updates every minute using sensor.time and check to see if the timer is active. If it is active update the slider.
  • make an automation that updates the timer (only if the timer is running) if the slider is moved. Use a condition that checks what started the timer using the context property on the state object. You’ll need to reverse engineer the properties in the context property. There are 3 properties, one of them will indicate that the other automation is updating the slider position. If that is the case, don’t fire this automation.
  • Make a script that starts the timer based on the sliders position.
  • Place the script & the slider into a lovelace card.

OR (the easy solution)

  • Make a single script that starts the timer based the sliders position.
  • Place the script & the slider into a lovelace card.

How about just having a simple automation with a time_pattern trigger of every minute, and have it call input_number.decrement (assuming the step parameter of the input_number is the default value of 1)? No timer required.

- trigger:
  - platform: time_pattern
    minutes: /1
  condition:
  - condition: numeric_state
    entity_id: input_number.my_timer
    above: 0
  action:
  - service: input_number.decrement
    entity_id: input_number.my_timer

It might need some refinement, but in general I think this could do what you want.

That’s a good idea and gets around keeping the two in sync

OMG, this is so simple, just brilliant! Thanks!

1 Like