Friendly Time Conversion not working

Hello,

New to Home Assistant so forgive any newbie mistakes.

I have the following in my Configuration.yaml to create a custom Template Sensor for displaying my UPS Runtime as a Friendly String instead of displaying only the seconds remaining.

sensor:
 - platform: template
   sensors:  
     myups_battery_runtime_friendly:
       friendly_name: 'UPS Time Remaining'
       value_template: "{{ states('sensor.myups_battery_runtime') | int | timestamp_custom('%H Hours, %M Minutes, %S Seconds', 0) }}"

sensor.myups_battery_runtime is currently showing a value of 4944. If I manually do the conversion to hours I get: 1.373333 Hours.

When using the above value_template I am getting: 01 Hours, 22 Minutes, 24 Seconds

Why the difference of ~15 Min?

sensor.myups_battery_runtime is the seconds of remaining battery runtime as returned from the NUT UPS Integration.

The β€œ.373333” of β€œ1.373333” is 37-one hundredths of an hour, not 37 minutes.

60 minutes per hour * 0.37 hours = 22.2 minutes. It’s working perfectly. :slight_smile:

Thank You. Makes 100% sense. Thought I was losing my mind.

1 Like

I’ve been there. :slightly_smiling_face: