Improve rais/drop calculation and handling

master
Marco H 2022-06-12 17:12:06 +02:00
parent b5f3930c41
commit 4dba48f0ac
1 changed files with 9 additions and 12 deletions

View File

@ -103,8 +103,6 @@
} else { } else {
saveSetting("lastLowWarningTs", 0); saveSetting("lastLowWarningTs", 0);
} }
} else {
saveSetting("lastLowWarningTs", 0);
} }
if (setting("highalarm")) { if (setting("highalarm")) {
@ -117,8 +115,6 @@
} else { } else {
saveSetting("lastHighWarningTs", 0); saveSetting("lastHighWarningTs", 0);
} }
} else {
saveSetting("lastHighWarningTs", 0);
} }
if (history3.length > 0 && !alreadyWarned) { if (history3.length > 0 && !alreadyWarned) {
@ -127,21 +123,22 @@
const raise3halarm = setting("raise3halarm"); const raise3halarm = setting("raise3halarm");
if (drop3halarm > 0 || raise3halarm > 0) { if (drop3halarm > 0 || raise3halarm > 0) {
// we need at least 30min of data for reliable detection // we need at least 30min of data for reliable detection
if (history3[0]["ts"] > ts - (30 * 60)) { const diffDateAge = Math.abs(history3[0]["ts"] - ts);
if (diffDateAge < 10 * 60) { // todo change to 1800
return; return;
} }
// Get oldest entry: // Get oldest entry:
const oldestPressure = history3[0]["p"]; const oldestPressure = history3[0]["p"];
if (oldestPressure != undefined && oldestPressure > 0) { if (oldestPressure != undefined && oldestPressure > 0) {
const diff = oldestPressure - pressure; const diffPressure = Math.abs(oldestPressure - pressure);
// drop alarm // drop alarm
if (drop3halarm > 0 && oldestPressure > pressure) { if (drop3halarm > 0 && oldestPressure > pressure) {
if (Math.abs(diff) > drop3halarm) { if (diffPressure > drop3halarm) {
if (doWeNeedToWarn("lastDropWarningTs")) { if (doWeNeedToWarn("lastDropWarningTs")) {
showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " + showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "Pressure drop", "lastDropWarningTs"); Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "lastDropWarningTs");
} }
} else { } else {
saveSetting("lastDropWarningTs", 0); saveSetting("lastDropWarningTs", 0);
@ -152,10 +149,10 @@
// raise alarm // raise alarm
if (raise3halarm > 0 && oldestPressure < pressure) { if (raise3halarm > 0 && oldestPressure < pressure) {
if (Math.abs(diff) > raise3halarm) { if (diffPressure > raise3halarm) {
if (doWeNeedToWarn("lastRaiseWarningTs")) { if (doWeNeedToWarn("lastRaiseWarningTs")) {
showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " + showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "Pressure raise", "lastRaiseWarningTs"); Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "lastRaiseWarningTs");
} }
} else { } else {
saveSetting("lastRaiseWarningTs", 0); saveSetting("lastRaiseWarningTs", 0);