From 642153369a31e5d2efdb96ed1b91e3f88b4f374d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Homonnay=20P=C3=A9ter?= Date: Fri, 10 Mar 2023 22:52:58 +0100 Subject: [PATCH 1/2] Added support for Sensirion's SEN5X Environmental sensor node-family for PM, RH/T, VOC, NOx measurements --- README.md | 6 +++ custom_components/local_luftdaten/const.py | 58 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 79a5057..8c12957 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,12 @@ At the moment following sensor data can be read: - SPS30_P1 - SPS30_P2 - SPS30_P4 +- SEN5X_P0 +- SEN5X_P1 +- SEN5X_P2 +- SEN5X_P4 +- SEN5X_NOX +- SEN5X_VOC - temperature - signal diff --git a/custom_components/local_luftdaten/const.py b/custom_components/local_luftdaten/const.py index 5008c84..2975b09 100644 --- a/custom_components/local_luftdaten/const.py +++ b/custom_components/local_luftdaten/const.py @@ -8,7 +8,7 @@ from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, PERCENTAGE, - PRESSURE_PA, + UnitOfPressure, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_CELSIUS, ) @@ -48,6 +48,12 @@ SENSOR_SPS30_P1 = 'SPS30_P1' SENSOR_SPS30_P2 = 'SPS30_P2' SENSOR_SPS30_P4 = 'SPS30_P4' +SENSOR_SEN5X_P0 = 'SEN5X_P0' +SENSOR_SEN5X_P1 = 'SEN5X_P1' +SENSOR_SEN5X_P2 = 'SEN5X_P2' +SENSOR_SEN5X_P4 = 'SEN5X_P4' +SENSOR_SEN5X_NOX = 'SEN5X_NOX' +SENSOR_SEN5X_VOC = 'SEN5X_VOC' SENSOR_TEMPERATURE = 'temperature' SENSOR_WIFI_SIGNAL = 'signal' @@ -63,7 +69,7 @@ device_class=SensorDeviceClass.PRESSURE, key=SENSOR_BME280_PRESSURE, name='Pressure', - native_unit_of_measurement=PRESSURE_PA, + native_unit_of_measurement=UnitOfPressure.PA, state_class=SensorStateClass.MEASUREMENT, ), SENSOR_BME280_TEMPERATURE: SensorEntityDescription( @@ -77,7 +83,7 @@ device_class=SensorDeviceClass.PRESSURE, key=SENSOR_BMP_PRESSURE, name='Pressure', - native_unit_of_measurement=PRESSURE_PA, + native_unit_of_measurement=UnitOfPressure.PA, state_class=SensorStateClass.MEASUREMENT, ), SENSOR_BMP_TEMPERATURE: SensorEntityDescription( @@ -98,7 +104,7 @@ device_class=SensorDeviceClass.PRESSURE, key=SENSOR_BMP280_PRESSURE, name='Pressure', - native_unit_of_measurement=PRESSURE_PA, + native_unit_of_measurement=UnitOfPressure.PA, state_class=SensorStateClass.MEASUREMENT, ), SENSOR_DS18B20_TEMPERATURE: SensorEntityDescription( @@ -234,6 +240,50 @@ native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, state_class=SensorStateClass.MEASUREMENT, ), + SENSOR_SEN5X_P0: SensorEntityDescription( + device_class=SensorDeviceClass.PM1, + key=SENSOR_SEN5X_P0, + name='PM1', + native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + state_class=SensorStateClass.MEASUREMENT, + ), + SENSOR_SEN5X_P1: SensorEntityDescription( + device_class=SensorDeviceClass.PM10, + key=SENSOR_SEN5X_P1, + name='PM10', + native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + state_class=SensorStateClass.MEASUREMENT, + ), + SENSOR_SEN5X_P2: SensorEntityDescription( + device_class=SensorDeviceClass.PM25, + key=SENSOR_SEN5X_P2, + name='PM2.5', + native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + state_class=SensorStateClass.MEASUREMENT, + ), + SENSOR_SEN5X_P4: SensorEntityDescription( + device_class=SensorDeviceClass.PM25, # SensorDeviceClass.PM4 not supported. + key=SENSOR_SEN5X_P4, + name='PM4', + native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + state_class=SensorStateClass.MEASUREMENT, + ), + SENSOR_SEN5X_NOX: SensorEntityDescription( + device_class=SensorDeviceClass.AQI, + # SensorDeviceClass.NOX_INDEX is not supported + # SensorDeviceClass.NITROGEN_MONOXIDE and .NITROGEN_DIOXIDE are supported, but require a unit of ug/m3 which is not appropriate for a unitless index + key=SENSOR_SEN5X_NOX, + name='NOX', + state_class=SensorStateClass.MEASUREMENT, + ), + SENSOR_SEN5X_VOC: SensorEntityDescription( + device_class=SensorDeviceClass.AQI, + # SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_INDEX is not supported + # SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS is supported, but requires a unit of ug/m3 which is not appropriate for a unitless index + key=SENSOR_SEN5X_VOC, + name='VOC', + state_class=SensorStateClass.MEASUREMENT, + ), SENSOR_TEMPERATURE: SensorEntityDescription( device_class=SensorDeviceClass.TEMPERATURE, key=SENSOR_TEMPERATURE, From 042e0be5592a882e94cd23bd15e0e0e15af4cb59 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 21 Apr 2023 22:35:39 +0200 Subject: [PATCH 2/2] Remove asyncio.coroutine This is not supported by Python 3.11 anymore, because this construct was deprecated in Python 3.8. Since HASS requires Python 3.10 at minimum, it should be safe to remove. --- custom_components/local_luftdaten/sensor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/custom_components/local_luftdaten/sensor.py b/custom_components/local_luftdaten/sensor.py index a313121..4f4f5b4 100644 --- a/custom_components/local_luftdaten/sensor.py +++ b/custom_components/local_luftdaten/sensor.py @@ -58,7 +58,6 @@ }) -@asyncio.coroutine async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Luftdaten sensor.""" name = config.get(CONF_NAME) @@ -66,7 +65,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= scan_interval = config.get(CONF_SCAN_INTERVAL) verify_ssl = config.get(CONF_VERIFY_SSL) - resource = config.get(CONF_RESOURCE).format(host)