Add temp offset with sensor template

Hi!
I am trying to add an offset to an outside temperature sensor I have that appears to be about 4 degrees celsius off the real temperature most of the time. The only problem is that I can’t get the value_template to work. I have added this to my configuration.yaml under sensors:
- platform: template sensors: utetemp_offset: value_template: '{{ states.sensor.tempute_temperature | float + 4 }}'
but I get sensor.utetemp_offset unknown friendly_name: utetemp_offset

I have also tried value_template: ‘{{ states.sensor.tempute_temperature | float + 4 }}’ which returns the value 4.0.

I have looked for some documentation that describes the math operands, but so far not found anything for a simple addition.

Could anybody help me out?

Thanks,
Tomas

Hi @tomoqv, Welcome to HA, try:
'{{ states.sensor.tempute_temperature.state | float + 4 }}'

3 Likes

Thanks a lot, worked like a charm!

Tomas

Can someone explain this syntax? According to the Jinja documentation, I would expect it to be equivalent to float(states.sensor.tempute_temperature.state) + 4, assuming each filter allows arithmetic expressions. However, I want to perform two-point calibration (with offset and gain), so I extended this method to {{ states.the_state | float + 3.2 | float * 2 }}, expecting a result equivalent to float(float(states.the_state) + 3.2) * 2) (the extra float was to get a valid expression, however, there is probably a better way). Anyways, the result seemed to behave as 3.2 was multiplied by 2 before being added to the state.

{{ (float(states_the_state) + 3.2) * 2 }} seemed to work fine, but I would prefer the filter method.