I suggesting adding the following services
timer.reset
timer.freeze
timer.unfreeze
make the state of the timer be the current time. Reset sets the current time to 0, freeze stops the timer and unfreeze starts it again.
Then we can make nice triggers / conditions based on the numeric state of a timer
N.B I had a very brief glance at the current timers. It seems the only service currently existing is Cancel. This can easily be replaced by freeze followed by reset.
To get 5 stars, make it so if the timer is frozen and the time is 0, the timer unfreezes.
Example:
I want script B to run exactly 2 minutes after script A finishes, unless script C is triggered and runs before B.
Solution: Script A adds a final action timer.reset. Script B triggers when the numeric state of the timer reaches 120.0 seconds. Script C checks the numeric state of the timer, and if > 0. freezes and resets it. Done.
Example 2: script D should run no more frequently than once per 5 minutes.
Solution: script D adds an action that resets and then unfreezes the timer. A condition is added that the timer numeric state must be either 0. (in case of a restart), or > 300.0 seconds.
Reset is probably actually start. Because if you pass a duration to a an already running timer with timer.start, then it will indeed reset. I used to have to send timer.cancel and then timer.start but now I can just pass timer.start regardless of whether the timer is already running.
The documentation could actually do with a minor update. The Pause service gives no indication on how to resume a timer and there is no resume service. So I just assumed this is done with the timer.start service without passing a duration, is that correct?
Yes. Start will start a timer. Either a stopped timer or a paused timer. If you pass in a duration, it essentially cancels the timer, and starts it with the new duration.
I make extensive use of this with my motion lights and motion music automations.
Upon motion, I start a timer with a ridiculously long duration like an hour and a half. And then when motion has stopped being detected, I start the timer again, with a much shorter duration of about 15 minutes.
Most of the time, I no longer get plunged into darkness now