Visualize location data from InfluxDB in Grafana Geomap

As it took me some time to figure this out, here is how your flux query needs to look like so that the Grafana Geomap panel recognizes the location data stored by openHAB:

import "strings"

from(bucket: "openhab/autogen")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Flash_Location")
  |> map(fn: (r) => ({r with lat: float(v: strings.split(v: r._value, t:",")[0]) , lon: float(v: strings.split(v: r._value, t:",")[1]) }))
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: true)
  |> fill(usePrevious: true)

The important part is the map function. It adds the fields lat and lon to the result based on the values openHAB stores. Those fields are then automatically recognized by the Geomap panel.

Have fun :slight_smile:

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.