Rule triggered by time doesn't fire

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.

Every six hours should be

Time cron "0 0 */6 * * ?"

because in openHAB the first digit are seconds … strange thing is your rule should have fired every six minutes …

yeah as far as I can tell it’s ignoring the cron all together.

Is the or the problem?

Ahhh, you have the “when” twice!

oh good catch. Ok I’ve updated that (and the cron) - will have to see what it does now.

See you in six hours :slight_smile:

1 Like