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?