Helper > Timer > attributes

I am still new with HA but I am looking at the Timer Helper and I can see if I “start” it from the GUI the timer counts down in seconds, on the screen, like the first image

image

Does anyone know how I can get a similar countdown showing on a button in a dashboard?
I thought if I created a sensor and show it’s state, like below, it might work, but it doesn’t update and just shows the initial value.

        friendly_name: "test timer"
        value_template: "{{ state_attr('timer.test_60_seconds','remaining') }}"

Does anyone have any tips?

A timer’s remaining attribute is not updated in real-time (it’s updated when paused). The countdown you see in the UI is managed by the UI on behalf of the timer entity (effectively, it’s doing its own countdown).

There is an attribut with the time it ends or something similar. You can use that to calculate the time left

Exactly.

Your Template Sensor will need to compute the timer’s remaining time. When the timer is active it has a finishes_at attribute. You can use that with now() to compute the remaining time. When the timer is paused, the finishes_at attribute ceases to exist and the remaining attribute represents the balance left. An important detail is that whatever template you create to compute the remaining time using now() will have a minimum resolution of one minute (i.e. template will be evaluated at intervals of one minute).

Perfect. Thanks, I think I have it like this (just need to trunc that trailing decials on the seconds but shouldn’t be a problem!)

{{ ( as_timestamp( state_attr('timer.test_60_seconds','finishes_at') ) )-(  as_timestamp(now())  ) }}
2 Likes

That template overlooks an important detail I mentioned. The finishes_at attribute doesn’t exist when the timer is idle or paused. You have to make the template handle that situation gracefully.

Yep, I noticed that, I have an if statement in there to check first. Thanks!

One of the problems you will encounter is that because the time resolution is in minutes, when the countdown drops below 1 minute it cannot display the remaining seconds so it will report 0 minutes remaining (for a full minute).

Why not just add the timer to an entity card?
It will display the time as it counts down and update every second.

No one should be pigeonholed into using an entity card for displaying an attribute. It’s sad to see there has never been development on fixing this after so many years. Tracking time left on a given timer is a quintessential component of process control.

6 Likes

I’m also trying to figure this out.
I’m struggling with now() because that shows the time without DST and the ‘finishes at’ uses DST so I’d have to add more code to calculate DST adjustments which seems messy.

Also I’d rather be able to see the seconds remaining.

There must be a way to acheive this! If the timer page in the UI can do it, why is it so complicated?

I’m trying to get the data onto an NSpanel.

I don’t get it…
As I have posted before, why not just add the timer to an entity card?
That is really all you need to do.

image

In my case, I’m not viewing it in the UI. I want to display it on my AWTRIX clock. For that I need something like {{ states (‘timer.boo_boo_timer’) }} to return the remaining time.