CountUP Timer

The addition of the Timer component is great, however I would really love it if this component also gave the option to start at 00:00:00 and count up. If this were implemented, it would also be good if services were added that would store the current timer value in a sensor (timer.store), and also add the current timer value to an existing time value stored in a sensor (timer.add).

Anyone have any good ways of doing this currently? I’m sure there are ways to use a custom counter with automations that increment every second/minute, but it would be much cleaner if this was able to be implemented into the existing timer component, or split into countdown and countup timers.

The timer component is actually neither a countUP nor a countDOWN timer. It just fires events / changes states after the specified duration has passed. This is intended, since by design a component should not change its state every second. This is to prevent state “pollution” of the database etc…
The exact remaining time is only needed in a few cases, and for those it is reasonable to use automations in conjuctions with the input_number or counter components to store the value. This approach also gives more flexibility, since you can decide yourself what resolution (seconds, minutes, hours…) you want to use.

So for example you can have an automation that increments (countUP, just like you want it) a counter as soon as the timer starts every second, and stops doing that when the timer has finished. If instead you want the remaining minutes, your automation would fire just every minute while the timer is active. Hardcoding that (with variable support for the resolution) into the component would make it more complex for something people may not need in the first place, and it can be easily constructed by yourself with the tools that are already available.

Regarding the stored remaining time: the counter component should support retaining its value across HASS restarts. If you chose the counter to represent seconds, you can actually use the restored value with the timer.start service. The service supports adding a new duration either in the format of 00:11:22, or by seconds, which would be what your counter has.

Thanks Daniel, I appreciate the explanation, it definitely makes sense. Not being a developer, sometimes it’s hard for me to grasp what’s feasible and/or practical. I’ll give it a shot using automations as you’ve suggested.

Here’s an example that’s using the counter and that increments every second: Timer Component - See remaining time?

Hi, it’s been a few years for this but as a new HA user I thought I’d ask again in case there’s something better for this that I haven’t found.

I’m a decade long Homeseer user moving to HA and HS has a timer feature that’s basically a count up timer with options to reset, start, pause just like HA’s countdown timers.

The solutions I’ve found seem to rely on an automation that triggers every second with a condition, but to me that means the automation will literally run every single second the server is running. The condition limits when actions will be triggered, but I’d honestly rather not have some automation that runs every second.

I like the countdown timer feature of HA and it works well for what I use it for. Seems like it wouldn’t be a big deal to offer a count up timer? Maybe it is, not sure.

With my migrations from HS to HA, I have realized that often I have to rethink how I did things before and how it should be done in HA, so I ask myself what I need a countUP timer for. Usually it’s so I can reference how long something has been in a particular state. For example, how long was the alarm armed most recently? How long was something in a state (the last time)?

So maybe there’s a better way to do this without a count up timer. I imagine it’s along the lines of using the input.datetime helper and somehow storing the delta somewhere?

Any help on this would be appreciated, and thanks!

Dennis

And this is one other thing I’ve been reading over:

Thought of something here – not sure if it’s possible to do time calculations easily but if I have a 12 hour regular timer helper and just start it when something triggers this will work for me if I can easily calculate the elapsed time of the timer, even though it’s counting down. For example:

  1. Timer is reset to 12 hours.
  2. Timer is triggered to start counting down due to an automation trigger.
  3. When some other thing happens and the cycle has finished, it stops the timer (or pauses?)
  4. The elapsed time of the timer is calculated (i.e. 12 hours minus whatever the timer value is)

Can this be done? Again, I’m still looking into other possible ways to do this but I thought maybe as long as whatever thing I am timing will never exceed 12 hours then I can use this method if there’s time calc options.

One option is to have two datetime helpers, and an input_number/text.
Add two buttons (start and stop).

Start sets the start datetime helper, and stop sets the stop datetime.
Have an automation trigger on datetime.stop change and calculate the difference and add it to input_number/text, then resets the helpers to some state that you know is not in running state.

With a picture elements card this can all be placed in a way that will make it intuitive and pretty.

Bumping this thread again – I’ve been working on more and more automations that could really use a count UP timer. Instead I have to use a timer with a large value (99 hrs for example) and then do math (and incorporate DST, etc) to calc the elapsed time since starting the timer.

I’d really be interested in a count up timer but I think it’s difficult to implement (I’ll re-read the above thread to see if that was explained).

From @Hellis81 above I will see about the two datetime helpers and calculating between them, although I’m not an expert in any sense and would really like some examples if someone else knows how to do what they suggested.

Thanks!

What about input_number and simple automation to increae its value every second? With all the drawback listed above… Then operations like reseting it can be done by zeroing input_number. Pausing, if needed can be implemented as input_boolean condition within automation to increase or to skip action. This way it can even survive HA restart, with small ofset needed for process to complete. If no one second granularity is needed increments can be done in 10 seconds, or 1 minute intervals, for example.

Here’s one option I saw recently

1 Like

Yeah, that was mentioned but I didn’t really like the idea that some automation continually runs just to increment a timer. I’ll look into the “timestamp” method of one when it starts and a different one when it ends and seeing how to calculate the time difference.

I’d not worry about automations running continuously. As some of my sensors do not refresh automatically (for example input voltage of Fibaro Smart Implant) I have few heartbeat automations that refresh input_boolean values every second to minute and use state change of this input booleans to trigger refresh automations or to slightly modity sensors values to triger some actions. Not the most elegant solution, but work perfectly fine and I do not see any significant impact of HA performance (it runs at ~3% of CPU (though it is 4 cores VM running of ESXi).

OK, I made two datetime helpers to store timestamps of the starting time, and one for the ending time. I used a PHP program on a separate linux server to poll the dates and subtract them, and I get a valid elapsed time that’s correct, so I know the two timestamp idea will work.

Now I just need to figure out how to do the datetime subtraction in HA to get the new elapsed hours, minutes, and seconds.

Would this be done in a template? Or just a python script somehow?

Thanks for any advice!

There already is a count down timer feature but I’d like there to be a count up timer. This would be very useful for anyone who is monitoring the run time of something.