Compensate the value of a sensor

Hi! Good Morning.
I have observed that my Xiaomi temperature sensor gives me half a degree more than a mercury thermometer. Is it possible in Home Assistant to compensate the value of a sensor? Thank you very much

I think you will need to use a template sensor something like this:

- sensor:
    room_temp:
      friendly_name: Room Temperature
      value_template: >-
        {{ (states('sensor.room_temp_raw')) | float - 0.5  }}

room_temp_raw is the value from the sensor and room_temp is the adjusted temperature.

1 Like

Thank you very much Jonah. It works perfectly

Interesting approach, but of course static, and most errors are not linear. Is there a way to add a matrix/function to have a compensation value depending on the current measured value?
Something like: 0-10 => +0.75, 11-25 => +0.5, 26-35 => -0.38
or a hash with values from 0-40 degree having an compensation factor?