Daily/monthly runtime of heating

I’m using InfluxDB 2,2 with Grafana. In InfluxDb I’m capturing when my heating start and stops.

This is done via a booelan value.

True = Heating running
False = Heating not running

I want to calculate the runtime over a period of time. I.e. heating runtime in hours per day, month etc.

What function do I need to use for this?
Can I use directly the boolean value or do I need to convert them first to something else?

This is my query I’m currently using to display if the heating is on/off

from(bucket: “iobroker”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “modbus.0.coils.80_Verdichter_on/off_diskret”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: “last”)

Which gives me this output

@alen79

Maybe try putting this before the yield() function?

  |> stateDuration(fn: (r) => r._value == "true")
  |> group(columns: ["_value"])
  |> count(column: "stateDuration")

It should give you something like this: