Calculate operating hours

Hello all,

I would like to calculate in flux, operating hours.
I have current values, if they go above a value, the time should be calculated in hours.

How do I do this?

from(bucket: "VH_Messwerte")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["topic"] == "Energie/VT100m/Strom/L1" or r["topic"] == "Energie/VT100m/Strom/L2" or r["topic"] == "Energie/VT100m/Strom/L3")
  |> filter(fn: (r) => r._value  > 4000)
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)

  |> elapsed(unit: 1s)

Hello @matze1708,
I’d use a map() function to assign a level based on a threshold.
Then I’d use stateDuration() to calculate the duration of the “above a value” time.