“ESPHome Sensor Showing Correct Raw Temp but Sending Wrong State (Unexpected Conversion?)”

My Dallas DS18B20 sensor shows correct raw temperatures in logs (e.g., 19.6°C), but ESPHome reports a different value to Home Assistant (like 30.4°C). I suspect a leftover conversion or filter, but I’ve rebuilt it several times. There was an early version with unit_of_measurement: set as F° that was changed. Reports fine with an offset but not when calibrate_linear is applied instead.

  • ESP8266 board (D1 Mini)
  • Dallas DS18B20 sensor on GPIO2
  • 4.7KΩ Resistor
  • ESPHome version: [2024.12.4]
  • Home Assistant version: [2025.1.4]

Setup Details:

What’s happening:

  • Raw log shows correct temp: Got Temperature=19.6°C
  • ESPHome sends wrong state: Sending state 30.41944 °C
  • Home Assistant reports this inflated value as around 86°F+

What I’ve tried:

  • Removed lambda functions, filters, and calibrations
  • Cleaned build files (esphome clean)
  • Erased flash (esptool.py erase_flash) and reflashed
  • Tried minimal config with no filters
  • Tested multiple calibrate_linear and offset setups
  • Added state_class: “measurement”

Logs

[23:58:30][D][dallas.temp.sensor:054]: 'Water Temperature': Got Temperature=19.6°C
[23:58:30][D][sensor:093]: 'Water Temperature': Sending state 30.41944 °C with 1 decimals of accuracy

YAML

esphome:
  name: fish-tank-temp
  friendly_name: Fish Tank Temp

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fish-Tank-Temp AP"
    password: !secret sexy_ap_password

captive_portal:

button:
  - platform: restart
    name: "Fish Tank Temp Sensor Restart"

 # One witre configuration 
one_wire:
  - platform: gpio
    pin: GPIO2
    

sensor:
  - platform: dallas_temp
    address: 0xe3000000365c4c28
    name: "Water Temperature"
    update_interval: 5s
    unit_of_measurement: "°C"
    device_class: "temperature"
    state_class: "measurement"
    filters:
      - calibrate_linear:
          datapoints:
            - 5.0 -> 0.0        # Ice water reading -> 32°F / 0°C
            - 14.0 -> 18.8      # Room temp reading -> 65°F / 18.3°C
      
      #- offset: -5.0   # Original Offset / Subtracting 8.1°C from the sensor reading

      #- sliding_window_moving_average: # Removed for Troubleshooting
      #    window_size: 5
      #    send_every: 1
      #    send_first_at: 1

Remove this:

And then you will get the raw value.

That linear equattion is returning 2.1* raw_value -10.4

So a raw_value of 19.6 → 30.5 which is exactly what you are seeing.

Its not quite linear, but close

Rounding error. They only have two points. Thus it is a linear equation.

Actually I drafted my response before you posted. Yes, it seems to be exactly as expected, given the config.

Ok, so I sorta understand but… then I’m confused as to how I properly calibrate this sensor. When I apply a direct offset to get the correct temperature in Ice water, the temperature is then way off at room temp once its removed from the ice water. The ice water is the only known variable I have to calibrate with besides a rough average of all my ambient temperatures. I don’t have a way to gather additional data points (which is why I have 10+ LYWSD03MMC’s and countless other temp sensors reading differently in my home)…Boiling water maybe? Do I have to a slope and intercept? I’m getting confused and frustrated.

Why do you think you have to calibrate it at all?

The DS18B20 has a ±0.5°C accuracy.

Calibrating a sensor with methods that are less accurate than the sensor output in the first place is silly idea.
Also, it a sensor is set up to measure for example ambient temperature, it should be calibrated with that temp range. Not with ice / boiling water.

1 Like

Because, it certainly wasn’t giving me a ±0.5°C reading accuracy. hence the original 5° offset. 3 different sensors and non of them gave near that delta. I have to monitor temperatures as best I can where 2 ° 's is a very big deal. I’m no longer great with math these days but my intellectual capacity certainly remains at a competent level , and as such I wouldn’t have tried to adjust a ±0.5°C accuracy. Its not emi/emf pollution because I switched to dual shielded cables with a drain wire, used a low noise power supply and even tossed on farrite’s to see if that helped any.

Then you have either purchased counterfeit sensors or there is heating coming from somewhere else (like the ESP CPU).