UPS runtime history as graph?

TLDR; how can i turn a value in seconds into a readable time that is still recognized by HA as a numeric value (so the history shows a graph).

I have a Cyberpower UPS which I connect to HA using NUT. One of the things I track is the runtime. The nut sensor exposes this in a weird format: it is the number of seconds * 60. To get this in a human readable format I use a template sensor:

      - unique_id: ups_readable_runtime
        state: "{{timedelta(seconds = (states.sensor.ups_battery_runtime.state | int / 60) )}}"  #"{{timedelta(seconds = (states.sensor.ups_battery_runtime.state | int / 60) ) | timestamp_custom('%H:%M:%S') }}"
        name: Ups looptijd
        icon: mdi:clock-end

This works nicely and shows the runtime in an hh:mm:ss format. However, when I look at the history, it shows as discrete values, not a graph. I tried adding device_class: timestamp and adding as_timestamp in different ways to the value template, but none of that works.

How can I fix this?

Graph this sensor instead sensor.ups_battery_runtime. Or if you want it in seconds create another template sensor that does not format the output as a time string, and give it a unit_of_measurement.

Also please don’t ignore the warnings in the documents:

https://www.home-assistant.io/docs/configuration/templating/#states

Odd that you can’t graph a value which is formatted as time by Home Assistant. You should be able to treat time as a numeric value, not a string. I don’t want to graph the original sensor as its values are off (* 60) and, more importantly I was hoping to be able to just see the graph in the sensor history when you open the details but that does not seem to be possible.

How would you graph time against time?

On the vertical axis. My UPS has a “runtime” at any time, depending on battery status and load. So for example right now that might say 1:30:00 (1 hour 30mins) but later today it could say 1:35:00 if for example the load would decrease. So yes, in this case it does make sense to set the “runtime” on the vertical axis in a history graph to see how it evolves over time.

So maybe there is some confusion over how I use the term “time” but in this case it is the “potential runtime” my ups has left should the power fail. And it would absolutely make sense to see how that evolves during the day.

You are going to have to make another template sensor that has a numeric value, like seconds, minutes or hours.