Ignore out-of-range Nanit sensor readings before publishing to MQTT - #39
Open
kalakris wants to merge 1 commit into
Open
Ignore out-of-range Nanit sensor readings before publishing to MQTT#39kalakris wants to merge 1 commit into
kalakris wants to merge 1 commit into
Conversation
The Nanit feed occasionally reports ValueMilli=-1000000 (-1000 °C) as an invalid-reading sentinel. processSensorData stored it without any bounds check, so the bridge published -1000 to babies/<id>/temperature. In Home Assistant this shows as -1768 °F, corrupting history and — for setups where a thermostat reads the sensor — risking a spurious HVAC call. Validate at ingestion: accept temperature within -20..60 °C and humidity within 0..100 %, otherwise log a warning and drop the reading so the prior value is retained. Range-based so it is robust to whatever firmware condition produces the sentinel. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
kalakris
marked this pull request as ready for review
June 19, 2026 22:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Nanit feed can send a
valueMilliof-1000000(representing −1000 °C) as an invalid-reading sentinel. Without validation the bridge publishes this straight to MQTT, and Home Assistant shows it as −1768 °F — corrupting sensor history and, if anything reads that sensor for thermostat control, potentially triggering a spurious HVAC call.This adds a range check in
processSensorDatabefore setting temperature or humidity: temperature must be −20..60 °C and humidity 0..100 %, otherwise the reading is logged as a warning and dropped, keeping the last good published value in place. The check is range-based rather than sentinel-specific, so it handles whatever firmware condition produces the bad value.Verified
go build,go vet, andgofmtclean. I've only seen the bad value once (and only on the temperature channel, not humidity), so the drop path wasn't reproduced on demand — the check is range-based rather than tied to the specific sentinel.