How can I use key/value variables in formatting?

I’m trying to suss out how to format my key/value pair dashboard variable. I’ve got a variable whose definitions is this:

4431 : Storage,8298 : Stairs,11041 : Closet,13781 : Attic

If I access these (the variable is named sensor) in my dashboard, I can get the keys easily:

SELECT last("battery_ok") FROM "autogen"."Acurite-Tower" WHERE ("id" =~ /^$sensor$/) AND $timeFilter GROUP BY time($__interval) fill(null)

However, I cannot figure out how to access the value from them. I don’t know how to use the above variable definition and, say, give the graph a title for each value.

I’ve read the formatting docs and all they mention are lists; there are no key/value examples on there, and certainly none that do this. It’s clearly a new-ish feature (here is the GH issue where its implementation is merged) so I’m hoping there’s just a doc miss somewhere.

Key/value dashboard variables are available only for some datasources (where it makes sense). InfluxDB doesnt support that.

I would recommend to read Grafana datasources doc to see what is supported/available. E.g. mysql supports that MySQL | Grafana Labs

That doesn’t line up with my experience. The query I showed up there works just fine, because it’s referencing the IDs in that k/v variable. What I can’t do, for some reason, is reference the value of it.

(I actually don’t see anything in the MySQL doc about how to use key/value variables either)

In any case, this variable isn’t coming from influxDB, I’m defining it as a custom variable.

Maybe I’m misunderstanding something here, but the templating language seems to be provider-agnostic, so I don’t follow your reponse.

1 Like

Maybe something like this will work
WHERE (“id” =~ /^${sensor:value}/)

1 Like