Tasmota: ADD:Humidity compensation for SGP30

Created on 3 Apr 2019  路  10Comments  路  Source: arendst/Tasmota

What should I do?

The SGP30 features an on-chip humidity compensation for the air quality signals (CO2eq and TVOC) and sensor raw signals (H2-signal and Ethanol_signal). To use the on-chip humidity compensation an absolute humidity value from an external humidity sensor like the SHTxx is required.

enhancement fixed

Most helpful comment

Tasmota has a hidden feature which stores temp and hum of a connected device in a global struct. The info in this struct can be used by any sensor needing this information for whatever reason.

So all that is needed is adding some code to the SGP30 sensor driver to get this global data. Sounds simple ;-)

All 10 comments

Hi,

According to the SGP30 datasheet that compensation is possible.

Tasmota is using the adafruit library 1.0.2 that does not have the commands for applying that compensation, but it is supported on the new adafruit library 1.0.3 from https://github.com/adafruit/Adafruit_SGP30

So, it is needed to update the library in Tasmota codebase and modify the SGP driver to allow using humidity as input. I think a new sensor command is needed to choose to apply or not this compensation.

Adding the label enhancement to this issue.

Thanks for sharing your ideas :+1:

Tasmota has a hidden feature which stores temp and hum of a connected device in a global struct. The info in this struct can be used by any sensor needing this information for whatever reason.

So all that is needed is adding some code to the SGP30 sensor driver to get this global data. Sounds simple ;-)

unfortunately it is not that easy! the SGP30 needs ABSOLUTE humidity with is very complicated to calculate and needs relative humidity, temperature and air pressure.

as it turns out that absolute humidity (as in contrast to relative humidity) is the factor that determines if viruses can survive in an environment (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2893471/) it would be very interesting to have it. since the bme280 provides all the necessary input, absolute humidity should be implemented there. it then can also be used for compensation of the sgp30.

the formula however is a monster and uses some flash and time consuming functions =>

abs_hum=0.622 * In_RelHum/100 * (1.01325 * 10^(5.426651 - 2005.1 / (InTemp + 273.15) + 0.00013869 * ((InTemp + 273.15) * (InTemp + 273.15) - 293700) / (InTemp + 273.15) * (10^(0.000000000011965 * ((InTemp + 273.15) * (InTemp + 273.15) - 293700) * ((InTemp + 273.15) * (InTemp + 273.15) - 293700)) - 1) - 0.0044 * 10^((-0.0057148 * (374.11 - InTemp)^1.25))) + (((InTemp + 273.15) / 647.3) - 0.422) * (0.577 - ((InTemp + 273.15) / 647.3)) * EXP(0.000000000011965 * ((InTemp + 273.15) * (InTemp + 273.15) - 293700) * ((InTemp + 273.15) * (InTemp + 273.15) - 293700)) * 0.00980665) / (In_Pressure/1000 - In_RelHum/100 * (1.01325 * 10^(5.426651 - 2005.1 / (InTemp + 273.15) + 0.00013869 * ((InTemp + 273.15) * (InTemp + 273.15) - 293700) / (InTemp + 273.15) * (10^(0.000000000011965 * ((InTemp + 273.15) * (InTemp + 273.15) - 293700) * ((InTemp + 273.15) * (InTemp + 273.15) - 293700)) - 1) - 0.0044 * 10^((-0.0057148 * (374.11 - InTemp)^1.25))) + (((InTemp + 273.15) / 647.3) - 0.422) * (0.577 - ((InTemp + 273.15) / 647.3)) * EXP(0.000000000011965 * ((InTemp + 273.15) * (InTemp + 273.15) - 293700) * ((InTemp + 273.15) * (InTemp + 273.15) - 293700)) * 0.00980665)) * In_Pressure/1000 * 100000000 / ((InTemp + 273.15) * 287.1)

i am short of time but i will definitely implement this if nobody else will.

digging a bit further gives a simplified version ignoring pressure (don't know the error induced)

in the bme280 GitHub =>https://github.com/finitespace/BME280/blob/master/src/EnvironmentCalculations.cpp

since most calculations found on the web don't use pressure i did take the much simpler calculation from bme280 and implemented this to the sgp30 driver. i also did put the absolute humidity value to the web gui and json output of the sgp30

if you want to try take it from my fork =>https://github.com/gemu2015/Sonoff-Tasmota
(take over the sgp30 lib and the sgp30 driver)

if it is tested for i while i can make a pr to tasmota

Hi @gemu2015, impressive formula, it got me hooked :)
Comparing what I saw here (https://planetcalc.com/2161 and https://planetcalc.com/2167) it seems overly complicated though - even with using pressure.
The pressure term is just f(p) = 1,0016 + 0,00000315 * p - 0,074 / p and within valid values of the bme280 this varies absolute humidity by less than 0,1% so you can really ignore it for normal atmospheric pressures.

Btw, I looked at your github repo and have a suggestion: it would be much easier to pick up features if you would implement them in branches and then merge to your master

@TONGXD Look in GEMUs fork. He worked on it :-)
GEMU Fork Tasmota

get the humidity value of si7021
鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌
https://github.com/sparkfun/SparkFun_SGP30_Arduino_Library

Thanks

Reopening this issue until the enhancement is added to Tasmota. Waiting for the PR from @gemu2015

Was this page helpful?
0 / 5 - 0 ratings

Related issues

he-so picture he-so  路  3Comments

ximonline picture ximonline  路  3Comments

abzman picture abzman  路  3Comments

kckepz picture kckepz  路  3Comments

wirelesssolution picture wirelesssolution  路  3Comments