Is it possible to make a count days since last time I cleaned the pellets burner?
Example.
I press a button in my UI (cleaned burner) when I press that button today’s date and time is stored and showed in the UI. And also showing in the UI days since last cleaning.
Pellets burner:
Cleaned 2019-01-01 time: 19:00:10
Days since: 9 (changing over time)
Set up an input_datetime that you push the date (maybe also the time) value to when you click on the ‘execute/activate’ button for a script that does exactly that.
Then you create template sensor that shows the difference of the datetime value between now and the datetime value of the value you just stored.
Might need a little formatting to show proper days and hours and such, though.
You can now place the input_datetime and the script in your frontend; invoking the script should store the current date and time in the inpt_datetime and show it straight away.
Hope that all works - I just pasted things together from various items because I don’t run it exactly that way.
And here’s an example I just crudely copied & pasted from the sensor I normally use to show how long HA has been running - you might have to use the Template Editor under /dev-template to make sure it works and to strip off what you don’t need:
- platform: template
sensors:
since_dishwasher_last_run:
value_template: >-
{%- set slb = states.input_datetime.dishwasher_last_run.state.split(' ') -%}
{%- set count = slb | length -%}
{%- set hms = slb[count - 1] -%}
{%- set hms_trimmed = hms.split('.')[0] -%}
{%- set hms_split = hms_trimmed.split(':') -%}
{%- set hours = hms_split[0] | int -%}
{%- set minutes = hms_split[1] | int -%}
{%- if count == 3 -%}
{{ slb[0] ~ ' ' ~ slb[1] ~ ' ' }}
{%- endif -%}
{%- if hours > 0 -%}
{%- if hours == 1 -%}
1 h
{%- else -%}
{{ hours }} h
{%- endif -%}
{%- endif -%}
{%- if minutes > 0 -%}
{%- if hours > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if minutes == 1 -%}
1 min
{%- else -%}
{{ minutes }} min
{%- endif -%}
{%- endif -%}
If you put the sensor.since_dishwasher_last_run in your frontend it should show what you want to see.
EDIT: Copy & paste error, was missing .state. part from the first split. Got some values out now. Doesn’t seem right yet, but at least it’s a value
Hi,
I’m trying to use this template for another similar purpose but seem to fall short. I only edited the sensor entity and my sensor has value “unknown”. When I put the sensor to the template editor, I get
Error rendering template: UndefinedError: 'homeassistant.core.State object' has no attribute 'split'