From 0ddcaa8fe746ce1add53fcf419216f4928dad1d2 Mon Sep 17 00:00:00 2001 From: Stefan Tibus <38475243+stibus@users.noreply.github.com> Date: Sun, 5 Jun 2022 00:54:10 +0200 Subject: [PATCH] Implement correct conversion of humidity for SHT4x The conversion of humidity from raw value is different for the SHT4x series. The fix implements the conversion as per datasheet. Also, the raw value is now cast to float before division. --- tasmota/tasmota_xsns_sensor/xsns_14_sht3x.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_14_sht3x.ino b/tasmota/tasmota_xsns_sensor/xsns_14_sht3x.ino index f2cbb7848..b073020e8 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_14_sht3x.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_14_sht3x.ino @@ -104,8 +104,12 @@ bool Sht3xRead(uint32_t type, float &t, float &h, uint8_t i2c_address) { if ((Sht3xComputeCrc(&data[0], 2) != data[2]) || (Sht3xComputeCrc(&data[3], 2) != data[5])) { return false; } - t = (float)((((data[0] << 8) | data[1]) * 175) / 65535.0) - 45; - h = (float)((((data[3] << 8) | data[4]) * 100) / 65535.0); + t = ((float)(((data[0] << 8) | data[1]) * 175) / 65535.0) - 45.0; + if (type == SHT3X_TYPE_SHT4X) { + h = ((float)(((data[3] << 8) | data[4]) * 125) / 65535.0) - 6.0; + } else { + h = ((float)(((data[3] << 8) | data[4]) * 100) / 65535.0); + } return (!isnan(t) && !isnan(h)); }