Time Template Conversion HH:MM:SS to X Days, X Hours, etc

Paste this into the Template Editor to see how it works:

{% set d = '5 Days, 6:30:20'.split(', ') %}
{% set x = 1 if 'day' in d[0]|lower else 0 %}
{% set t = d[x].split(':') %}
{{ '{}{} hours, {} minutes, and {} seconds'.format(d[0]|lower~', ' if x == 1 else '', t[0], t[1], t[2]) }}

Replace ‘5 Days, 6:30:20’ with ‘6:30:20’ and the result will not show 0 days.

Yet again, you will need to modify the template to use your sensor’s value. What is the entity name of the sensor?

2 Likes