Trying to create sensor with friendly Time

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?

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. :slight_smile:

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.

Funny way to state a run time, but okay and also funny with the mix of English and German. :slight_smile:

But maybe it is because you have set a state and device class, since your state is actually not a valid format for timestamps.

Can’t you add it in the GUI in the helper menu?

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.