From 2c6d185bfc65dbc20eaf0a08bcb3ef302a196b02 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 20 Oct 2025 01:46:09 -0400 Subject: [PATCH] Add dynamic humidity calibration from temp offset With the physical limitations of the SuperSensor, we were able to compensate for the temperature differential due to internal heating from the ESP, but this compensation was not being taken into account by the humidity sensor. Add a compensation factor based on the offset to ensure humidity properly tracks the filtered temperature value. --- supersensor.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/supersensor.yaml b/supersensor.yaml index 3c7aa0f..2c76fc5 100644 --- a/supersensor.yaml +++ b/supersensor.yaml @@ -694,6 +694,20 @@ sensor: id: sht45_humidity accuracy_decimals: 1 filters: + - lambda: |- + // Grab measured and corrected temperatures + float t_meas = id(sht45_temperature).state - id(temperature_offset); + float t_corr = id(sht45_temperature).state; + float rh_meas = x; + + // Compute saturation vapor pressures (Magnus formula) + auto es = [](float T) { return 6.112 * exp((17.62 * T) / (243.12 + T)); }; + float rh_corr = rh_meas * es(t_meas) / es(t_corr); + + // Clamp to 0–100 % + if (rh_corr < 0) rh_corr = 0; + if (rh_corr > 100) rh_corr = 100; + return rh_corr + id(humidity_offset); - offset: !lambda return id(humidity_offset); - sliding_window_moving_average: window_size: 20