Flux query equivalent - power usage

Hi

I need help converting a query from QL to Flux. It works in QL fine, but I want to group by month which Flux can do well.

The query basically gives me a time (in minutes) the power was above a certain value (in this case, 320W)

QL:
SELECT count(“value”) / 6 FROM “one_year”.“heating_ppnorth” WHERE (“value” > 320) AND $timeFilter GROUP BY time(30d) fill(null) tz(‘Pacific/Auckland’)

I end up getting results via QL like this:
2022-06-26 00:00:00 1.83 hour
2022-06-27 00:00:00 4.05 hour
2022-06-28 00:00:00 3.12 hour
2022-06-29 00:00:00 1.21 hour

The underlying data provides power consumption in watts, written to InfluxDB every 10 seconds. The query above will count every minute it’s running above the threshold and I’ve got a transformation on the chart which will Total each day.

Figured it out, if anyone else needs this, I used:

from(bucket: "bucket/default")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "ppnorth" )
  |> filter(fn: (r) => r._value > 320.0 )
  |> aggregateWindow(every: 1mo, fn: count)
  |> map(fn: (r) => ({ r with _value: float(v: r._value) / 6.0 }))
1 Like