diff --git a/config.schema.json b/config.schema.json index 45dc28e..bf669c0 100644 --- a/config.schema.json +++ b/config.schema.json @@ -114,6 +114,10 @@ "type": "string", "title": "Humidity Topic" }, + "dewPointTopic": { + "type": "string", + "title": "Dew Point Topic" + }, "batteryTopic": { "type": "string", "title": "Battery Topic" @@ -169,6 +173,7 @@ "mqtt.url", "mqtt.temperatureTopic", "mqtt.humidityTopic", + "mqtt.dewPointTopic", "mqtt.batteryTopic" ] }, diff --git a/lib/accessory.js b/lib/accessory.js index 5eaa487..732ce47 100644 --- a/lib/accessory.js +++ b/lib/accessory.js @@ -29,6 +29,7 @@ class HygrothermographAccessory { this.temperatureMQTTTopic = undefined; this.humidityMQTTTopic = undefined; + this.dewPointMQTTTopic = undefined; this.batteryMQTTTopic = undefined; this.mqttClient = this.setupMQTTClient(); @@ -37,6 +38,23 @@ class HygrothermographAccessory { this.log.debug("Initialized accessory"); } + get dewPoint() { + if ( + this.hasTimedOut() || + this.latestTemperature == null || + this.latestHumidity == null + ) { + return; + } + // Magnus dew point approximation + const t = this.temperature; + const h = this.humidity; + const a = 17.27; + const b = 237.7; + const alpha = (a * t) / (b + t) + Math.log(h / 100); + return (b * alpha) / (a - alpha); + } + setTemperature(newValue, force = false) { if (newValue == null) { return; @@ -51,6 +69,9 @@ class HygrothermographAccessory { .updateValue(newValue); this.addFakeGatoHistoryEntry(); this.publishValueToMQTT(this.temperatureMQTTTopic, this.temperature); + if (this.dewPoint) { + this.publishValueToMQTT(this.dewPointMQTTTopic, this.dewPoint); + } } get temperature() { @@ -74,6 +95,9 @@ class HygrothermographAccessory { .updateValue(newValue); this.addFakeGatoHistoryEntry(); this.publishValueToMQTT(this.humidityMQTTTopic, this.humidity); + if (this.dewPoint) { + this.publishValueToMQTT(this.dewPointMQTTTopic, this.dewPoint); + } } get humidity() { @@ -268,12 +292,14 @@ class HygrothermographAccessory { temperatureTopic, humidityTopic, batteryTopic, + dewPointTopic, url, ...mqttOptions } = config; this.temperatureMQTTTopic = temperatureTopic; this.humidityMQTTTopic = humidityTopic; + this.dewPointMQTTTopic = dewPointTopic; this.batteryMQTTTopic = batteryTopic; const client = mqtt.connect(url, mqttOptions);