Sensor template time remaining calculation

Ah, understood.

Another option (still human readable, but with different formatting) is:

{{state_attr('sun.sun', 'next_rising')|as_datetime|as_local - now()}}

This returns the amount of time until the next sunrise less one hour:

{{ state_attr('sun.sun', 'next_rising') | as_datetime | as_local - now() - timedelta(hours=1)  }}

This does the same thing but displays the result in the requested format:

{{ (state_attr('sun.sun', 'next_rising') | as_datetime | as_local - now() - timedelta(hours=1)).total_seconds()
 | timestamp_custom('%Hh %Mm %Ss',false) }}

1 Like