MQTT HA discovery declares `raw` as numeric although raw values may contain `N`
The Problem
Description
Home Assistant logs an error when the MQTT raw value contains N, which is a valid raw output from AI-on-the-edge-device when a digit could not be recognized.
Example raw MQTT payload:
N00587.315Topic:
watermeter/main/rawHome Assistant then reports an error similar to:
Value error while updating state of sensor.watermeter_raw,
topic: 'watermeter/main/raw'
with payload: b'N00587.315'Why this seems to be a Home Assistant MQTT discovery issue
The raw value is intentionally not guaranteed to be numeric.
The source code also describes ReturnRawValue as:
string ReturnRawValue; // rawValueStr; Raw value (with N & leading 0)and the project tests include values such as:
N23.456However, the Home Assistant MQTT discovery configuration for the raw entity currently appears to use the same unit, device class and state class as the processed value entity.
For a water meter this results in the raw entity being announced approximately as:
unit_of_measurement: m³
device_class: water
state_class: total_increasing
entity_category: diagnosticHome Assistant therefore expects a numeric value, while the valid raw MQTT payload may contain N.
Expected behavior
The processed value entity should remain the numeric meter value and use the appropriate:
unit_of_measurement
device_class
state_classThe raw entity should, in my opinion, be treated as a diagnostic/text value because it can legitimately contain N.
For example, the Home Assistant discovery configuration for raw could omit:
unit_of_measurement
device_class
state_classwhile retaining:
entity_category: diagnosticThis would preserve the raw value exactly as reported instead of trying to convert an uncertain reading such as N00587.315 into a valid numeric meter reading.
Additional note
I noticed that the changelog previously mentions:
Removed State Class and unit from
rawtopic
so this may be related to behaviour that was addressed earlier and later changed again.
Environment
- Device: AI-on-the-edge-device
- Meter type: Water
- MQTT: Enabled
- Home Assistant MQTT Discovery: Enabled
- AI-on-the-edge-device version:
[insert version] - Home Assistant version:
2026.9.3
Version
16.1.0
Logfile
Not neededExpected Behavior
No response
Screenshots
No response
Additional Context
No response
Source: jomjol/AI-on-the-edge-device