How to convert C° to F° in Flux?

Hello, I am using InfluxDB V2 w/ Grafana to visualize my data, the data is coming in just fine to grafana, but it’s in C° as that is what the sensor itself reports, can someone please take a look at my script and let me know how I can convert the value to F°? Thank you!

from(bucket: “Test 3”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “sensor_data”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: “last”)

Bumping this topic to see if anyone can help, I have been researching for the last two days, I have tried multiple variations of |>map trying to do value *1.8 + 32.00 but cannot get this to work, If I cannot get this data to read in F° I will have to abandon influxdb and utilize another database with this functionality.

add

|> map(fn: (r) => ({ r with _fahrenheit: r._value * 1.8 + 32.0 }))

1 Like

Thank you so much! It works now, but I am now running into another issue, instead of the query just displaying the gauge with F, it’s also displaying it in C, any idea how to get it to only display the F value?

Here is my full script along with a screenshot from Grafana.

from(bucket: “Test 3”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “sensor_data”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: 15m, fn: last, createEmpty: false)
|> map(fn: (r) => ({ r with _fahrenheit: r._value * 1.8 + 32.0 }))
|> yield(name: “last”)

You can select the fields to display in the Fields section of the gauge settings.

220930_221617

A better solution is probably to remap the _value itself instead of creating a new _fahrenheit field.

|> map(fn: (r) => ({r with _value: r._value * 1.8 + 32.0}))

I would place the |>map line before the aggregateWindow function.

I appreciate you more than you know! I am extremely unfamiliar with flux and have a very critical project assigned to me that needed this functionality so this was a lifesaver, thank you again!!

Yeah, Flux is really… annoying. I don’t know why the inventors of Influx couldn’t stay with an SQL-near syntax which is far better to understand.