From 660076293868a9bb7061c4d1a381f81ed4dfc0d2 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 1 Jun 2024 10:57:20 -0700 Subject: [PATCH] Add support for WS-1938 indoor CO2 sensor Fixes #160 --- DEVELOPMENT.md | 4 ++++ README.md | 2 ++ src/controllers/weatherDataController.ts | 2 ++ src/entityManager.ts | 8 ++++++++ src/entityNames.ts | 2 ++ 5 files changed, 18 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index d01af3b..da0eb72 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -42,3 +42,7 @@ And here's an example with lightning: And here's an example with AQIN data: `/data/?tempf=76.3&date=2023-09-28T16%3A15%3A00.000Z&aqi_pm25_24h_aqin=5&batt_25=1&tz=America%2FChicago&pm25_in_aqin=0.9&co2_in_24h_aqin=988&feelsLikein=74.9&aqi_pm25=38&lastRain=2023-09-23T21%3A22%3A00.000Z&pm10_in_24h_aqin=1.9&dewPointin=50.3&monthlyrainin=3.043&dailyrainin=0&aqi_pm25_aqin=4&pm25_in_24h_aqin=1.2&solarradiation=68.02&pm25_24h=3&humidityin=41&aqi_pm25_24h=13&humidity=69&pm_in_humidity_aqin=46&pm10_in_aqin=1.2&maxdailygust=6.93&pm_in_temp_aqin=74.1&uv=0&windspeedmph=0&yearlyrainin=7.752&winddir=184&hourlyrainin=0&eventrainin=0&baromabsin=28.969&battin=1&dewPoint=65.36&tempinf=75.7&battout=1&feelsLike=76.87&dateutc=1695917700000&windgustmph=1.12&macAddress=C8%3AC9%3AA3%3A55%3A93%3A17&pm25=9&co2_in_aqin=964&baromrelin=28.969&batt_co2=1&winddir_avg10m=195&weeklyrainin=0` + +And here's an example with indoor CO2 data: + +`/data/?tempf=76.3&date=2023-09-28T16%3A15%3A00.000Z&aqi_pm25_24h_aqin=5&batt_25=1&tz=America%2FChicago&pm25_in_aqin=0.9&co2_in_24h_aqin=988&feelsLikein=74.9&aqi_pm25=38&lastRain=2023-09-23T21%3A22%3A00.000Z&pm10_in_24h_aqin=1.9&dewPointin=50.3&monthlyrainin=3.043&dailyrainin=0&aqi_pm25_aqin=4&pm25_in_24h_aqin=1.2&solarradiation=68.02&pm25_24h=3&humidityin=41&aqi_pm25_24h=13&humidity=69&pm_in_humidity_aqin=46&pm10_in_aqin=1.2&maxdailygust=6.93&pm_in_temp_aqin=74.1&uv=0&windspeedmph=0&yearlyrainin=7.752&winddir=184&hourlyrainin=0&eventrainin=0&baromabsin=28.969&battin=1&dewPoint=65.36&tempinf=75.7&battout=1&feelsLike=76.87&dateutc=1695917700000&windgustmph=1.12&macAddress=C8%3AC9%3AA3%3A55%3A93%3A17&pm25=9&co2_in_aqin=964&baromrelin=28.969&batt_co2=1&winddir_avg10m=195&weeklyrainin=0&co2_in=1447&co2_in_24h=1289` diff --git a/README.md b/README.md index 710d511..030f6a3 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,8 @@ The following sensors are supported. Note that weather stations will only report | batteryPM25Ok | State of the PM25 device battery, `0` for not ok, `100` for ok | Yes | No | percent | | batteryLightning | State of the lightning device battery, `0` for not ok, `100` for ok | Yes | No | percent | | co2 | CO2 meter reading | Yes | No | ppm | +| co2_in | Indoor CO2 meter reading | Yes | No | ppm | +| co2_in_24h | Indoor CO2 meter 24 hour average | Yes | No | ppm | | dewpoint | Outdoor dewpoint temperature | No | Yes | °F | | eventDate | Date of the latest measurements | Yes | Yes | date | | humidity1..10 | Humidity sensors 1 through 10 | Yes | No | percent | diff --git a/src/controllers/weatherDataController.ts b/src/controllers/weatherDataController.ts index 3d21f39..c1bfc1f 100644 --- a/src/controllers/weatherDataController.ts +++ b/src/controllers/weatherDataController.ts @@ -140,6 +140,8 @@ export async function processWeatherData(req: express.Request, res: express.Resp setDataPayload(EntityNames.BATTERYPM25OK, convertBatteryValue(req.query.batt_25 as string)); setDataPayload(EntityNames.BATTERYLIGHTNING, convertBatteryValue(req.query.batt_lightning as string)); setDataPayload(EntityNames.CO2, +req.query.co2); + setDataPayload(EntityNames.CO2_IN, +req.query.co2_in); + setDataPayload(EntityNames.CO2_IN_24H, +req.query.co2_in_24h); // Only available in Weather Underground updates. For Ambient Weather stations // this is a calculated sensor, handled farther down in this function. setDataPayload(EntityNames.DEWPOINT, +req.query.dewptf); diff --git a/src/entityManager.ts b/src/entityManager.ts index 3f1c828..74079ff 100644 --- a/src/entityManager.ts +++ b/src/entityManager.ts @@ -188,6 +188,14 @@ export function initialize(): void { ), ); entities.set(EntityNames.CO2, new Sensor(EntityNames.CO2, deviceId, SensorUnit.partsPerMillion, DeviceClass.CO2)); + entities.set( + EntityNames.CO2_IN, + new Sensor(EntityNames.CO2_IN, deviceId, SensorUnit.partsPerMillion, DeviceClass.CO2), + ); + entities.set( + EntityNames.CO2_IN_24H, + new Sensor(EntityNames.CO2_IN_24H, deviceId, SensorUnit.partsPerMillion, DeviceClass.CO2), + ); entities.set(EntityNames.DEWPOINT, new Sensor(EntityNames.DEWPOINT, deviceId, SensorUnit.F, DeviceClass.TEMPERATURE)); entities.set( EntityNames.EVENTDATE, diff --git a/src/entityNames.ts b/src/entityNames.ts index 369d3ee..29b665c 100644 --- a/src/entityNames.ts +++ b/src/entityNames.ts @@ -21,6 +21,8 @@ enum EntityNames { BATTERYPM25OK = "batteryPM25Ok", BATTERYLIGHTNING = "batt_lightning", CO2 = "co2", + CO2_IN = "co2_in", + CO2_IN_24H = "co2_in_24h", /** * @deprecated Replaced with eventDate */