Skip to content

Commit 7584ebd

Browse files
authored
Merge pull request #43 from mash2k3/dev
Dev
2 parents 589ca20 + 11969e6 commit 7584ebd

File tree

10 files changed

+882
-55
lines changed

10 files changed

+882
-55
lines changed

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This custom component integrates the Qingping Air Quality Monitors [CGS1/CGS2/CG
1616

1717
- Automatic discovery of Qingping CGS1/CGS2/CGDN1 devices
1818
- Real-time updates of air quality data
19-
- Configurable temperature and humidity offsets
19+
- Configurable offsets
20+
- Configuration entites
2021
- Adjustable update interval
2122
- Automatic unit conversion for temperature
2223
- Device status monitoring
@@ -39,15 +40,15 @@ This custom component integrates the Qingping Air Quality Monitors [CGS1/CGS2/CG
3940
5. Search for "Qingping Pro AQM" and follow the configuration steps
4041

4142
## Configuration
42-
<img src="https://github.com/user-attachments/assets/3cc92957-3460-4ba4-b78f-17afab455f40" alt="Device Discovery" width="250" align="left">
43+
<img src="https://github.com/user-attachments/assets/a123e039-7ada-4062-a5aa-f2c7b2d20085" alt="Device Discovery" width="250" align="left">
4344
The integration supports automatic discovery of Qingping CGS1/CGS2/CGDN1 devices.
4445
<br />If your device is not discovered automatically, you can add it manually by providing the MAC address.
4546
<br />⚠️ Do not include : in your MAC address. example: 532D38701E1F
4647
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
4748

4849

4950
## How it Works
50-
<img src="https://github.com/user-attachments/assets/46567747-a8cb-443e-be23-78a87e741a42" alt="Device Discovery" width="275" align="right">
51+
<img src="https://github.com/user-attachments/assets/55a42477-59a7-48b6-b70b-f743c5e2a69a" alt="Device Discovery" width="275" align="right">
5152

5253
1. **Device Discovery**: The integration uses MQTT to discover Qingping CGS1/CGS2/CGDN1 devices on your network. It listens for messages on the MQTT topic `qingping/#` to identify available devices.
5354

@@ -62,6 +63,19 @@ The integration supports automatic discovery of Qingping CGS1/CGS2/CGDN1 devices
6263
- TVOC (ppb, ppm and mg/m³) `Only on CGS1`
6364
- eTVOC (ppb, VOC index and mg/m³) `Only on CGS2`
6465
- Noise level `Only on CGS2`
66+
- Temp & Humidity Offsets
67+
- PM2.5 Offsets
68+
- PM10 Offsets
69+
- TVOC Offsets `Only on CGS1`
70+
- eTVOC Offsets `Only on CGS2`
71+
- CO2 Offsets
72+
- Auto Sliding `Only on CGDN1`
73+
- Auto CO2 Calibration `Only on CGDN1`
74+
- Manual Calibration `Only on CGDN1`
75+
- Night Mode `Only on CGDN1`
76+
- Power Off Time `Only on CGDN1`
77+
- Screensaver `Only on CGDN1`
78+
- Timezone `Only on CGDN1`
6579
- Battery level
6680
- Device status (online/offline)
6781
- Firmware version
@@ -73,12 +87,12 @@ The integration supports automatic discovery of Qingping CGS1/CGS2/CGDN1 devices
7387
- mg/m³ = ppb/218.77<br />
7488

7589
**eTVOC Sensor**: The sensor can be set to 3 different measurement units, by default it is VOC index. The component converts from voc index to get ppb and mg/m³.
76-
- ppb = (index * 5) + 35
77-
- mg/m³ = (index * 0.023) + 0.124
90+
- ppb = ( math.log ( 501 - voc_index ) - 6.24) * -2215.4
91+
- mg/m³ = ( ppb * 4.5 * 10 + 5 ) / 10 / 1000
7892

7993
5. **Data Updates**: The component subscribes to MQTT messages from the device. When new data is received, it updates the relevant sensors in Home Assistant.
8094

81-
6. **Offset Adjustments**: The integration allows you to set offset values for temperature and humidity readings. These offsets are applied to the raw sensor data before it's displayed in Home Assistant.
95+
6. **Offset Adjustments**: The integration allows you to set offset values for sesor readings. These offsets are applied to the device before it's displayed in Home Assistant.
8296

8397
7. **Update Interval**: You can configure how often the device should report new data. This is done through a number entity that allows you to set the update interval in seconds.
8498

custom_components/qingping_cgs1/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .const import DOMAIN, CONF_TEMPERATURE_OFFSET, CONF_HUMIDITY_OFFSET, DEFAULT_OFFSET, CONF_UPDATE_INTERVAL, DEFAULT_UPDATE_INTERVAL
1111

12-
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.NUMBER, Platform.SELECT]
12+
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.NUMBER, Platform.SELECT, Platform.SWITCH, Platform.BUTTON, Platform.TIME]
1313

