From 36f5a2863e5952b99a3fae2ce96a7e71d033fb14 Mon Sep 17 00:00:00 2001 From: Brandon Harvey <8107750+bharvey88@users.noreply.github.com> Date: Tue, 14 Jul 2026 11:11:28 -0500 Subject: [PATCH] Fix Reduce DB Reporting freezing DPS310 pressure and ambient sensors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When Reduce DB Reporting was on, the DPS310 pressure sensor only reported on a >= 5.0 hPa change. Barometric pressure normally drifts 1-3 hPa a day, so the reading could freeze for hours and look like a dead sensor. Give the reduce-gated ambient sensors (pressure, ESP temp, LTR390 light/UV) a delta-OR-hourly-heartbeat floor, and publish the first post-boot reading so a value always shows on boot. Lower the pressure delta to 0.5 hPa and move the DPS310 poll to 60s. Radar filters and the toggle-off path are unchanged. Fixes #70 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- Integrations/ESPHome/Core.yaml | 85 +++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 64bcb20..0fbf2a0 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,6 +1,6 @@ substitutions: name: apollo-msr-2 - version: "26.7.12.1" + version: "26.7.14.1" device_description: ${name} made by Apollo Automation - version ${version}. # Default update channel on first boot (no stored user choice yet, i.e. a # fresh flash). The beta-channel builds override this to "Beta" (see @@ -426,22 +426,24 @@ sensor: id: sys_esp_temperature filters: - lambda: |- - static float last_reported_value = -6.0; + static float last_reported_value = NAN; + static uint32_t last_report_time = 0; float current_value = x; - // Check if the reduce_db_reporting switch is on + // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen if (id(reduce_db_reporting).state) { - // Apply delta filter: only report if the value has changed by 5 or more - if (abs(current_value - last_reported_value) >= 5.0) { - last_reported_value = current_value; // Update the last reported value + uint32_t now = millis(); + if (isnan(last_reported_value) || + abs(current_value - last_reported_value) >= 5.0 || + (now - last_report_time) >= 3600000UL) { + last_reported_value = current_value; + last_report_time = now; return current_value; - } else { - // Return the last reported value without updating if change is less than 5 - return {}; // Discard the update } + return {}; // Within delta and under the hourly heartbeat -> discard } else { - // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; + last_report_time = millis(); return current_value; } @@ -644,22 +646,24 @@ sensor: id: ltr390light filters: - lambda: |- - static float last_reported_value = -21.0; + static float last_reported_value = NAN; + static uint32_t last_report_time = 0; float current_value = x; - // Check if the reduce_db_reporting switch is on + // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen if (id(reduce_db_reporting).state) { - // Apply delta filter: only report if the value has changed by 5 or more - if (abs(current_value - last_reported_value) >= 5.0) { - last_reported_value = current_value; // Update the last reported value + uint32_t now = millis(); + if (isnan(last_reported_value) || + abs(current_value - last_reported_value) >= 5.0 || + (now - last_report_time) >= 3600000UL) { + last_reported_value = current_value; + last_report_time = now; return current_value; - } else { - // Return the last reported value without updating if change is less than 20 - return {}; // Discard the update } + return {}; // Within delta and under the hourly heartbeat -> discard } else { - // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; + last_report_time = millis(); return current_value; } uv_index: @@ -667,22 +671,24 @@ sensor: id: ltr390uvindex filters: - lambda: |- - static float last_reported_value = -21.0; + static float last_reported_value = NAN; + static uint32_t last_report_time = 0; float current_value = x; - // Check if the reduce_db_reporting switch is on + // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen if (id(reduce_db_reporting).state) { - // Apply delta filter: only report if the value has changed by 1 or more - if (abs(current_value - last_reported_value) >= 1.0) { - last_reported_value = current_value; // Update the last reported value + uint32_t now = millis(); + if (isnan(last_reported_value) || + abs(current_value - last_reported_value) >= 1.0 || + (now - last_report_time) >= 3600000UL) { + last_reported_value = current_value; + last_report_time = now; return current_value; - } else { - // Return the last reported value without updating if change is less than 20 - return {}; // Discard the update } + return {}; // Within delta and under the hourly heartbeat -> discard } else { - // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; + last_report_time = millis(); return current_value; } @@ -693,26 +699,29 @@ sensor: id: dps310pressure filters: - lambda: |- - static float last_reported_value = -6.0; + static float last_reported_value = NAN; + static uint32_t last_report_time = 0; float current_value = x; float offset = id(dps310_pressure_offset).state; if (!isnan(offset)) { current_value += offset; } - // Check if the reduce_db_reporting switch is on + // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen. + // Barometric pressure normally drifts only 1-3 hPa a day, so the old 5 hPa delta could freeze the reading for hours. if (id(reduce_db_reporting).state) { - // Apply delta filter: only report if the value has changed by 5 or more - if (abs(current_value - last_reported_value) >= 5.0) { - last_reported_value = current_value; // Update the last reported value + uint32_t now = millis(); + if (isnan(last_reported_value) || + abs(current_value - last_reported_value) >= 0.5 || + (now - last_report_time) >= 3600000UL) { + last_reported_value = current_value; + last_report_time = now; return current_value; - } else { - // Return the last reported value without updating if change is less than 5 - return {}; // Discard the update } + return {}; // Within delta and under the hourly heartbeat -> discard } else { - // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; + last_report_time = millis(); return current_value; } temperature: @@ -720,7 +729,7 @@ sensor: id: dps310temperature filters: - lambda: return x - id(dps310_temperature_offset).state; - update_interval: 30s + update_interval: 60s i2c_id: bus_a