Temperature Sensor Fahrenheit to Celsius

I have read a number of threads in here and trialled a number of json formula’s before posting. I have a temperature sensor that outputs Fahrenheit and I want to convert it to Celsius… simple right.

Here’s what I am dealing with…

The MQTT Explorer output

The configuration.yaml code

mqtt:
  - sensor:
      name: "FX100+ Temp"
      state_topic: "selfmon/vmod.011159/temperature"
      unit_of_measurement: "°C"
#      value_template: "{{ value_json.temperature }}"

You will note the value_template is commented out… that’s because I have been trialling with and without.

Here’s what I see in the dshboard… note the celcius icon but the temperature is in Fahrenheit.
FX100_Temp_Dashboard

Embarrassed to ask, as obviously I am doing something wrong in the json area… I have tried a number of formulas to try and convert from Fahrenheit to Celsius but no success.

And yes, I have changed the unit of measure to Fahrenheit… and here’s what I see.
FX100_Temp_F

I have seen some posts that say if the HA is set to Celcius it will convert… so maybe I am missing something?

Ok, tried…

value_template: "{{ ((value | float) - 32) / 1.8 }}"

Which seems to convert correctly… but I am stuck on rounding the temperature output to XX.X as I get XX.XXXXXXXX which doesn’t look great.

You can set the precision in the UI, or in your template. My guess would be that you were only rounding the number 1.8 as filters preceed all other operations. You need some brackets like this:

{{ ((value | float - 32) / 1.8)|round(2) }}

Thank you, much appreciated.

I was close… but not close enough

"{{ {'Celsius': (value - 32) / 1.8 | round(2)} }}"

Hmmm… the code you offered throws an error? I also tried below, and it throws an error to…

"{{ ((value | float) - 32) / 1.8 | round(2)) }}"

Interesting.

What error?

Also neither of what you posted is what I did:

Fair enough, I agree my post didn’t explain it well.

After adding the suggested code you provided I went to the screen below and clicked on the ALL YAML (red circle) and it gave me a red square error… when I normally get a green box with a tick.

I’ve completely deleted the code and re-entered with the code from your help. Here’s the code I loaded, with your help:-

mqtt:
  - sensor:
      name: "FX100+ Temp"
      state_topic: "selfmon/vmod.011159/temperature"
      unit_of_measurement: "°C"
      value_template: "{{ ((value | float - 32) / 1.8)|round(2) }}"

I’ve restarted the yellow instead of clicking on the ALL YAML option, and it now appears to be working. Apology for any confusion, or if I’ve done something I shouldn’t have.