In a mushroom template card I have it reporting the time my boiler was put on/off.
Until now I’ve been using the last_changed value of the toggle, but this updates whenever HA is reset, so I was looking to create and use a persistent value instead.
So I created a datetime helper which, whenever the boiler is switched on/off, it updates.
That part works fine.
Where I’m stuck is in the template logic where it looks to compare the date of the activity compared to now() and if the same then return just the time. If a mismatch, return date + time.
This worked fine before with the last_changed, but I’m struggling to get the formatting for the datetime helper in the set variable
Currently it looks like this:
{% set datenow = (as_timestamp(now()))| timestamp_custom('%y%m%d', True) | float() | round (0) %}
{% set lastheated = (as_timestamp(states.input_boolean.water_heating.last_changed)) | timestamp_custom('%y%m%d', True) | float() | round (0) %}
{% if states('input_boolean.water_heating')=='on' %}
On {{( states('input_datetime.boiler_activity') | as_timestamp| timestamp_custom('%H:%M', True))}}
{% elif (is_state('input_boolean.water_heating','off') and (datenow == lastheated)) %}
OFF {{( states('input_datetime.boiler_activity') | as_timestamp| timestamp_custom('%H:%M', True))}}
{% else %}
OFF {{( states('input_datetime.boiler_activity') | as_timestamp| timestamp_custom('%y/%m/%d %H:%M', True))}}
{% endif %}
The below returns the right value, but I’m struggling to figure our how to format it for the lastheated variable.
{{(states('input_datetime.boiler_activity') | as_timestamp| timestamp_custom('%y%m%d', True))}}