From 492b59e9d1eb2a50622d0759871f380a4a7d6891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 21 May 2021 08:46:39 +0200 Subject: [PATCH] Add indoor air quality interface and catch invalid VOC measurement value --- .../integrationpluginzigbeedevelco.cpp | 32 +++++++++++++++++-- .../integrationpluginzigbeedevelco.h | 1 + .../integrationpluginzigbeedevelco.json | 17 +++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/zigbeedevelco/integrationpluginzigbeedevelco.cpp b/zigbeedevelco/integrationpluginzigbeedevelco.cpp index ed36694c..4bb38134 100644 --- a/zigbeedevelco/integrationpluginzigbeedevelco.cpp +++ b/zigbeedevelco/integrationpluginzigbeedevelco.cpp @@ -368,7 +368,13 @@ void IntegrationPluginZigbeeDevelco::setupThing(ThingSetupInfo *info) bool valueOk = false; quint16 value = measuredValueAttribute.dataType().toUInt16(&valueOk); if (valueOk) { - thing->setStateValue(airQualitySensorVocStateTypeId, value); + if (value == 0xFFFF) { + qCWarning(dcZigbeeDevelco()) << "Received invalid VOC measurment. The sensor is not ready yet."; + } else { + qCDebug(dcZigbeeDevelco()) << thing << "VOC changed" << value << "ppm"; + thing->setStateValue(airQualitySensorVocStateTypeId, value); + updateIndoorAirQuality(thing, value); + } } else { qCWarning(dcZigbeeDevelco()) << "Failed to convert VOC measurment value" << measuredValueAttribute; } @@ -379,8 +385,13 @@ void IntegrationPluginZigbeeDevelco::setupThing(ThingSetupInfo *info) bool valueOk = false; quint16 value = attribute.dataType().toUInt16(&valueOk); if (valueOk) { - qCDebug(dcZigbeeDevelco()) << thing << "VOC changed" << value << "ppm"; - thing->setStateValue(airQualitySensorVocStateTypeId, value); + if (value == 0xFFFF) { + qCWarning(dcZigbeeDevelco()) << "Received invalid VOC measurment. The sensor is not ready yet."; + } else { + qCDebug(dcZigbeeDevelco()) << thing << "VOC changed" << value << "ppm"; + thing->setStateValue(airQualitySensorVocStateTypeId, value); + updateIndoorAirQuality(thing, value); + } } else { qCWarning(dcZigbeeDevelco()) << "Failed to convert VOC measurment value" << attribute; } @@ -830,6 +841,21 @@ void IntegrationPluginZigbeeDevelco::configureVocReporting(ZigbeeNode *node, Zig }); } +void IntegrationPluginZigbeeDevelco::updateIndoorAirQuality(Thing *thing, uint voc) +{ + if (voc <= 65) { + thing->setStateValue(airQualitySensorIndoorAirQualityStateTypeId, "Excellent"); + } else if (voc <= 220) { + thing->setStateValue(airQualitySensorIndoorAirQualityStateTypeId, "Good"); + } else if (voc <= 660) { + thing->setStateValue(airQualitySensorIndoorAirQualityStateTypeId, "Moderate"); + } else if (voc <= 2200) { + thing->setStateValue(airQualitySensorIndoorAirQualityStateTypeId, "Poor"); + } else { + thing->setStateValue(airQualitySensorIndoorAirQualityStateTypeId, "Unhealthy"); + } +} + void IntegrationPluginZigbeeDevelco::readDevelcoFirmwareVersion(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint) { // Read manufacturer specific basic cluster attribute 0x8000 diff --git a/zigbeedevelco/integrationpluginzigbeedevelco.h b/zigbeedevelco/integrationpluginzigbeedevelco.h index 53b78014..05b40aed 100644 --- a/zigbeedevelco/integrationpluginzigbeedevelco.h +++ b/zigbeedevelco/integrationpluginzigbeedevelco.h @@ -119,6 +119,7 @@ private: void configureHumidityReporting(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint); void configureBattryVoltageReporting(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint); void configureVocReporting(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint); + void updateIndoorAirQuality(Thing *thing, uint voc); void readDevelcoFirmwareVersion(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint); void readOnOffPowerAttribute(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint); diff --git a/zigbeedevelco/integrationpluginzigbeedevelco.json b/zigbeedevelco/integrationpluginzigbeedevelco.json index 3cc2e74d..f9fa2893 100644 --- a/zigbeedevelco/integrationpluginzigbeedevelco.json +++ b/zigbeedevelco/integrationpluginzigbeedevelco.json @@ -153,7 +153,7 @@ "name": "airQualitySensor", "displayName": "Air qualiy sensor", "createMethods": ["auto"], - "interfaces": ["temperaturesensor", "humiditysensor", "battery", "wirelessconnectable"], + "interfaces": ["indoorairquality", "temperaturesensor", "humiditysensor", "battery", "wirelessconnectable"], "paramTypes": [ { "id": "dbad9e63-1adc-45ef-8bfc-4947060f19f4", @@ -228,6 +228,21 @@ "type": "bool", "defaultValue": false }, + { + "id": "8396ec7e-54d4-452f-9558-c366e0904b2f", + "name": "indoorAirQuality", + "displayName": "Air quality", + "displayNameEvent": "Air quality changed", + "type": "QString", + "defaultValue": "Good", + "possibleValues": [ + "Excellent", + "Good", + "Moderate", + "Poor", + "Unhealthy" + ] + }, { "id": "1ba14107-4241-46d0-b65f-eb6e8c6f8e08", "name": "voc",