Hello,
can you tell me how the code has to be so that I can convert seconds in Grafana and display them in hours and minutes?
The background is as follows: My Wihtings Sleep Sensor Mat gives me the daily bedtime in seconds. So e.g. 24800 seconds would be 6.8 hours. But I would rather have an output in the format 6 hours. 32 minutes.
How can I do that? I’ve been trying for hours, but unfortunately I’m not getting anywhere
Hi @damrak2022,
Thanks for opening this post.
Did you try the option “Standard Option” on the right side of the panel?
If you go into “unit” it will open a drop-down list. Select Time from that and then select hours (h)
Let us know if this helps.
I set it up like this and my panel looks like this:
In my Withings app, the values look like this:
I think that’s going in the right direction, but the question now is how do I display the values 6.72 or 2.95 correctly, because an hour has only 60 minutes and so the display is of course 6.72 or acu 2.95 wrong. Do I still have to change the code and if so, what does it have to look like?
Is the problem just to have 6.72 hours dispayed at 6h34m (or 06:34)? Wouldn’t a custom unit like this work?
I can’t set time:hh:mm under unit. For me there is only duration hh:mm:ss and then the result is completely wrong. Even if I enter it by hand, it is completely wrong.
I tested on some of my data and you are correct in that the HH:MM values are not correct.
Here is some data that I have, which is in hours:
and here is that same data with the unit duration:(hh:mm:ss)
Basically, it thinks that my units were seconds, so 14.9 seconds gets displayed as 00:00:14.
Going back to my Flux query, I was calculating the elapsed time in seconds of a switch state being ON, and then converting it to hours using the map statement. Removing the map()
function, we have:
Since the above values are in seconds, we can use the unit duration:(hh:mm:ss) and get this:
So long story short…build a Flux query that returns the value in seconds, then use the unit duration:(hh:mm:ss)
My flux request looks like this everywhere. Can you please explain to me what I have to change here, because unfortunately I’m not that fit yet.
The values that I record are in Unix format. see the screenshot
What is the unit of measure for these values? Newtons? Seconds? Minutes? Nautical miles?
I am trying to understand how the above output relates to your originally posted query, i.e.
import "timezone"
option location = timezone.location(name: "Europe/Berlin")
from(bucket: "DBANDY1")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Laufzeit_Imac")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 24h, fn: sum, timeSrc: "_start")
Value is the duration a device is switched on measured in minutes.
OK, so if it’s in minutes, you need to convert it using a map()
function to convert it to seconds, because (as I concluded in the original post above), you need your Flux query to return the value in seconds, then in Grafana use the unit duration:(hh:mm:ss). See below and see if that works for you.
import "timezone"
option location = timezone.location(name: "Europe/Berlin")
from(bucket: "DBANDY1")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Laufzeit_Imac")
|> filter(fn: (r) => r["_field"] == "value")
|> map(fn: (r) => ({r with _value: r._value * 60}))
|> aggregateWindow(every: 24h, fn: sum, timeSrc: "_start")
A friend just told me I explained this wrong. The values are:
that comma is decimal separator.
Sorry, it doesn’t work - see here:
If you hold the mouse over the red part, what is the error message?
This is the error message
invalid: runtime error: type conflict: int != float
In the map function, instead of 60 try writing as 60.0 and see if the same error message appears.