diff --git a/apps/widbaroalarm/README.md b/apps/widbaroalarm/README.md index 6708b1e2b..b92a51050 100644 --- a/apps/widbaroalarm/README.md +++ b/apps/widbaroalarm/README.md @@ -11,7 +11,9 @@ Get a notification when the pressure reaches defined thresholds. * Low threshold: Warn when pressure drops below this value * High alarm: Toggle high alarm * High threshold: Warn when pressure exceeds above this value -* Change alarm: Warn when pressure changes more than this value in the recent 3 hours (having at least 30 min of data) +* Drop alarm: Warn when pressure drops more than this value in the recent 3 hours (having at least 30 min of data) + 0 to disable this alarm. +* Raise alarm: Warn when pressure raises more than this value in the recent 3 hours (having at least 30 min of data) 0 to disable this alarm. * Show widget: Enable/disable widget visibility * Buzz on alarm: Enable/disable buzzer on alarm diff --git a/apps/widbaroalarm/default.json b/apps/widbaroalarm/default.json index 7dbe6fc17..3d81baa81 100644 --- a/apps/widbaroalarm/default.json +++ b/apps/widbaroalarm/default.json @@ -4,7 +4,8 @@ "min": 950, "highalarm": false, "max": 1030, - "changeIn3h": 2, + "drop3halarm": 2, + "raise3halarm": 0, "show": true, "interval": 15 } diff --git a/apps/widbaroalarm/settings.js b/apps/widbaroalarm/settings.js index d3d2df0ae..1455072e4 100644 --- a/apps/widbaroalarm/settings.js +++ b/apps/widbaroalarm/settings.js @@ -53,15 +53,25 @@ step: 10, onchange: x => save("max", x), }, - "Change alarm": { - value: settings.changeIn3h, + "Drop alarm": { + value: settings.drop3halarm, min: 0, max: 10, step: 1, format: x => { return x != 0 ? x + ' hPa/3h' : 'off'; }, - onchange: x => save("changeIn3h", x) + onchange: x => save("drop3halarm", x) + }, + "Raise alarm": { + value: settings.raise3halarm, + min: 0, + max: 10, + step: 1, + format: x => { + return x != 0 ? x + ' hPa/3h' : 'off'; + }, + onchange: x => save("raise3halarm", x) }, "Show widget": { value: settings.show, diff --git a/apps/widbaroalarm/widget.js b/apps/widbaroalarm/widget.js index 443b6c68c..9b65ffe5b 100644 --- a/apps/widbaroalarm/widget.js +++ b/apps/widbaroalarm/widget.js @@ -80,8 +80,9 @@ if (!alreadyWarned) { // 3h change detection - const threeHourChange = setting("changeIn3h"); - if (threeHourChange > 0) { + const drop3halarm = setting("drop3halarm"); + const raise3halarm = setting("raise3halarm"); + if (drop3halarm > 0 || raise3halarm > 0) { // we need at least 30min of data for reliable detection if (history3[0]["ts"] > ts - (30 * 60)) { return; @@ -91,10 +92,23 @@ const oldestAvgPressure = (history3[0]["p"] + history3[1]["p"] + history3[2]["p"]) / 3; if (oldestAvgPressure != undefined && oldestAvgPressure > 0) { const diff = oldestAvgPressure - avrPressure; - if (Math.abs(diff) > threeHourChange) { - showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " + - Math.round(oldestAvgPressure) + " to " + Math.round(avrPressure) + " hPa", - "Pressure " + (diff > 0 ? "drop" : "raise")); + + // drop alarm + if (drop3halarm > 0 && oldestAvgPressure > avrPressure) { + if (Math.abs(diff) > drop3halarm) { + showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " + + Math.round(oldestAvgPressure) + " to " + Math.round(avrPressure) + " hPa", + "Pressure drop")); + } + } + + // raise alarm + if (raise3halarm > 0 && oldestAvgPressure < avrPressure) { + if (Math.abs(diff) > raise3halarm) { + showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " + + Math.round(oldestAvgPressure) + " to " + Math.round(avrPressure) + " hPa", + "Pressure raise")); + } } } }