Skip to content

Ignore out-of-range Nanit sensor readings before publishing to MQTT - #39

Open
kalakris wants to merge 1 commit into
indiefan:mainfrom
kalakris:filter-out-of-range-sensor-readings
Open

Ignore out-of-range Nanit sensor readings before publishing to MQTT#39
kalakris wants to merge 1 commit into
indiefan:mainfrom
kalakris:filter-out-of-range-sensor-readings

Conversation

@kalakris

@kalakris kalakris commented Jun 19, 2026

Copy link
Copy Markdown

The Nanit feed can send a valueMilli of -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 processSensorData before 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, and gofmt clean. 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.

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
kalakris marked this pull request as ready for review June 19, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant