pihome-shc / pihome

PiHome - Smart Heating, Ventilation and Air Conditioning (HVAC)
http://www.pihome.eu
Other
52 stars 25 forks source link

DS18b20 filtering and EWMA #454

Closed JSa1987 closed 3 years ago

JSa1987 commented 3 years ago

Hello,

I have implemented filtering to remove random spikes from the DS18b20 readings and the option to apply an Exponential Weighted Moving Average for data smoothing.

The data from my DS18b20 sensors connected directly to the Raspberry Pi used to look like this with random spikes: Graph with spikes

Now it looks like this: Graph without spikes

The gpio_ds18b20.py script now runs in the background at all times and does an acquisition of the DS18b20 at regular time intervals defined by the _updaterate parameters (by default set at 60sec). I have created the check_ds18b20.php script that checks if gpio_ds18b20.py is running and if this is not the case it restarts it. The cronjob.txt file has been edit to run the check_ds18b20.php script every minute. This is the same logic already used for gateway.py and check_gw.php.

The _dTmax parameter in gpio_ds18b20.py defines that maximum expected difference in temperature between two consecutive acquisitions from the same sensor (this is by default set to 3 degC). If the difference between the previous reading and the current reading of the sensor is more than _dTmax the previous reading is returned and the current reading is skipped. The _skipmax parameter defines how many consecutive points from a sensor can be skipped (the default value is 3), once this value has been reached the current reading from the sensor is used regardless of the difference from the previous reading.

The gpio_ds18b20.py script now has the option for applying an Exponential Weighted Moving Average for data smoothing. See here for an explanation of EWMA and here for an application to DS18b20 readings. The EMWA is controlled by the alpha parameter (that needs to be between 0 and 1). The higher the value of alpha the more reactive the output will be, the lower the value of alpha the more smooth the output will be. By default alpha = 1, that means that the EWMA is disabled.

pihome-shc commented 3 years ago

@JSa1987 thank you for hard work.