#How to show Sensor data in Hours rather than Seconds?

1 messages · Page 1 of 1 (latest)

crude dock
#

I have a weird issue showing data from my UPS. The raw incoming data seems to be in seconds, but:

When I add the data as an entity to the dashboard, it shows in Hours:Minutes

When I add the data as a sensor to the dashboard, it shows in Seconds

What I want is to show it in Hours:Minutes:Seconds in the Sensor as well.

How can I do that?

Some research shows I would need to make a custom sensor (by editing the configuration.yml file?) but I'm scared that if I do something wrong there HA won't boot.

Would this work? Do I add that at the bottom of the configuration.yml in the File Editor?

sensor:
  - platform: template
    sensors:
      formatted_time:
        friendly_name: "Formatted Time"
        value_template: >
          {% set seconds = states('sensor.your_sensor') | int %}
          {% set hours = (seconds // 3600) %}
          {% set minutes = (seconds % 3600) // 60 %}
          {% set seconds = seconds % 60 %}
          {{ '%02d:%02d:%02d' | format(hours, minutes, seconds) }}

But I would like to double check it here for sanity's sake, as I never edited any yaml and always used the visual GUI.

Also, the entity in the screenshot shows Minutes:Seconds, I would like it to also show Hours, even if they're zero. Is that possible too?

twin summit
#

Hi, you don't need to edit the configuration any more to create a template sensor. You can make one in the UI at Settings > Devices & Services > Helpers.

still vault
#

When I add the data as an entity to the dashboard, it shows in Hours:Minutes
When I add the data as a sensor to the dashboard, it shows in Seconds

I guess that's just a limitation of the sensor card, it doesn't use the HH:MM:SS formatting like some other cards do

#

If you try to make a custom sensor, then you won't be able to display it in a sensor card, because it won't be recognized as numeric.