Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Publish dew point approximation to mqtt #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
"type": "string",
"title": "Humidity Topic"
},
"dewPointTopic": {
"type": "string",
"title": "Dew Point Topic"
},
"batteryTopic": {
"type": "string",
"title": "Battery Topic"
Expand Down Expand Up @@ -169,6 +173,7 @@
"mqtt.url",
"mqtt.temperatureTopic",
"mqtt.humidityTopic",
"mqtt.dewPointTopic",
"mqtt.batteryTopic"
]
},
Expand Down
26 changes: 26 additions & 0 deletions lib/accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class HygrothermographAccessory {

this.temperatureMQTTTopic = undefined;
this.humidityMQTTTopic = undefined;
this.dewPointMQTTTopic = undefined;
this.batteryMQTTTopic = undefined;
this.mqttClient = this.setupMQTTClient();

Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down