Skip to content

Commit

Permalink
Fix warnings due to InfluxDBs way of handling empty returns
Browse files Browse the repository at this point in the history
Apparently, if InfluxDB doesn't count any values it won't just return `count: 0`, but rather _nothing_ (`[[]]`)...
  • Loading branch information
KLVN committed Jan 20, 2021
1 parent d4695d2 commit e844b07
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions additionalScripts/bathroomVentilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ setInterval(function () {
if (result.error) {
console.error(result.error);
} else {
var countAboveThreshold = result["result"][0][0]["count"];
if (result["result"][0].length >= 1) {
var countAboveThreshold = result["result"][0][0]["count"];

// If there are >= 14 values above 6kW in the last three minutes (see query)
if (countAboveThreshold >= 14) {
// then set fan speed to 4
setState(datapoint_prefix + "." + datapoint_names["w00102"], 4);
// and after 15 minutes set fan speed back to its initial value
setStateDelayed(datapoint_prefix + "." + datapoint_names["w00102"], currentFanSpeed, 15 * 60000, true, function () {
console.log("VENTILATION: Ventilation was turned off 15 minutes after showering");
});
// If there are >= 14 values above 6kW in the last three minutes (see query)
if (countAboveThreshold >= 14) {
// then set fan speed to 4
setState(datapoint_prefix + "." + datapoint_names["w00102"], 4);
// and after 15 minutes set fan speed to 0
setStateDelayed(datapoint_prefix + "." + datapoint_names["w00102"], 0, 15 * 60000, true, function () {
console.log("VENTILATION: Ventilation was turned off 15 minutes after showering");
});
}
}
}
});
Expand Down

0 comments on commit e844b07

Please sign in to comment.