Calibrate Sensor

Yes, you are absolutely right!
For every new feature the code of HA has to be changed.
But that does not mean that it is impossible.

1 Like

It’s currently impossible without the mechanisms in place on all sensors and something like that would need to be approved by the main dev team. So right now, it’s quite impossible. Remember, this WTH isn’t closed… there’s a reason for that. It would be closed if it was implemented on the sensor :wink:

You’re right. They only have to add 1 property, a ‘calibration’ property, with default value zero.
After retrieving the value from thee sensor, they only have to add 1 line… Add calibration value.
It’s not impossible. It’s easy.

This is a very good idea! So the first thing is to add the calibration attribute.

Uh, not at all. Calibration and compensation requires a linear/non-linear equation or linear/non-linaer interpolation method. All differ and all result in different values and those values need to be configured by the user or a calibration method performed by the user. It’s not just a simple property.

To put it into perspective, the compensation integration only handles linear and non linear polynomial compensation. Adding linear and non-linear interpolation to it would probably double or triple size of that integration. Applying those methods across all sensors would require a whole backend model where the user would only see a simple result in the end and possibly 1 or 2 new attributes.

Don’t need it anymore. I’ll do it in deconz.
Why make it complicated…

That’s a flat offset, decons can also do everything I listed :wink:

FYI a simple offset is only a partial linear 2 dimensional polynomial compensation. It does not account for slope. Most compensations are linear in nature but also account for a slope. i.e. y = a*x + b (2d polynomial), where an offset is just y = x + b. Take a look at the esphome documentation on all the calibration methods.

Which might I add is part of the original WTH

So, ESPHOME has a calibration mechanism built-in.
As sensors and lights are most used devices in HA, I think it’s a good reason to add this ability in HA too.

:man_facepalming:I never said it was…

Hi, I tried the Compensation function, but do not understand the result.


compensation:
  hoszivattyu_set_pwr:
    source: sensor.hoszivattyu_set_pwr
    unit_of_measurement: '%'
    degree: 1
    data_points:
      - [0, 0]
      - [10, 17]
      - [18, 18]
      - [20, 19]
      - [21, 21]
      - [22, 22]
      - [23, 23]
      - [24, 24]
      - [25, 26]
      - [26, 27]
      - [27, 30]
      - [28, 32]
      - [29, 33]
      - [30, 35]
      - [31, 37]
      - [32, 38]
      - [33, 39]
      - [34, 40]
      - [35, 41]
      - [36, 43]
      - [37, 44]
      - [38, 45]
      - [39, 46]
      - [40, 47]
      - [41, 48]
      - [43, 49]
      - [44, 50]
      - [45, 51]
      - [46, 52]
      - [47, 53]
      - [49, 54]
      - [50, 55]
      - [51, 56]
      - [52, 57]
      - [54, 58]
      - [55, 59]
      - [58, 60]
      - [59, 61]
      - [60, 62]
      - [61, 63]
      - [62, 64]
      - [64, 65]
      - [65, 66]
      - [67, 67]
      - [68, 68]
      - [70, 69]
      - [71, 70]
      - [75, 72]
      - [76, 73]
      - [77, 74]
      - [79, 75]
      - [81, 76]
      - [82, 77]
      - [84, 78]
      - [85, 79]
      - [87, 80]
      - [89, 81]
      - [90, 82]
      - [92, 83]
      - [93, 84]
      - [95, 85]
      - [96, 86]
      - [98, 87]
      - [99, 88]
      - [100, 91]

I except if the value of the original sensor is the left, the right value will be the value of the compensation sensor.

But not this is the situation. sensor is 43 and the comp.sensor is 45.39. Why? (it should be 49).

Thank you

I think this code https://github.com/home-assistant/core/blob/23fad6076968610a2c1559dac27990347b2826d3/homeassistant/components/sensor/init.py in function “state” should be the right place to implement it. There I could check the “calibrate” attribute and add it to the sensor value.

Because this is the fit you are requesting from the compensation integration.

Remember, this integration does not interpolate, it fits a 1d polynomial to your dataset. Increase the degree of your equation to get a better fit.

This is a 10th degree fit

FYI, I could add interpolation to the integration. Here’s a comparison:

2 Likes

For the last time, please stop. You’re not adding anything valuable to this conversation. A simple offset will not work, just look at the post above. That place in the code does not cover the setup of the compensation, UI for the setup of the compensation, and the storage of the compensation interpolation or polynomial. All things that need to be handled and approved by the core team because this would be a core change. This is why it was made into an integration. So for the love of god, let it be. At this point it’s out of everyones hands and in the core teams hands. Thanks.

Thank you for the explanation

Hi everyone, even if this is an old post, seems a good starting point.

I’m looking for a way to calibrate a sensor value (Arduino adc measuring soil moisture) based on another sensor (battery), as given how capacitive soil sensors work the readings change based on battery level. Has anyone an idea?
Thanks!