1414
_LOGGER = logging.getLogger(__name__)
1515

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Support for Qingping CGSx button entities."""
2+
from __future__ import annotations
3+
4+
import json
5+
import logging
6+
7+
from homeassistant.components import mqtt
8+
from homeassistant.components.button import ButtonEntity
9+
from homeassistant.config_entries import ConfigEntry
10+
from homeassistant.const import CONF_NAME, CONF_MAC, CONF_MODEL
11+
from homeassistant.core import HomeAssistant
12+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
13+
from homeassistant.helpers.entity import EntityCategory
14+
from homeassistant.exceptions import HomeAssistantError
15+
16+
from .const import DOMAIN, MQTT_TOPIC_PREFIX
17+
18+
_LOGGER = logging.getLogger(__name__)
19+
20+
async def async_setup_entry(
21+
hass: HomeAssistant,
22+
config_entry: ConfigEntry,
23+
async_add_entities: AddEntitiesCallback,
24+
) -> None:
25+
"""Set up Qingping CGSx button entities from a config entry."""
26+
mac = config_entry.data[CONF_MAC]
27+
name = config_entry.data[CONF_NAME]
28+
model = config_entry.data[CONF_MODEL]
29+
30+
device_info = {
31+
"identifiers": {(DOMAIN, mac)},
32+
"name": name,
33+
"manufacturer": "Qingping",
34+
"model": model,
35+
}
36+
37+
buttons = []
38+
39+
# CGDN1-specific buttons
40+
if model == "CGDN1":
41+
buttons.append(
42+
QingpingCGSxManualCalibrationButton(config_entry, mac, name, device_info)
43+
)
44+
45+
if buttons:
46+
async_add_entities(buttons)
47+
48+
49+
class QingpingCGSxManualCalibrationButton(ButtonEntity):
50+
"""Button to trigger manual CO2 calibration."""
51+
52+
def __init__(self, config_entry, mac, name, device_info):
53+
"""Initialize the button."""
54+
self._config_entry = config_entry
55+
self._mac = mac
56+
self._attr_name = f"{name} Manual Calibration"
57+
self._attr_unique_id = f"{mac}_manual_calibration"
58+
self._attr_device_info = device_info
59+
self._attr_entity_category = EntityCategory.CONFIG
60+
self._attr_icon = "mdi:tune-vertical"
61+
62+
async def async_press(self) -> None:
63+
"""Handle the button press."""
64+
try:
65+
payload = {"type": "29"}
66+
topic = f"{MQTT_TOPIC_PREFIX}/{self._mac}/down"
67+
68+
_LOGGER.info("Triggering manual calibration for %s", self._mac)
69+
await mqtt.async_publish(self.hass, topic, json.dumps(payload))
70+
71+
except Exception as err:
72+
_LOGGER.error("Failed to trigger manual calibration: %s", err)
73+
raise HomeAssistantError(f"Failed to trigger calibration: {err}")

custom_components/qingping_cgs1/const.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,25 @@
4646
DEFAULT_DURATION = "86400"
4747

4848
QP_MODELS = ["CGS1", "CGS2", "CGDN1"]
49-
DEFAULT_MODEL = "CGS1"
49+
DEFAULT_MODEL = "CGS1"
50+
51+
# Device-specific settings
52+
CONF_CO2_ASC = "co2_asc"
53+
CONF_CO2_OFFSET = "co2_offset"
54+
CONF_PM25_OFFSET = "pm25_offset"
55+
CONF_PM10_OFFSET = "pm10_offset"
56+
CONF_NOISE_OFFSET = "noise_offset"
57+
CONF_TVOC_OFFSET = "tvoc_zoom"
58+
CONF_TVOC_INDEX_OFFSET = "tvoc_index_zoom"
59+
60+
# Default values for device settings
61+
DEFAULT_SENSOR_OFFSET = 0
62+
63+
# CGDN1 specific settings
64+
CONF_POWER_OFF_TIME = "power_off_time"
65+
CONF_DISPLAY_OFF_TIME = "display_off_time"
66+
CONF_NIGHT_MODE_START_TIME = "night_mode_start_time"
67+
CONF_NIGHT_MODE_END_TIME = "night_mode_end_time"
68+
CONF_AUTO_SLIDING_TIME = "auto_slideing_time"
69+
CONF_SCREENSAVER_TYPE = "screensaver_type"
70+
CONF_TIMEZONE = "timezone"

custom_components/qingping_cgs1/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "local_push",
99
"issue_tracker": "https://github.com/mash2k3/qingping_cgs1/issues",
1010
"requirements": [],
11-
"version": "1.2.5"
11+
"version": "1.2.7"
1212
}

0 commit comments

Comments
 (0)