Time interval to string

In case anyone else is looking for a concise way of displaying seconds as hours/minutes/seconds (and suppressing hours or minutes if they're zero):

{{ states('sensor.custom_print_time_left') | int(0)
  | timestamp_custom('%-H hr %-M min %-S sec', false)
  | regex_replace('(^0 hr| 0 min)', '') | trim }}

The pattern within timestamp_custom is easy to change if you need a different time format.

Reference: strftime


EDIT

I had a sense of déja vu while writing this post and then found that I had suggested the same technique to someone else last month:

2 Likes