this post was submitted on 17 Mar 2024
16 points (94.4% liked)

homeassistant

15293 readers
12 users here now

Home Assistant is open source home automation that puts local control and privacy first.
Powered by a worldwide community of tinkerers and DIY enthusiasts.

Home Assistant can be self-installed on ProxMox, Raspberry Pi, or even purchased pre-installed: Home Assistant: Installation

Discussion of Home-Assistant adjacent topics is absolutely fine, within reason.
If you're not sure, DM @GreatAlbatross@feddit.uk

founded 2 years ago
MODERATORS
 

Does anyone know what I need to put in order to display the timer duration?

Currently I have

{{ states('timer.dining_study_clear') }}

And that just displays Active, Idle or Paused.

top 8 comments
sorted by: hot top controversial new old
[–] infeeeee@lemm.ee 5 points 1 year ago (1 children)
{{ state_attr('timer.dining_study_clear', 'duration') }}
[–] sabreW4K3@lazysoci.al 1 points 1 year ago

Thank you so much for putting me on the right track!

[–] mike_wooskey@lemmy.d.thewooskeys.com 4 points 1 year ago (1 children)

From what I understand, a timer's duration is the amount of time the timer was set to run for when it was started - the total time, not the time remaining.

If you're wanting to determine the time remaining in an active timer, you need something like:

{% set finish_time = state_attr('timer.timer_entity_id', 'finishes_at') %}
{{ '00:00' if finish_time == None else (as_datetime(finish_time) - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

Or this version, which breaks hours and minutes into speakable parts:

{% set finish_time = state_attr('timer.timer_entity_id', 'finishes_at') %} 
{% set hours, minutes = ('00:00' if finish_time == None else (as_datetime(finish_time) - now()).total_seconds() | timestamp_custom('%H:%M', false)).split(':') | map('int') %} 
{{ '' if hours == 0 else hours ~ ' hour' if hours == 1 else hours ~ ' hours' }} {{ ' and ' if hours > 0 }} {{ minutes ~ ' minute' if minutes == 1 else minutes ~ ' minutes' }}     
[–] sabreW4K3@lazysoci.al 1 points 1 year ago (1 children)

Holy fuck, you're beautiful! It doesn't update in real time, but it's better than what I had. Thank you so much!

[–] NessD@lemmy.world 3 points 1 year ago (1 children)

There is a timer bar card in HACS.

[–] sabreW4K3@lazysoci.al 1 points 1 year ago (1 children)

Slightly more than what I need as it's just for a secondary line in my dashboard, but thank you.

[–] NessD@lemmy.world 2 points 1 year ago

It was basically the only thing I found that updates in real time and it is highly customizable. If you find something simpler, let me know. I'm also looking. :)