From 62fed4c1eb1079f29e72e1a80b749a8dafe43f8e Mon Sep 17 00:00:00 2001 From: arno1801 <120399978+arno1801@users.noreply.github.com> Date: Sun, 6 Aug 2023 19:59:17 -0400 Subject: [PATCH] Improved compensation sgp30 (#5208) --- esphome/components/sgp30/sgp30.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/esphome/components/sgp30/sgp30.cpp b/esphome/components/sgp30/sgp30.cpp index a6572620c4..25a3c1ab8f 100644 --- a/esphome/components/sgp30/sgp30.cpp +++ b/esphome/components/sgp30/sgp30.cpp @@ -181,9 +181,18 @@ void SGP30Component::send_env_data_() { ESP_LOGD(TAG, "External compensation data received: Temperature %0.2f°C", temperature); } - float absolute_humidity = - 216.7f * (((humidity / 100) * 6.112f * std::exp((17.62f * temperature) / (243.12f + temperature))) / - (273.15f + temperature)); + float absolute_humidity; + if (temperature < 0) { + absolute_humidity = + 216.67f * + ((humidity * 0.061121f * std::exp((23.036f - temperature / 333.7f) * (temperature / (279.82f + temperature)))) / + (273.15f + temperature)); + } else { + absolute_humidity = + 216.67f * + ((humidity * 0.061121f * std::exp((18.678f - temperature / 234.5f) * (temperature / (257.14f + temperature)))) / + (273.15f + temperature)); + } uint8_t humidity_full = uint8_t(std::floor(absolute_humidity)); uint8_t humidity_dec = uint8_t(std::floor((absolute_humidity - std::floor(absolute_humidity)) * 256)); ESP_LOGD(TAG, "Calculated Absolute humidity: %0.3f g/m³ (0x%04X)", absolute_humidity,