Something is wrong…
back for some extra info and added the ‘old’ template, which calculates correctly based on the last_boot sensor:
this is the code in the dev template editor:
{{as_timestamp(states('sensor.last_boot'))}}
{%- set boot = as_timestamp(now())-as_timestamp(states('sensor.last_boot')) %}
{%- macro phrase(name, divisor, mod=None) %}
{%- set value = ((boot // divisor) % (mod if mod else divisor))|int %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{%- set values = [phrase('week', 60*60*24*7),
phrase('day', 60*60*24),
phrase('hour', 60*60),
phrase('min', 60),
phrase('sec', 1, 60)]
|select('!=','')|list %}
{{values[:-1]|join(', ') ~ ' and ' ~ values[-1] if values|length > 1 else
values|first}}
#old version
{% set boot = as_timestamp(now()) - as_timestamp(states('sensor.last_boot')) %}
{% set seconds = boot|int %}
{% set minutes = (boot // 60)|int %}
{% set hours = minutes // 60 %}
{% set days = hours // 24 %}
{% set weeks = days // 7 %}
{% set seconds = seconds % 60 %}
{% set minutes = minutes % 60 %}
{% set hours = hours % 24 %}
{% set days = days % 7 %}
{% macro phrase(value,name) %}
{%- set value = value|int %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value,name,end) if value|int > 0 else ''}}
{%- endmacro %}
{% set text = [phrase(weeks,'week'),phrase(days,'day'),phrase(hours,'hr'),
phrase(minutes,'min'),phrase(seconds,'sec')]|select('!=','')
|list|join(', ') %}
{% set last_comma = text.rfind(',') %}
{% set text = text[:last_comma] + ' and' + text[last_comma + 1:] %}
{{text}}
seems the streamlined version doesn’t mod the hours correctly.
Adding the Mod for the hours in the calculation:
{%- set values = [phrase('week', 60*60*24*7),
phrase('day', 60*60*24),
phrase('hour', 60*60, 24),
phrase('min', 60,60),
phrase('sec', 1, 60)]
|select('!=','')|list %}
makes the calculation correct again:
should they be added to the other time units too, according to the old template:
# {% set seconds = seconds % 60 %}
# {% set minutes = minutes % 60 %}
# {% set hours = hours % 24 %}
# {% set days = days % 7 %}