I’ve got the rule which will check a battery and call a script the sends a boxcar notification.
I have the rule set up on a switch and that works.
But it’s supposed to fire every 6 hours and doesn’t
Script as follows:
import org.openhab.core.library.types.*
val int lowBatteryThreshold = 90
rule "Battery Monitor"
when
when Time cron "0 */6 * * * ?" or
Item boxcar_action received update
then
logInfo("BatteryMonitor","Received Command")
if (! g_battery.allMembers.filter([state < lowBatteryThreshold]).empty)
{
logInfo("BatteryMonitor","Found some item(s) under threshold")
val report = g_battery.allMembers.filter([state instanceof DecimalType]).sortBy([state]).map[
name + ": " + (state as DecimalType)
].join("\n")
val message = "Battery levels (Threshold:" + lowBatteryThreshold + "):\n" + report
logInfo("BatteryMonitor","Report produced: " + message)
val StringBuilder report2 = new StringBuilder(64)
/* g_battery.allMembers.forEach[g |
logInfo("BatteryMonitor","Item " + g.name + " state: " + g.state as DecimalType)
if ((g.state as DecimalType) < lowBatteryThreshold) {
report = report + "Item " + g.name + " state: " + g.state as DecimalType) + " Low Battery"
logInfo("BatteryMonitor","Low Battery")
}
]
message = "Battery levels (Threshold:" + lowBatteryThreshold + "):\n" + report
*/
executeCommandLine("/etc/openhab/configurations/scripts/boxcar.sh " + message)
}
end
Any ideas why? Technically this isn’t actually doing anything any more, but it should still be posting a message.