Understanding device class duration better

image

The simple answer is that the entity card doesn’t properly handle duration sensors. Btw, duration sensors are translated from their floating point number to hh:mm:ss. This is so they can be graphed and displayed in the front end. Unfortunately, some cards do not support them.

2 Likes

That’s it… I only realised now it was about the entity (singular) card. Missed that.

Petro, do we just need to remember this or is this hit and miss (i.e. not documented anywhere)?

It’s just hit and miss where it works from what I can tell

1 Like

I would be very happy about your support:

Using a rest sensor, I get the daylight duration as a string in the format “H:M:S”.

I would like to compare this value in the UI with the daylight duration of yesterday and tomorrow. To do this, I need to convert the string into a timestamp or an integer (duration in seconds).
Of course, I would prefer to be able to display the duration in its original notation in the UI: Hours:Minutes:Seconds

I have given the sensor the device_class “duration” and the state_class: “measurement”.

name: “Tageslicht morgen”
resource: !secret tageslicht_morgen
platform: rest
value_template: “{{ as_timestamp(strptime(value_json.results.day_length, ‘%H:%M:%S’)) | timestamp_custom(‘%s’) }}”
unit_of_measurement: “s”
device_class: duration
state_class: measurement
scan_interval:
hours: 24

I’m afraid that my value_template is already faulty and that’s why my sensor has a value of the equivalent of -70 years.

As you can see, I’m far away from my goal.

Try:

value_template: "{{ value_json.results.day_length | as_timedelta }}"