Help with adjusting temperature sensor!

I’m trying to calibrate my temperature sensors by adjusting the temperature to match a master sensor. I have read this is done by using a template (https://home-assistant.io/docs/configuration/templating/). I can’t understand how this is done.

Could someone please give my an example for a template that adjust a temperature sensor with entity name “sensor.temperature_158d0001b7b128” say +1 degree celcius?

1 Like

Also interested in this - will write back if i stumble upon anything …

I received a suggestion on another forum but i haven’t had time to try this yet:

{{ states.sensor.temperature_158d0001b7b128.state | float + 1 }}

This should add 1 degree to the temperature sensor with entity name “sensor.temperature_158d0001b7b128".

ah yes, that looks like the exact example i found haha.
alas, I’m not 100% sure where to plop that. i tried doing it in the ‘customize.yaml’ but with no luck (yet!).

And every thread about this i find on the forum seems to be pointing people to very broad “how-to” pages (that i’ve read!) that assume some prior knowledge, without actually giving the answer haha. ahhhh well

I’ll come back to this conundrum one day when things make a bit more sense perhaps, I’m still early in my hassio set up :smiley:

Where do you put “{{ states.sensor.temperature_158d0001b7b128.state | float + 1 }}” do you simply go to <> in the menu on the left at the bottom and then enter it in the JSON field ?

1 Like

It’s a bit blind leading the blind here but I think you should add the template under sensor: in configuration.yaml. I added this to my configuration.yaml:

sensor:
  - platform: template
    sensors:
      sun_state:
        friendly_name: "Kitchen temperature adjusted"
        value_template: >-
          {{ states.sensor.temperature_158d0001b7b128.state | float + 50 }}

After a restart of Hass.io I got a new virtual device that showed the original sensors value plus 50. The sensor is NOT however a temperature sensor, it’s showing under states as “sensor.sun_state” (?!) and only show time active when clicked on in the GUI, not a graph with values over time as the other temperature sensors.

5 Likes

ah yes, i get the same as yours - it’s still a step fwd though!

screengrab

I’ll have a click around this afternoon and see if I can fumble a way around getting to a graph like we want.

got it - you need to add a unit of measure to it:

unit_of_measurement: '°C'

1 Like

It’s sensor.sun_state because you named it that way. If you want to change it you just have to replace the 4th line of your example with the name you want it to have.

To see it as a graph in the pop up you have add to add the attribute unit_of_measurement with either °C or °F as value.

Hello

I have the same topic but just with a humidity sensor:

sensor:
  - platform: template
    sensors:
      sun_state:
        friendly_name: "Humidity adjusted"
        unit_of_measurement: "%"
        value_template: >-
          {{ states.sensor.temperature_158d0001f54796.state | float + 2 }}

How can I change the value to let’s say 70 to 72? +2 does not really do it… I end up with 21.6%… is there a trick ? or is float not correct for humidity?

1 Like

Hey there!

The problem looks to be you’re calling your temp sensor instead of your humidity sensor. This part:

sensor.temperature_158d0001f54796

Needs to be replaced.

1 Like

I feel stupid now

1 Like

No way! The forum is here for exactly this purpose! I’m new to homeassistant and was glad I could help someone for a change :smile:

2 Likes

Looks like you’ve got this all sorted but I did it differently.

Rather than creating a new temperature, resulting in having both the original and adjusted temperatures, I wanted to just fix the original temperature directly so simply subtracted the value I wanted when the value was being gathered in the first place. It seems to work for me, but maybe I have a different goal than you. If nothing else then it may be helpful to someone else doing the same as me in the future.

This is from an ESP8266 via JSON from MQTT.

Mad that 2 DS18B20 sensors are so wildly different, 5.5 degrees in my case!

  • platform: mqtt
    name: “MultiSensor1 Temperature”
    state_topic: “tele/MultiSensor1/SENSOR”
    value_template: “{{ value_json[‘DS18B20’].Temperature -5.5 }}”
    unit_of_measurement: “°C”
2 Likes

Well, that is a better alternative IMHO. I rather not have TWO sensors, rather just calibrate the original sensor.

I don’t know if this is possible with other sensors, like the ones I use (Xiaomi Zigbee imported from the Xiaomi gateway)?

Hi,
i tried same config

  • platform: mqtt
    name: “Temperature”
    state_topic: “tele/Tempout/SENSOR”
    value_template: ‘{{ value_json[“DS18B20”].Temperature -5.0 }}’
    unit_of_measurement: “°C”

it is working, but the problem is, that im getting like 10 digit number … how can i round it or make it like xx.xx number … thanks

@eskejp
Try something like ‘{{ (value_json[“DS18B20”].Temperature -5.0) | round(2) }}’

Strongly note the parantheses around (value… - 5.0). If you leave this out, it will round 5.0 first then subtract!

working like a charm! thanks a lot.

hi there
using zigbe2mqtt and added this code:

#temp and humidity sensor

  • platform: template
    sensors:
    xiaomi_temp_1_calibrated:
    value_template: >-
    {{ (float(states.sensor.0x286d970001010cd0_temperature.state) - 3.2 ) }}
    friendly_name: ‘corrigido’
    icon_template: mdi:thermometer

Altough i get the following error
Invalid config for [binary_sensor.template]: invalid template (TemplateSyntaxError: expected token ',', got 'x286d970001010cd0_temperature') for dictionary value @ data['sensors']['xiaomi_temp_1_calibrated']['value_template']. Got '{{ (float(states.sensor.0x286d970001010cd0_temperature.state) - 3.2 ) }}'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/binary_sensor.template/

can someone help ?
thanks

Your sensor name ist wrong. “0x286d970001010cd0_temperature” is not a sensor name, it starts with a number.