Hi all,
Over the past few days I ran into a strange issue with one of my CO₂ sensors that is forwarded from Homey to Home Assistant via the MQTT Hub app. The temperature and humidity sensors from the same device worked fine, but the CO₂ value never showed up in Home Assistant.
In the Home Assistant logs I noticed error messages related to the MQTT discovery payload for this sensor. The message indicated that the device_class was invalid. This was surprising, because another CO₂ sensor using the same device_class was still working correctly.
After some digging and Googling, I eventually published a corrected discovery payload manually using MQTT Explorer. As soon as I did that, the CO₂ entity was created immediately and everything started working again.
It turns out the root cause lies in how Home Assistant handles MQTT Discovery:
-
Existing entities continue to work, even if the discovery payload later becomes invalid.
-
New entities are rejected if the discovery payload contains errors.
The temperature and humidity entities for this CO₂ device already existed, so they kept working. The CO₂ entity did not exist (I probably deleted it myself accidentally during a recent cleanup), and because the discovery payload contained errors, Home Assistant refused to recreate it.
My first conclusion is that the MQTT Hub app on Homey is sending discovery payloads that do not fully comply with Home Assistant’s MQTT Discovery specifications. After manually publishing a correct discovery payload, the CO₂ sensor works normally again.
Below is a summary of the issues I believe I’m seeing based on the error messages in the HA log.
If this looks familiar, perhaps these points can be addressed in a future release of MQTT Hub?
1. Device class – CO₂
What MQTT Hub currently sends: device_class: “co2”
What Home Assistant expects: device_class: “carbon_dioxide”
Effect in Home Assistant: The CO₂ entity is not created. Home Assistant rejects the discovery payload.
Log message: Error about expected SensorDeviceClass.
2. Unit of measurement – temperature
What MQTT Hub currently sends: unit_of_measurement: “C”
What Home Assistant expects: unit_of_measurement: “°C”
Effect in Home Assistant: Discovery is rejected. Existing entities continue to work, but new ones are not created.
Log message: ValueError for temperature sensor.
3. Unit of measurement – particulate matter (PM) sensors
What MQTT Hub currently sends: unit_of_measurement: “ug/m”
What Home Assistant expects: unit_of_measurement: “µg/m³”
Effect in Home Assistant: Discovery is rejected. New entities are not created.
Log message: ValueError for PM sensor.
4. Numeric sensors sending null
What MQTT Hub currently sends: Payload “null” for sensors that must have a numeric value (e.g., voltage).
What Home Assistant expects: A number, or “unavailable” if the value is temporarily not available.
Effect in Home Assistant: Home Assistant logs errors and ignores the update.
Log message: “non numeric value: ‘null’”.