Feature Request: Initial Duration Attribute in Timers

First, the feature request, which I believe is pretty trivial: can we add the initial duration loaded from yaml to the timer attributes? E.g., intiial_duration from yaml would be 00:30:00 and would be unaffected by changes to timer start time, etc.

Then, a little context: I wrote a quick AppDaemon app to make timers persist across HA restarts. One of the consequences, however, of changing the timer duration after boot (to continue the timer) is that the initial duration specified in yaml gets lost. Most of my timers–e.g., “bathroom light off after 30 minutes,” rely on that initial duration for future runs. Historically, that was easy; the duration goes in configuration.yaml and I just start the timer with no duration specified. But if I use my persistence script, that duration gets lost if a timer was running at restart, meaning I need to code the desired duration into ever place that starts a persistent timer or build some code to automatically do that. It seems simpler to just make that information permanently available.

I can think of a few ways to solve this, including:

  • a per-timer option to not store the new duration on timer.start
  • an option to start the timer with the original duration without exposing it as an attribute

I honestly think all of these would be helpful, and none are breaking changes. I’m also aware there is an open PR for internal timer persistence in HA; that would be great! But the attribute still seems useful and seemed like the easiest way to implement it.

Many thanks!

-puk

p.s. Any good links for getting a local build of HA going? I’m currently running Hassio on RPi4, and I’m happy to implement this myself and make a PR, but I’m relatively new to docker and haven’t gotten over the the hump of getting a dev environment up and replacing my production environment.

Perhaps I’m just confused, but how is this different from the duration: tag in the timer documentation, or the associated duration attribute?

The duration attribute will change if you start the timer with a different duration. So if you set the duration to 2:00 for timer.away in your configuration.yaml and then call timer.start with duration = 00:10:00, the duration attribute will now be 00:10:00 and there will be no way to even figure out what the original duration from the yaml was. If you restart HA, however, it will go back to 00:02:00. I’m proposing an additional attribute that would stay at 00:02:00 even if you start the timer and manually specify 10 minutes. It wouldn’t be used for anything other than lookup by scripts/automations.

Hope that clarifies!

[Edit: just to head off the question, you can timer.reload to reset the value, but that has a lot of other side-effects, including resetting the timer, changing other timers timers, etc.]