Why is unit_of_measurement: '°F' not working?

Hello everyone. I just setup ESPEasy + BME280 with HA. In configuration.yaml file I put this (see below), and HA won’t accept the degree sign. If I get rid of the sign, everything works but obviously it doesn’t convert C to F. What am I missing?

sensor:
- platform: mqtt
name: “BME280 Temperature”
state_topic: “home/ESPE_Ali/BME280/Temperature”
unit_of_measurement: ‘°F’
device_class: temperature

be careful about the “type” of apostrohpe. '°F'

Edit: or does “imperial” work?

How have you configured unit_system? The choices are metric or imperial. If you set it to imperial, Home Assistant will assume all received temperature values are in Fahrenheit and will display them in Fahrenheit.

homeassistant:
  unit_system: imperial

If you have unit_system: metric and wish to display a temperature sensor’s value in Fahrenheit then unit_of_measurement: '°F' will cause the value to be converted from metric to imperial.

The begining of configuration.yaml file it says imperial, from ESPEasy I get the value in C so the “imperial” should turn it to F but didn’t happen (this is without unit_of_measurement: ‘°F’) . Later, I tried both apostrohpes, didn’t work and even when I do the correct way and save it, in HA configuration- Configuration validation it comes out as error,

“Error loading /home/homeassistant/.homeassistant/configuration.yaml: ‘utf-8’ codec can’t decode byte 0xb0 in position 1807: invalid start byte.”

I have no idea what that means but I tried to pinpoint the issue and it turns out the degree sign is causing it, I don’t know is it because of imperial already setup or something else.

If I remove " unit_of_measurement: ‘°F’ ", I am still receiving in C.

No.

unit_system: imperial means to handle all received data as being in the imperial unit system (and to present it in imperial units). That means Home Assistant will treat the temperature value received from the ESPEasy as being in Fahrenheit. So if the sensor is actually sending values in Celsius, that’s unknown to Home Assistant because it was set to unit_system: imperial.

‘0xb0’ is your º. use the ‘0xba’ one. If you hold alt+167 it will create the correct one. So:

Hold Alt, then type 1 6 7 on the number pad.

unit_of_measurement: 'ºF'

and if that doesn’t work, just remove the degree.

1 Like

Works here:

#MQTT Sensors
  - platform: mqtt
    name: "Attic Temp."
    state_topic: "attic/temperature"
    force_update: true
    unit_of_measurement: "°F"
    
  - platform: mqtt
    name: "Attic Light"
    state_topic: "attic/light_status"
    force_update: true
    
  - platform: mqtt
    name: "Room Temperature"
    state_topic: "tele/room/SENSOR"
    value_template: "{{ value_json['DHT11'].Temperature }}"
    force_update: true 
    unit_of_measurement: "°F"   
    
  - platform: mqtt
    name: "Room Humidity"
    state_topic: "tele/room/SENSOR"
    value_template: "{{ value_json['DHT11'].Humidity }}"
    force_update: true 
    unit_of_measurement: "%" 

Since you didn’t follow the instructions at the top of the forum for posting code, I can’t determine if you used the right quote marks or not. (The forum editor makes them grammatically “correct”). In my code, the degrees mark is inserted as alt+0176.

Lol don’t ask me why but I have been Alt + 0176 ing. However, that did not convert C to F. It just put ºF right next to the temp that is in C.

So just to be clear, if I have already put imperial, HA assumes the data fed is in F format? So imperial does not automatically receive C temp and convert it to F temp? Then what is the point behind imperial?

Btw is " unit_of_measurement: “°F” " just for labeling? It doesn’t do any conversion?

Not quite “assumes”, you are explicitly telling it that you wish to operate with the imperial unit system. In other words, you are instructing Home Assistant to handle received data as being in imperial units (where applicable). Accordingly, Home Assistant will display the data in imperial units without conversion.

So imperial does not automatically receive C temp and convert it to F temp?

No. When you set unit_system: imperial, you are indicating the received data, like temperature, will be in imperial units . If you then proceed to include sensors that report their data in metric units, Home Assistant does not know which are metric and which are imperial. It will handle all of them according to whatever unit_system is set to.

It doesn’t do any conversion?

I don’t know how it works in the latest version but in 0.80 (the version I am using) it does perform a conversion … but maybe not the way you expect. Here’s what I mean:

  • My unit_system is set to metric.
  • I have an existing indoor temperature sensor that reports 20.5 °C (in a badge).
  • I created a copy of the indoor sensor but with unit_of_measurement: '°F'
  • The second sensor reports -6.4 °C (in a badge).

What happened here is that it interpreted the 20.5 as being a temperature value in Fahrenheit and converted it to Celsius. 20.5 F is -6.4 C.

1 Like