I find Compensation integration very useful to calibrate hardware sensors without hacking with ESPHome or Tasmota.
The problem I’ve found is with sensors that have a lower bound value, i.e. Power sensors.
Case scenario: A switch with power consumption sensor that want to be calibrated. If you use Compensation integration with n+1 data_points
and n degree
, due to the regression formula, you may end up with a sensor which gives you negative values when switch is off, which not only has no sense, but will give you negative energy consumption if you integrate it.
My suggestion is to add a new configuration variable to allow a lower bound of sensor values. If output value is lower that the bound, the bound itself is assigned (usually zero).
Of course, a new template sensor to get this behaviour may be easily created, but I think it’s general enough to add to the Compensate integration.