Display of the time recording of individual devices

If your values in InfluxDB are in ms, then change your map function to:

|> map(fn: (r) => ({r with _value: r._value / 1000.0}))

so that it returns values in seconds. As I concluded here, the only way for the duration (hh:mm:ss) to work is for the Influx query to return the value in seconds.

Also, is the aggregateWindow statement needed here? Maybe try it without it. As I understand it, you are simply storing the number of seconds each device is on and you want it to display in Grafana (as hh:mm:ss).

Also, I often see home power consumption queries where people store the kWh used, or the on/off status of something (lamp, television, etc), and then they use an elapsed() function or stateDuration() or something else to calculate the time the device is on. In your query, there does not appear to be any reference to power, so I presume you obtain these running times from some other query or datasource.