Average value from InfuxDB v2

Hi guys,

I have 2 outdoor temperature sources that I can save in InfuxDB v2. Now I’m trying to write Flux query in Grafana to display the average temperature graph. Both temperatures have the same “measurement”, “field” and “where” tag, and difference is only “source” tag.

from(bucket: "netatmo")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "meteodata" and
    r._field == "temperature" and
    r.where == "outdoor" and
    r.source == "netatmo"
  )

If I do not specify r.source, I have 2 lines in my graph. But I need only one line, calculated average from 2 values. How I can get it?

Maybe problem is that temperature values are NOT stored at the same timestamp because it is from 2 devices and this sendings data randomly, when temperature change. Sometimes the temperature is sent twice per minute, sometimes one per 3 minutes. I need an average value with 1-minute timeframe.

Thanks for your help.

Hello @oldrichsveda,
I believe you want to use aggregateWindow() in this case. Please give it a try and get back to me!

Hello @Anaisdg I tried aggregateWindow() but there is one problem. Netatmo temperature data is every 5 minutes, but data from Loxone is random. If I need one minute data, I need to “copy” data from last measurement at Netatmo and agregate average data per minute from the Loxone before plotting to graph. But I don’t know how.