Transform -> Convert Field Type fails if my input is an "On"/"Off" string

  • What Grafana version and what operating system are you using?

Grafana v11.2.2 on a Raspberry Pi 5 Bookworm. Data source is InfluxDB on the same Pi.

  • What are you trying to achieve?

Ultimately a “logic analyser” time series view like Boolean values in Graph pannel - Grafana / Time Series Panel - Grafana Labs Community Forums, where each on/off input is graphed vertically offset from the others. I’m trying one step at a time and falling on the first hurdle.

  • How are you trying to achieve it?

I have multiple inputs I want to graph, and for each the query returns a String with values of “On” and “Off”.

I’m trying to convert “On” to the number 1 and “Off” to number 0, so I can then perform maths to add an offset to the value returned by each query, building the ‘layered’ logic analyser view in the example linked above.

  • What happened?

I’ve not had any success with Transform data / Convert field type. If I choose Number, the output is always ‘null’. As a test I also tried Boolean, and again, my results were always “true” even when the input was “Off”.

I couldn’t determine if Value Mappings are calculated before Data Transforms, and I also tried to map “On” to 1 and “Off” to 0 without success.

  • What did you expect to happen?

Ideally, “On” becomes numeral 1. From there I think my job is all downhill.

  • Can you copy/paste the configuration(s) that you are having problems with?

image

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

no errors.

  • Did you follow any online instructions? If so, what is the URL?

Lots, including a brief frustrating session with chatGPT.

Here’s the official documentation:
Transform data | Grafana documentation

I’ve also experimented with other Transforms, including ‘Add field from calculation’, and also trying to tweak the SQL query to add an “IF” or “CASE” to do the conversion ‘upstream’, but any attempts at those threw errors.

Am I approaching this wrong? TIA for any assistance.

Use Grot instead not chat gpt

Also convert won’t convert such string to numeric

Do it on the flux side of things with map or use Overrides

Thanks for the quick response.

Unfortunately I can’t change it in Influx because the data’s variable: sometimes it’s a numeral, other times strings, so I’ve needed to write everything as the lowest common denominator: a string. (For the panels that require numeric input, the Convert field type → number works well).

Using an override doesn’t appear to make any difference:

image

This still doesn’t work. :frowning:

That seems very problematic. Hard to expect grafana to handle “bad” data

It’s the environment I find myself in: I’m logging data being sent to a bus, and the “value” changes type depending on the sender and receiver. They interpret it as required. Unfortunately it’s Influx’s inflexibility here that’s the rub.

Is there NO way Grafana can be coerced to re-interpret these values? I’ve tried a few other Transformations (e.g. Add field from calculation) without success.

It looks to me like InfluxQL doesn’t support CASE or IF, so I think that alternative approach is blocked for me: Explore data using InfluxQL | InfluxDB Cloud (TSM) Documentation (influxdata.com)

@yosiasz has a very good suggestion above. If you can switch your query language from InfluxQL to Flux, then you should be able to do what you are attempting.

Unfortunately flux is being deprecated, and as I’m building a new open-source application here it makes sense to steer clear of it. :frowning:

1 Like

Just in case you did not see this, there is an effort in the open source community to keep Flux maintained. Paul Dix (InfluxData CEO) has supported this as well.

2 Likes

Ouch!
Make it standardized before writing to influxdb?

I think this would be an issue in any backend

Unfortunately I’ve already standardised the data, and string was the lowest common denominator.

I’ve been going well until now. Convert field type → number works well for my “stringy numbers”. (I’m still surprised Convert field type → boolean can’t normalise "On/“Off” to bool!)

Think non English data coming in…

French
allumé et éteint