So like almost everybody else I am using history_stats too.
To calculate the time my bed is occupied.
### daily usage of sleep time @ my side
- platform: history_stats
name: sleep time yesterday for makis
entity_id: binary_sensor.master_bed_occupied
state: 'on'
type: time
end: '{{ now().replace(hour=11, minute=0, second=0) }}'
duration:
hours: 15
It does work, but when I look at the state it gives me something that is not time! (7.82)
The hour has 60 minutes, so how the earth it shows 82 ???
No one answer… it depends on what you want to do with it, for me it serves as the time how much my son spends behind his gaming console and how long certain (often pointless) lights are on. I personally would not like h:mm:ss as it more resembles the clock time…prefer it to be 7h49m… that is just ‘me’ of course
Depending my on what you want to do, the answers would vary, as said above, but one thing I’d do is to set the device class to duration and also a unit of measurement. This will automatically treat the number as a timedelta object which will allow a number of things to work automatically. One thing I’ve observed though, if you plot it (with the built-in cards), it won’t use a nicely formatted time on the y axis, but the decimal value instead.