Uptime / Duration sensor device class

Hi,

the device classes of the sensor platform currently only support a timestamp (i.e., a concrete time instant). However, one might be interested in also displaying an elapsed period of time.

In my case, I want to report intervals such as uptime etc. via MQTT. This could be emulated via a binary available / unavailable sensor, however I then can’t distinguish a device restart from a MQTT connection loss. Publishing the “time of boot” as timestamp requires time synchronization and moreover doesn’t really allow for anything that potentially “finishes” (such as charging).

Cheers

Great idea and an oversight that can be easily fixed. A lot of integrations already use sensor entities but conspicuously have no device_class for ones that provide a duration, like Xiaomi vacuum’s “Last Clean Duration” and “Filter Left” (time), both measured in seconds.

EDIT: They just added it recently, unlike what the post below implies. They didn’t have it at the time of this post.

This exists already. device_class: duration