fix: add state_class for co2-density sensor#1631
Open
parkghost wants to merge 1 commit intoXiaoMi:mainfrom
Open
fix: add state_class for co2-density sensor#1631parkghost wants to merge 1 commit intoXiaoMi:mainfrom
parkghost wants to merge 1 commit intoXiaoMi:mainfrom
Conversation
Add co2-density property mapping to SPEC_PROP_TRANS_MAP to enable statistics recording for CO2 sensors. Changes: - Import CONCENTRATION_PARTS_PER_MILLION from homeassistant.const - Add co2-density mapping with: - device_class: SensorDeviceClass.CO2 - state_class: SensorStateClass.MEASUREMENT - unit_of_measurement: CONCENTRATION_PARTS_PER_MILLION (ppm) This ensures CO2 sensors (like those from CGDN1 device) have proper device classification and Home Assistant can record long-term statistics. Fixes XiaoMi#1630
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.
Summary
Add
co2-densityproperty mapping toSPEC_PROP_TRANS_MAPto enable statistics recording for CO2 sensors.Changes
CONCENTRATION_PARTS_PER_MILLIONfromhomeassistant.constco2-densitymapping with:device_class:SensorDeviceClass.CO2state_class:SensorStateClass.MEASUREMENTunit_of_measurement:CONCENTRATION_PARTS_PER_MILLION(ppm)Why
Currently, CO2 sensors (like those from CGDN1/Qingping Air Monitor Lite device) are missing:
state_classattributedevice_classattributeThis prevents Home Assistant from recording long-term statistics for CO2 sensors, while other similar density sensors (PM2.5, PM10, TVOC, VOC) work correctly.
Testing
After applying this fix, CO2 sensor entity shows:
{ "state_class": "measurement", "device_class": "carbon_dioxide", "unit_of_measurement": "ppm" }Home Assistant statistics recording is now enabled for CO2 sensors.
Fixes #1630