Filter LD2450 NaN to 0 when no target detected - #91
Conversation
Restores pre-2026.3 behavior so the LD2450 per-target numeric sensors report 0 instead of unknown when a target slot is empty. Upstream ESPHome PR esphome/esphome#13602 changed the ld2450 component to publish NaN for x, y, speed, angle, distance, and resolution when no target is present. Home Assistant renders NaN as unknown, which breaks numeric_state triggers, history graphs, and statistics built around these entities. Adds an isnan(x) ? 0.0 : x lambda filter to all 18 per-target numeric sensors (target_1/2/3 x x/y/speed/angle/distance/resolution). Closes #89
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds filter lambdas to LD2450 target numeric sensors ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 53 minutes and 1 second.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 326-397: The YAML inline lambda filters (e.g., the filters under
Target-1 X/ Y/ Speed/ Angle/ Distance/ Resolution and the corresponding filters
under target_2 and target_3) use a ternary with a colon which breaks YAML
parsing; replace each inline "- lambda: return isnan(x) ? 0.0 : x;" with a
block-scalar lambda (use "- lambda: |" followed by the lambda body on the next
indented line) for all 18 filter blocks so the colon inside the expression is
not interpreted as a mapping separator.
🪄 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: ff0419d6-5968-4f83-8e14-fa043d8f7443
📒 Files selected for processing (1)
Integrations/ESPHome/Core.yaml
YAML plain scalars cannot contain ': ' (colon followed by whitespace), so the inline form 'return isnan(x) ? 0.0 : x;' fails to parse on the second colon in the ternary. Switch all 18 per-target filters to the block-scalar form (- lambda: |- ... ) which preserves the colon and parses correctly.
Version: 26.3.2.2
What does this implement/fix?
Restores the pre-2026.3 behavior of the LD2450 per-target numeric sensors so they report `0` instead of `unknown` when a target slot is empty.
Background
ESPHome PR esphome/esphome#13602 changed the `ld2450` component to publish `NaN` for `x`, `y`, `speed`, `angle`, `distance`, and `resolution` when no target is present in a given slot. Home Assistant renders `NaN` as `unknown`, which breaks numeric_state triggers, history graphs, and statistics built around these entities.
The change was intentional upstream, intended to disambiguate "no target" from coordinate (0, 0). However, in Home Assistant the resulting `unknown` state breaks numeric_state triggers, history graphs, and statistics built on these entities. This PR restores the prior numeric behavior for Apollo users until upstream provides a non-breaking opt-in.
Closes #89.
Change
Adds a single-line lambda filter (`isnan(x) ? 0.0 : x`) to all 18 per-target numeric sensors (target_1/2/3 x x/y/speed/angle/distance/resolution).
The `direction` text_sensor (already shows "NA"), target/zone counts, and binary sensors are unaffected.
Types of changes
Checklist / Checklijst:
If user-visible functionality or configuration variables are added/modified: