Temperature values convert from centigrade to fahrenheit

I am creating my first chart and I am pulling temperature values from a sensor. The values are in centigrade and I need to display them in fahrenheit. I found lots of examples on how to do this but I am using flux as the syntax due to pulling the latest versions of grafana and influxdb

Here is the current code any help on this would be great :slight_smile:


from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "my_sensor")
  |> filter(fn: (r) => r["server"] == "server_name.com")
  |> filter(fn: (r) => r["name"] == "inlet_temp")
  |> filter(fn: (r) => r["unit"] == "degrees_c")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")


|2022-07-03 12:00:15|18 °C|
|2022-07-03 12:00:45|19 °C|
|2022-07-03 12:01:15|19 °C|

Maybe look into map

    |> map(fn: (r) => ({r with _value: (r._value * 9/5) + 32}))
1 Like

I will give it a shot something like this ? need to read up flux and how the language works

from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "my_sensor")
  |> filter(fn: (r) => r["server"] == "server_name.com")
  |> filter(fn: (r) => r["name"] == "inlet_temp")
  |> filter(fn: (r) => r["unit"] == "degrees_c")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({r with _value: (r._value * 9/5) + 32}))
  |> yield(name: "mean")
2 Likes

I was trying the above example but when building the query I get the error

Invaild: runtime error @8:6-8:62: map: type conflict: int != float

Yes you have to unify your data type to be able to perform calculation , you can convert all number to float since you may want decimals,
|> map(fn: (r) => ({ r with _value: float(v: r._value) *9.0/5.0 + 32.0}))
something like that, add decimal to your constant number to convert to float and convert type like this
float(v: r._value)
int(v:r._value)

2 Likes

Thank you your example worked and the value that came back was indeed a decimal value .

nice ! if you want to please us validate one of the answer as solution :wink: