Hello,
I am trying to create a sensor which gives me a friendly time (hours and minutes) from another entity.
this is the sensor:
- sensor:
- name: "Waschmaschinen Dauer schön"
unique_id: "waschmaschine_dauer_schon"
unit_of_measurement: min
state_class: total
device_class: timestamp
state: >
{% set hours = states('sensor.waschmaschine_dauer_year') | float %}
{% set total_hours = hours | int %}
{% set minutes = ((hours - total_hours) * 60) | round %}
{{ total_hours }} St. {{ minutes }} Min.
In templating it works perfectly and gives me 106 St. 29 Min.
When I paste the code into a template.yaml package the sensor is not available.
What am I doing wrong?
WallyR
(Wally)
February 17, 2025, 12:00pm
2
Did you reload template entities in developer tools or restarted HA core after the copying?
Also I do not understand how you waschmaschine_dauer_year is formatted, because the calculations you do is a bit strange.
106 hours is a bit of strange for a run time on a washing machine too.
Could you post a screenshot of the sensor from developer tools?
Hi,
the state of the sensor gives me the yearly runtime like this
And yes, I restartet HA afterwards.
WallyR
(Wally)
February 17, 2025, 12:19pm
4
Funny way to state a run time, but okay and also funny with the mix of English and German.
But maybe it is because you have set a state and device class, since your state is actually not a valid format for timestamps.
Hellis81
(Hellis81)
February 17, 2025, 12:23pm
5
Can’t you add it in the GUI in the helper menu?
123
(Taras)
February 17, 2025, 12:46pm
6
deepblue120:
What am I doing wrong?
The following options require the template’s result to be a number.
unit_of_measurement: min
state_class: total
This option requires the template’s result to be a datetime string in ISO8601 format.
device_class: timestamp
You have combined all three options, which makes no sense, plus your template doesn’t even produce a number.
Remove all three options.