Convert timer into percentage for guage card

I’m trying to convert a timer (elapsed time) to percentage for the gauge card.
In this example the timer is set for 15 mins so once it reaches 10 mins the % value should be ~67%.
The start time is always 0 and the end time is in this case 15 but I’ve multiple timers so the end time would be coming from duration. Don’t know how to get the elapsed time into a % value.
I had a look at

and

But don’t know how to modify it to suit for my sensor.

I’ve manged to get it upto this

{% set d = state_attr('timer.timer_garage_door', 'finishes_at') %}
{{ '00:00:00' if d == None else
(as_datetime(d) - now()).total_seconds() | timestamp_custom('%H:%M:%S', false) }}
{% set t = state_attr('timer.timer_garage_door', 'duration') | as_timedelta %}

But now the next step would be use the t and d into percentages.
May be some modification of the above two examples …
Appreciate if someone can assist in converting this into a template entity that I can then use for my gauge card.

I’m not working with timers but I tried something close to (what I think) you want:

{% set duration_time = state_attr('timer.timer_garage_door','duration').split(':') %}
{% set duration = duration_time[0] | int *24*60 + duration_time[1] | int *60 + duration_time[2] | int %}
{% set remaining_time = state_attr('timer.timer_garage_door','remaining') %}
{% set remaining = 0 if remaining_time == None else remaining_time.split(':')[0] | int *24*60 + remaining_time.split(':')[1] | int *60 + remaining_time.split(':')[2] | int %}
{{ remaining / duration  * 100 }}

thanks … but the remaining and duration remains static just the finishes_at in the full time stamp format changes, so finishes_at needs to be converted to compatible format before the division process.
In other words remaining needs to replaced with finishes_at in the right format…
may be one more iteration ?

This isn’t 100% accurate because last_changed updates on restart and pause events, but it works around the problem caused by time_remaining being useless… as long as your timers generally run straight through.

{% set timer = 'timer.timer_garage_door' %}
{% set start = states[timer].last_changed %}
{% set d = state_attr(timer, 'finishes_at') %}
{{ 0 if d == None else 100 - (((d|as_datetime - now()).total_seconds() / 
(d|as_datetime - start).total_seconds())*100)|round(0) }}

FWIW, if you are timing short intervals, you’ll likely be disappointed using the core Gauge card since it will only update every minute. If you haven’t already, check out the Timer Bar Card

1 Like

thanks Drew

  1. It seems to be working but going from 100 down to 0 so instead of 0 to 100…

  2. I’m using Timer Bar Card for Garage door but will be using this for my washing machine which runs for over an hour. Just pasted Garage timer as an example :slight_smile:

Just add 100 - after the else

All good, thanks :slight_smile: