Configuration Template. How To convert F to C on temperature?

preface; been at this under a week, still trying to figure out most of the HA stuff. go easy on me.

I have a 4-in-1 sensor which reports temperature in F only. I’m in Canada, i want to see it in C.
How do i do this?

I have spent some time reading threads, and i think it’s via a template of some sort. Took me about 15 minutes just to figure out how to even add the customize.yaml into the config. (most of my config up till now has been GUI. so very few yaml configs except an mqtt and tts entry. )

i’ve put this in my customize.yaml: everything is indented with spaces, 2 per level.

- platform: template
  sensors:
    inov_sensor_temperature_air:
      unit_of_measurement: 'C'
      value_template: '{{ (value -32 ) * 5/9 }}'

that gives me an “expected a dictionary for dictionary value @ data[‘customize’]” error.

what am i doing wrong here please?

1 Like

Not sure if this is what you want or will work in your situation but I have my HA set up to read everthing in F as I live in the United States. But I also recently added my 3d printers and I wanted those temp sensors to report in C.

I was able to make the change by putting this line in my configuration.yaml.

homeassistant:
  customize: !include customize.yaml

Then in my config folder I created a folder named “customize” and added these lines, which set each sensor entity that I wanted to report in C.

sensor.ender3_actual_bed_temp:
  unit_of_measurement: 'C'
  friendly_name: Bed Temperature
  icon: mdi:thermometer
sensor.ender3_actual_tool0_temp:
  unit_of_measurement: 'C'
  friendly_name: Nozzle Temperature
  icon: mdi:thermometer
sensor.ender3_target_tool0_temp:
  unit_of_measurement: 'C'
  friendly_name: Nozzle Target Temp
  icon: mdi:thermometer
sensor.ender3_target_bed_temp:
  unit_of_measurement: 'C'
  friendly_name: Bed Target Temp
  icon: mdi:thermometer

yea, i found your thread, and I did try something like that, but all it did was change my sensor from 73 F to 73 C, didn’t actually change the numeric value.

Like I said this may not work for you if your device only reports in Fahrenheit. You may have to do some conversion to get it to show in celsius. I am also still really new to this. Make sure you add the customize command in your configuration.yaml to point to the new folder.

Did you set your configuration correct ? (Developer Tools -> General)

image

yes, my configuration is set to Metric.

it doesn’t seem to make a difference. everything is coming in via MQTT if that makes a difference.
image

Manually configured mqtt or auto-discovered ? If manual configured, you can calculate the F -> C . I think (but should check) you need to substract 32 and then multiply by 5/9.

mqtt config is manual;

mqtt:
  discovery: true
  discovery_prefix: homeassistant
  broker: 10.10.1.84
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

i have the formula to convert, but i dont know how / where to apply it. (top post which doesn’t work)

or do you mean the devices…
all the devices are auto-discover.

Just checking, you do have this line in your configuration.yaml correct?

homeassistant:
  customize: !include customize.yaml

yes. but the sample code i put above isn’t in the customize.yaml at this point, as it was causing an error.

This don’t go under customize.yaml :

- platform: template
  sensors:
    inov_sensor_temperature_air:
      unit_of_measurement: 'C'
      value_template: '{{ (value -32 ) * 5/9 }}'

Either this in customize.yaml :

    sensor.inov_sensor_temperature_air:
      unit_of_measurement: '°C'

Or this in sensor.yaml : (or configuration.yaml under sensor: )

- platform: template
  sensors:
    inov_sensor_temperature_air_in_C:
      unit_of_measurement: '°C'
      value_template: '{{ (sensor.inov_sensor_temperature_air.value -32 ) * 5/9 }}'
1 Like

OK good to know. I am still learning as well.
Thank you

i dont currently have a sensor.yaml
i assume that would be addressed with a sensors: !include sensor.yaml ?

I did try just setting the unit of measure to C, but that didn’t auto-change the value, it just made it report 74 C. when i try to do ‘°C’ with the ‘degree’ i get the following error:
‘utf-8’ codec can’t decode byte 0xb0 in position 76: invalid start byte
it doesn’t like that character. is there an alternate unicode for the degree symbol?

regardless, i’ll try under sensors next, as i was trying to put that in customize.
Thanks.

I suspect this may not work

see the docs for template sensor and the changing units example: Template - Home Assistant

You can test your calculation in the template section of developer tools: developer tools → template

type in your formula and see what it evaluates to. Once it works, you can put that calculation in your template sensor (in the sensors.yaml file if that is what your configuration points to.

I stand corrected (still early here, had no coffee yet)

Indeed, sensors. !include sensor.yaml

and then

- platform: template
  sensors:
    inov_sensor_temperature_air_in_C:
      unit_of_measurement: 'C'
      value_template: '{{ (states('sensor.inov_sensor_temperature_air') | float -32 ) * 5/9 }}'

ah hah! and Yay.

sensor:
  - platform: template
    sensors:
      inov_sensor_temperature_in_c:
        unit_of_measurement: 'C'
        value_template: '{{ (( states("sensor.inov_sensor_temperature_air") | float ) -32) *5/9 }}'

couple things… it didn’t like the capitol ‘C’ in the name, had to make lower case. and the quotes in the quotes, changed to double quotes. that is returning a C value now on that new sensor.

next question… how to round the value_template to 2 decimal points ?

sensor:
  - platform: template
    sensors:
      inov_sensor_temperature_in_c:
        unit_of_measurement: 'C'
        value_template: '{{ "%.2f"|format((( states("sensor.inov_sensor_temperature_air") | float ) -32) *5/9) }}'

thank you so much… such a little thing to bang head into wall for two hours for!

one last question, trying to add the thermometer icon to the new sensor, but when i add
icon: mdi:thermometer
under the sensor, it says [icon] is an invalid option for [sensor.template]
would i have to add the icon line under customize instead?

answered my own question, yes it works in customize.