Calibration of aqara temperature sensors

Dear all I,
I use Hassio and several aquara sensors. I works quiet well, but their temperature differs a bit from each other at the same spot. To fix this I wanted to add an offset via templating them, but somehow I did not get it…

I have created a file called sensors.yaml in this I have added:

- platform: template
      value_template: '{{ (sensor.room_a_t_h | round(1)) + 5}}' 
      friendly_name: 'Room A Temp'

I tried to integrate this by adding template: !include sensors.yaml into the configuration.yaml

But it did not work. Two questions:

  1. What du I have to change to make it work?
  2. Will this code change the volume of the entity or do I have to choose another entity to show the real temperature?


- platform: template
      value_template: '{{ ( states('sensor.room_a_t_h')|float + 5 )|round(1) }}' 
      friendly_name: 'Room A Temp'
  1. No it will not change the existing sensor, you will have to use the new template sensor.

There is no component called “template:” the config needs to be under “sensor:” there’s also problems with your template I suggest to take a look here:

Try like this:

  - platform: template
        value_template: "{{ (states('sensor.room_a_t_h') | int + 5) | round(1)}}"
        friendly_name: 'Room A Temp'

This code will generate a new sensor called sensor.t_offset_room_a, which will have your adjusted temperature. The temperature in the original entity will not be affected.

Does your sensor really have a difference of 5 degrees to the other sensor, seems pretty high?

I missed the bit about the include. Good catch.

There’s a problem with this though:

...5 | round(1)}}

It only rounds the digit ‘5’.

1 Like

I tested this in the template editor and it worked as expected.

It still only rounds the digit 5. See this note on order of operations:

Also his sensor should be cast as a float not an int. The fact that he is rounding suggests a fractional part.

Ooooooooh !
A slapped wrist there for @Burningstone, doubly so @tom_l , as I think he was in a thread recently where the exact same thing was pointed out.
Mind you, I sometimes have to put templates through the editor half a dozen times (with lots of head scratching between) before I catch the simplest mistakes :man_shrugging:

No, I have a temperature sensor with temperature of 22.5 degrees and with my template the resulting value is 27 degrees.

Pipe | takes priority over everything except brackets

I have a temperature sensor with temperature of 22.5 degrees and with my template the resulting value is 27 degrees.

Which is round(0) not round(1).

You have also cast a floating point number as an integer which truncates precision.

1 Like

Ah I see now, stupid me. Not enough sleep, too high red bull intake, I assume. :joy:

1 Like

Maybe HA users should have a PPPMA mantra ?
Parenthesis, Pipe, Power, Multiplication & Addition ??? :rofl:

1 Like

Wao, you are quick! Just getting lunch and coming back to see the solution!

Thank you, it works pretty well. I choose 5°C to see something :wink: it is not the real difference.

I have only to change the quotation marks and add the unit:

    - platform: template
          value_template: "{{ ( states('sensor.room_a_t_h')|float + 5 )|round(1) }}" 
          friendly_name: 'T Room A'
          unit_of_measurement: '°C'

Thx a lot!

1 Like

If it works, can you please mark the post with the solution, so that others can quickly find the solution in the future.

Just one more question, how do source out the calibration to another file?

I don’t understand, what do you mean with “source out the calibration”?

I mean I don’t want to have this calibration in the configuration.yaml instead in sensors.yaml but it did not work like I wrote it in my post in the beginning.

So I have no clue how to include the sensors.yaml into configuration.yaml, because template: !include sensors.yaml did not work properly.

You have marked your own post as the solution.
It is customary to mark the post who gave you answer as the solution (either Tom or Burning) to follow your example EVERY thread would be solved by the OP.

You may also find that your ‘offset’ is not linear and an mx+c suits better or even a polynomial, these can also be done. But the last thread I participated in on this subject. The error was merely perception and just the way the sensor updated - correction was not needed.

If you want the sensor in your sensor.yaml file then just put the include (as burningstone suggested) in there.

1 Like

Now I got it :slight_smile:

When I enter the code directly into configuration.yaml there must be a sensor: followed by the code, when indirectly, the sensor has still to be there, but followed by include! sensors.yaml and the code is in this data.


1 Like

Take a look here for more information about this: