Skip to content

fix: add state_class for co2-density sensor#1631

Open
parkghost wants to merge 1 commit intoXiaoMi:mainfrom
parkghost:fix/co2-density-state-class
Open

fix: add state_class for co2-density sensor#1631
parkghost wants to merge 1 commit intoXiaoMi:mainfrom
parkghost:fix/co2-density-state-class

Conversation

@parkghost
Copy link
Contributor

@parkghost parkghost commented Feb 2, 2026

Summary

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)

Why

Currently, CO2 sensors (like those from CGDN1/Qingping Air Monitor Lite device) are missing:

  • state_class attribute
  • device_class attribute
  • proper unit of measurement

This 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.

image

Fixes #1630

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
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.

CO2 sensor (co2-density) missing state_class, no statistics recorded

1 participant