How to format a card to show hours instead of seconds?

Hi,
I have a Miio entity (a vacuum) which shows various properties:

As you can see, values are shown in seconds.
It’s fine for the integration page, but in the dashboard I would like to have hours.

Is it possible without having to define an extra template sensor? Formatting “on the fly” depending on the dashboard seems like a reasonable use case…

Thanks.

1 Like

As far as I know, no.
But I think it would be a good change in the integration.
Who would want it in seconds?
Minutes is perhaps more useful but still, hours is probably the most useful here.

I think the integration is fine and changing it would even affect long term storage of data, it’s the dashboard that should allow reformatting numbers.

1 Like

I’ve run into this, too. Just recently in 2022.5 something changed and now some of my dashboard displays which were in decimal hours are in HH:MM:SS format. That’s OK, but I don’t need the seconds to display. It only makes the screen look cluttered.

In hopes of avoiding the flood of responses I know would come, let me be clear: I know I can create a template in whatever format I want. I’ve got dozens of templates already. I don’t think it’s a good practice to create templates (data) simply to display a value. The display should be separate from the data.

This isn’t the first time this has come up. A quick search came up with this question, and a few Feature Requests. I suggest up-voting any you agree with:

There are no doubt more discussions on this; I just did a very quick search.

I agree. Creating templates to format a value is like cracking walnuts with a sledgehammer.

There was an issue raised when the Xiaomi vacuum changed from hours to seconds. The devs indicated that as a policy they no longer change the units reported by the device and it would not be changed. So we are probably going to see more of this sort of thing.

1 Like

I think it’s reasonable.

I didn’t find them, I guess my search used the wrong terms.

Thanks!

The groundwork is in place for this to be handled by the UI in the future. In 2022.4 (maybe 5), a new sensor device class duration was added. As long as a sensor has the following things set:

  • Has a value of hours, minutes, or seconds
  • Corresponding unit_of_measurement, h, m, or s
  • device_class: duration

The UI will display the value as d HH:MM:SS. Where d is days, HH is hours, MM is minutes and SS is seconds.

In the future, I could see a setting in the UI being added for the display on a duration sensor.

To add this functionality to the vacuum sensors, just manually customize the entity with

device_class: duration

Also, you should open an issue against the integration that’s creating those entities, as they should be setting the duration device class.

4 Likes

Thanks. I’ll open the issue for the Xiaomi/Milo vacuum as they do not have the device class, e.g.

Though I would still need my template sensors to convert the values to hours for the bar cards I use as row elements:

EDIT:

1 Like

This is great. The notice it was coming also helped me find it and the function is very helpful to me.

Hello. Can you share a card? Thanks

This is an old, but still relevant discussion…

I have everything set up as mentioned here. All I need is to be able to tell the UI to display HH:MM and not HH:MM:SS. I’d love to avoid the extra template sensor.

Is there a FR for this somewhere that I might’ve missed?

IIRC duration sensors already do this. I’m not sure if you can select a display. Timestamp sensors only show relative time. A nice FR would be to give these 2 sensor types “Unit conversion” options to change them into a specific format.

Hmm, maybe just check this, in case I’m missing something:

Sensor:

sensor:
  - platform: history_stats
    name: Baby Sleeping
    entity_id: input_boolean.baby_sleep_mode
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

Customisation:

    sensor.baby_sleeping:
      device_class: duration
      unit_of_measurement: h
      state_class: total_increasing

Display:

Settings:

As you can see, it interprets the sensor as if it’s a numeric value (which I suppose it technically is).

I wonder - does “uom” have any impact on a sensor with the “duration” device_class?
Cannot check it myself right now, just curious.
For instance , if a value “1” has “uom: hour” - will it be displayed as “01:00:00”?
Or, if a value “1000” has “uom: ms” - will it be displayed as “00:00:01”?

Regarding accuracy.
The displayed value is “01:51:31”. You may convert it to hours - and you will get “1,858611111111111”.
If I default value is “1.86”, it should be displayed as “01:51:36”.

1 Like

Yup, I get that. :slight_smile: But I think for dates and times precision should be handled differently. The precision UI was specifically added for presentation purposes. In this case the internal representation looks entirely different, so it doesn’t quite work.

Looks good, there is no Show As on the entity, so different display options are probably not implemented. You’ll probably need to create a template sensor unfortunately.

Thanks, yeah, I’ve done that for some other older sensors. When I implemented this new one I wanted to see if I could avoid it. Thanks again.

Couldn’t find a way to display d hh:mm:ss. It only displays hh:mm:ss, even after going over 24h.

duration device classes go over 24 hours. If yours isn’t, it’s an issue with your template or the sensor itself.