I configured Flux for my grafana mqtt temperature sensor (gathered via zigbee2mtqq > mosquitto > telegraf > influxdb2).
I have this simple flux query that generally does work:
from(bucket: "homeassistant")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mqtt_consumer")
|> filter(fn: (r) => r["_field"] == "temperature")
|> filter(fn: (r) => r["topic"] == "zigbee2mqtt/Arbeitszimmer/SENSOR" or r["topic"] == "zigbee2mqtt/Schlafzimmer/SENSOR")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
However my legend contains these entries:
temperature {host="192.168.0.42", topic="zigbee2mqtt/Schlafzimmer/SENSOR"}
temperature {host="192.168.0.42", topic="zigbee2mqtt/Arbeitszimmer/SENSOR"}
I spend a lot of time to search this forum and google but could not find a way on how to specify the actual label content. I would like them to just read “Schlafzimmer” and “Arbeitszimmer”.
I could see that in InfluxQL you are able to do that with ALIAS / GROUP BY statements. But I am unable to find how to do that using Flux in grafana.
Any help much appreciated!