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.

  • Mike Wooskey@lemmy.d.thewooskeys.com
    link
    fedilink
    English
    arrow-up
    1
    ·
    8 months ago

    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' }}