-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (37 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const cron = require("node-cron");
const Tado = require("node-tado-client");
const axios = require("axios");
require("dotenv").config();
var tado = new Tado();
cron.schedule("*/20 * * * *", function () {
console.log("updating brewfather every twenty minutes");
let temperature = undefined;
tado.login(process.env.TADO_USERNAME, process.env.TADO_PASSWORD).then(() => {
tado
.getZoneState(process.env.TADO_HOME_ID, process.env.TADO_ZONE_ID)
.then((resp) => {
temperature =
(resp.sensorDataPoints &&
resp.sensorDataPoints.insideTemperature &&
resp.sensorDataPoints.insideTemperature.celsius) ||
undefined;
if (typeof temperature == "number") {
axios
.post(process.env.BREWFATHER_WEBHOOK, {
name: process.env.BREWFATHER_DEVICE_NAME,
ext_temp: temperature,
temp_unit: "C",
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
})
.catch(function (err) {
console.log(err);
});
});
});