What unit does the DS18B20 output? Fahrenheit or Centigrade?

Occasionally I look through my homeassistant.log file to determine if there is any error or warning that I can fix. Usually a notation to update my configuration.

Now I am noticing a “Please update your configuration” warning. (It’s not new, I just hadn’t noticed it before now).:

2023-01-05 18:47:36.551 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.freezer_temperature_c (<class 'homeassistant.components.esphome.sensor.EsphomeSensor'>) is using native unit of measurement 'C' which is not a valid unit for the device class ('temperature') it is using; Please update your configuration if your entity is manually configured, otherwise create a bug report...

In esphome, this works except for the warning in the log file:

sensor:
  - platform: dallas
    address: 0x350416a036beff28
    name: ${device_name} Temperature_C
    id: temperature_c
    resolution: 9
    unit_of_measurement: C
    
  - platform: template
    name: ${device_name} Temperature_F
    id: temperature_f
    lambda: return id(temperature_c).state * 9/5+32;
    update_interval: 5s

Deciphering the warning and reading the platform notes, I gather that the DS18b20 outputs centigrade, so the “unit_of_measurement: C” is not needed. I commented this line and now the state of sensor.freezer_temperature_C is fahrenheit?

What am I missing?

I think you just need the degree symbol before the “C” for your unit_of_measurement.
E.g. °C

That results in the same fahrenheit output as if the unit_of_measurement line were commented out.

You need to quote the special character though:

sensor:
  - platform: dallas
    address: 0x350416a036beff28
    name: ${device_name} Temperature_C
    id: temperature_c
    resolution: 9
    unit_of_measurement: '°C'

Also units may be converted depending on your profile language settings.

I forgot that, but it doesn’t change the value, just what is displayed.

Maybe this should be a different thread…

I’ve seen other posts about not being able to control the units, but I hadn’t paid much attention to them because all of my temperature sensors are showing Fahrenheit on my Lovelace cards. I set up a simple test on my desktop, a Wemos D1 Mini and a Dallas DS18b20 sensor.

In yaml:

  - platform: dallas
    address: 0x67020D9246E81C28
    name: "Temperature"

The ESPHome logs say:

[D][dallas.sensor:143]: 'Temperature': Got Temperature=6.7°C
[22:41:19][D][sensor:126]: 'Temperature': Sending state 6.68750 °C with 1 decimals of accuracy

So the Dallas is sending temperature in °C.

I added: unit_of_measurement: ‘°C’ and the ESPHome logs said:

[D][dallas.sensor:143]: 'Temperature': Got Temperature=6.6°C
[22:39:18][D][sensor:126]: 'Temperature': Sending state 6.56250 °C with 1 decimals of accuracy

It matters not if I have unit_of_measurement: ‘°C’ or unit_of_measurement: ‘°F’, or no unit_of_measurement, the ESPHome Logs say the same.

But in a Lovelace card, it gets converted to Fahrenheit no matter what Unit I put into the card GUI.

  • type: entity
    entity: sensor.temperature
    name: Temperature
    unit: ºC

How do I get the Lovelace card to show °C?

Because:

Actually it’s not the profile setting it is Settings → System → General:

Screenshot 2023-01-07 at 15-47-11 Settings – Home Assistant

You can change individual sensor units in the device properties / more-info card for the sensor.

Thanks, that’s exactly what I was looking for.