yorickpeterse / openflow

A ventilation system built around Itho Daalderop's DemandFlow system, written in Inko
Mozilla Public License 2.0
7 stars 0 forks source link

Implement automatic background calibration #3

Closed yorickpeterse closed 1 year ago

yorickpeterse commented 1 year ago

The CO2 sensor values are the raw values from the sensor, not taking into account drift over time. For example, in my case it seems my sensor isn't able to report values lower than 500 ppm (give or take a few ppm) when ventilating a room that hasn't been used in hours. Should this be due to drift it would also explain why some of the CO2 values reported are higher than I expect.

To handle this we should implement "Automatic Background Calibration". The way this works is simple: every Sunday at 04:00 we pick a pre-determined/configured room, turn off ventilation for all other rooms, then ventilate this room for 30 minutes. During this time we keep recording the lowest CO2 value. At the end we persist this value somewhere, and use the difference between it and the supposed CO2 concentration (420 ppm per https://www.co2.earth/) to derive the real CO2 value.

Example: the CO2 censor records 500 ppm as the lowest value. The difference to apply is then 420 - 500 = -80. So the next time we encounter a value of say 735 ppm, the actual value is 735 + -80 = 655 ppm.

The delta should be persisted somewhere so it can be reused between restarts. This should be in /var/lib/openflow/state.json. The README should be updated to mention the need for a container volume such that /var/lib/openflow isn't lost if the container is deleted and recreated. When calibrating, we should also record the difference in the metrics database, so it can be monitored over time.

The target level should be configurable to account for any other sensor inaccuracies and differences in outdoor air quality (e.g. not all areas may have the same concentration). The duration will just be a fixed 30 minutes, because that should be more than enough. The speed should use a dedicated speed so we can ventilate the room faster than usual, getting rid of any built-up CO2 in a short enough time period.

yorickpeterse commented 1 year ago

I'm going to leave this as-is for the time being. When ventilating our unused living room when we're not home, CO2 levels drop to <= 400 ppm, suggesting the sensor is still working fine. Reading through the various Itho documents out there, I suspect the sensor has its owl built-in calibration as well.