Templating help - Show remaining time in HH:MM of timer

The finishes_at attribute contains no value when the timer isn’t running. Attempting to perform arithmetic with a non-existent value isn’t advisable. Therefore the template should check if the attribute’s value exists before using it.

template:
    - binary_sensor:
        ...
        attributes:
          remaining_time: >-
            {% set f = state_attr('timer.dishwasher', 'finishes_at') %}
            {{ '00:00:00' if f == None else 
              (as_datetime(f) - now()).total_seconds() | timestamp_custom('%H:%M:%S', false) }}
8 Likes