Skip to content

Add heartbeat floor to Reduce DB Reporting ambient sensors#105

Open
bharvey88 wants to merge 1 commit into
ApolloAutomation:betafrom
bharvey88:fix/reduce-db-heartbeat
Open

Add heartbeat floor to Reduce DB Reporting ambient sensors#105
bharvey88 wants to merge 1 commit into
ApolloAutomation:betafrom
bharvey88:fix/reduce-db-heartbeat

Conversation

@bharvey88

@bharvey88 bharvey88 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Version: 26.7.14.1

What does this implement/fix?

Companion to the MSR-2 fix for ApolloAutomation/MSR-2#70. MSR-1 uses a BME280 (not a DPS310), and its pressure channel is not reduce-gated — but its other reduce-gated ambient sensors share the same "hardcoded delta, no time floor" pattern that can make a sensor look frozen when Reduce DB Reporting is on.

Changes (Reduce DB Reporting behaviour only — the toggle-off path is unchanged):

  • Added a 1-hour heartbeat floor to the reduce-gated ambient sensors (ESP Temperature, LTR390 Light, LTR390 UV) so each always refreshes at least hourly. Existing deltas are preserved.
  • Radar distance/energy filters are intentionally left as-is (they return NAN when no target and deliberately suppress high-rate motion noise).
  • BME280 pressure/temperature/humidity are unchanged (pressure already reports every 60s, no toggle gating).

esphome config validates.

Types of changes

  • Bugfix (fixed change that fixes an issue)
  • New feature (thanks!)
  • Breaking change (repair/feature that breaks existing functionality)
  • Dependency Update - Does not publish
  • Other - Does not publish
  • Website of github readme file update - Does not publish
  • Github workflows - Does not publish

Checklist / Checklijst:

  • The code change has been tested and works locally
  • The code change has not yet been tested

If user-visible functionality or configuration variables are added/modified:

  • Added/updated documentation for the web page

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved reduced database reporting for internal temperature, light, and UV readings.
    • Sensor updates now report when values change significantly or at least once per hour, preventing stale readings while reducing unnecessary updates.
  • Chores

    • Updated the firmware version to 26.7.14.1.

The reduce-gated ambient sensors (ESP temp, LTR390 light/UV) used a
hardcoded delta with no time floor, so with Reduce DB Reporting on they
could freeze and never show a value on boot.

Give them a delta-OR-hourly-heartbeat floor and publish the first
post-boot reading. Radar filters, BME280 pressure, and the toggle-off
path are unchanged.

Related to ApolloAutomation/MSR-2#70

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@github-actions github-actions Bot added the bugfix Bug fix label Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The ESPHome firmware version is updated to 26.7.14.1. Temperature and LTR390 sensor filters now report significant changes or hourly heartbeats when reduced database reporting is enabled.

Changes

Sensor reporting updates

Layer / File(s) Summary
Heartbeat-based sensor reporting
Integrations/ESPHome/Core.yaml
The firmware version is bumped, and temperature, light, and UV filters track timestamps and emit updates on threshold changes or hourly heartbeats.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: new-feature

Suggested reviewers: trevorschirmer

Poem

A rabbit watched the sensors glow,
Reporting change, then time would flow.
Each hour brings a heartbeat bright,
While quiet values sleep through night.
Hop, hop—the firmware’s fresh and spry!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: adding an hourly heartbeat floor to Reduce DB Reporting for ambient sensors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 411-413: Update the reporting conditions for sys_esp_temperature
at Integrations/ESPHome/Core.yaml lines 411-413, LTR390 Light at lines 629-631,
and LTR390 UV at lines 654-656 to report only on the first publish or when the
current NAN state differs from the previous NAN state, while preserving the
hourly heartbeat and existing thresholds (5.0 for temperature, 20.0 for LTR390
sensors); apply the equivalent state-change logic at all three sites.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2d3aa73-a5f0-4b9b-9c3d-abd6a31082e1

📥 Commits

Reviewing files that changed from the base of the PR and between 0b69a22 and 284a38e.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

Comment on lines +411 to +413
if (isnan(last_reported_value) ||
abs(current_value - last_reported_value) >= 5.0 ||
(now - last_report_time) >= 3600000UL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle NAN values gracefully to avoid error-hiding and database spam.

The current logic has a significant flaw when the sensor fails and returns NAN:

  1. If the sensor drops offline and starts returning NAN while operating normally, abs(NAN - last) >= threshold evaluates to false. The error is suppressed until the hourly heartbeat fires, hiding the sensor failure from the system for up to an hour.
  2. Once the heartbeat fires, last_reported_value becomes NAN. On subsequent polls, isnan(last_reported_value) stays true, causing EVERY NAN reading to bypass the checks and report immediately. This spams the database with errors, defeating the "Reduce DB Reporting" intent.

To fix this, check explicitly if this is the first publish or if the NAN state has changed (i.e., newly failed or newly recovered) instead of checking only if the last value was NAN.

  • Integrations/ESPHome/Core.yaml#L411-L413: Apply the robust state-change check for ESP Temperature.
  • Integrations/ESPHome/Core.yaml#L629-L631: Apply the robust state-change check for LTR390 Light.
  • Integrations/ESPHome/Core.yaml#L654-L656: Apply the robust state-change check for LTR390 UV.
🛠️ Proposed fix for `sys_esp_temperature` (lines 411-413)
-              if (isnan(last_reported_value) ||
-                  abs(current_value - last_reported_value) >= 5.0 ||
-                  (now - last_report_time) >= 3600000UL) {
+              bool is_first_publish = last_report_time == 0;
+              bool state_changed = isnan(current_value) != isnan(last_reported_value);
+              if (is_first_publish || state_changed ||
+                  abs(current_value - last_reported_value) >= 5.0 ||
+                  (now - last_report_time) >= 3600000UL) {

(Apply the equivalent change with >= 20.0 for the LTR390 sensors at lines 629-631 and 654-656)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isnan(last_reported_value) ||
abs(current_value - last_reported_value) >= 5.0 ||
(now - last_report_time) >= 3600000UL) {
bool is_first_publish = last_report_time == 0;
bool state_changed = isnan(current_value) != isnan(last_reported_value);
if (is_first_publish || state_changed ||
abs(current_value - last_reported_value) >= 5.0 ||
(now - last_report_time) >= 3600000UL) {
📍 Affects 1 file
  • Integrations/ESPHome/Core.yaml#L411-L413 (this comment)
  • Integrations/ESPHome/Core.yaml#L629-L631
  • Integrations/ESPHome/Core.yaml#L654-L656
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Integrations/ESPHome/Core.yaml` around lines 411 - 413, Update the reporting
conditions for sys_esp_temperature at Integrations/ESPHome/Core.yaml lines
411-413, LTR390 Light at lines 629-631, and LTR390 UV at lines 654-656 to report
only on the first publish or when the current NAN state differs from the
previous NAN state, while preserving the hourly heartbeat and existing
thresholds (5.0 for temperature, 20.0 for LTR390 sensors); apply the equivalent
state-change logic at all three sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant