I’m not exactly sure how I should check if the cron-triggered rules are loaded twice. Could you please explain this? Here is the code of all my cron triggered rules:
rule "Daily Doorbird motion events"
when
Time cron "0 0 0 * * ?"
then
var int counter = (NUM_Entrance_DoorBird_MotionEventCounterDaily.state as DecimalType).intValue
//logError("Daily Doorbird motion events", counter.toString())
NUM_Entrance_DoorBird_MotionEventsDaily.postUpdate(counter)
NUM_Entrance_DoorBird_MotionEventCounterDaily.postUpdate(0)
end
rule "Hourly Doorbird motion events"
when
Time cron "0 0 * * * ?"
then
var int counter = (NUM_Entrance_DoorBird_MotionEventCounterHourly.state as DecimalType).intValue
//logError("Hourly Doorbird motion events", counter.toString())
NUM_Entrance_DoorBird_MotionEventsHourly.postUpdate(counter)
NUM_Entrance_DoorBird_MotionEventCounterHourly.postUpdate(0)
end
rule "Fire indicator check"
when
Time cron "0 0 17 * * ?"
then
var DateTime checkDateTime = now.minusDays(1)
var sb = new StringBuilder
var String strDateTimeFormat = "yyyy-MM-dd'T'HH:mm:ssz"
var DateTime lastPacketReceived = getZwaveLastPacketReceived.apply("zwave:device:4c0da5c0:node28")
DT_ZWAVE_FireIND_1_LastUpdate.postUpdate(lastPacketReceived.toString(strDateTimeFormat))
//var String checkResult = checkStateIsBefore.apply(DT_ZWAVE_FireIND_1_LastUpdate, lastPacketReceived, checkDateTime) as String
if (lastPacketReceived.isBefore(checkDateTime)) {
sb.append(String::format("PC Zimmer David: %s\n", lastPacketReceived.toString(strDateTimeFormat)))
}
lastPacketReceived = getZwaveLastPacketReceived.apply("zwave:device:4c0da5c0:node12")
DT_ZWAVE_FireIND_2_LastUpdate.postUpdate(lastPacketReceived.toString(strDateTimeFormat))
//checkResult = checkStateIsBefore.apply(DT_ZWAVE_FireIND_2_LastUpdate, lastPacketReceived, checkDateTime) as String
if (lastPacketReceived.isBefore(checkDateTime)) {
sb.append(String::format("Keller: %s\n", lastPacketReceived.toString(strDateTimeFormat)))
}
lastPacketReceived = getZwaveLastPacketReceived.apply("zwave:device:4c0da5c0:node44")
DT_ZWAVE_FireIND_4_LastUpdate.postUpdate(lastPacketReceived.toString(strDateTimeFormat))
//checkResult = checkStateIsBefore.apply(DT_ZWAVE_FireIND_4_LastUpdate, lastPacketReceived, checkDateTime) as String
if (lastPacketReceived.isBefore(checkDateTime)) {
sb.append(String::format("1. Stock: %s\n", lastPacketReceived.toString(strDateTimeFormat)))
}
lastPacketReceived = getZwaveLastPacketReceived.apply("zwave:device:4c0da5c0:node43")
DT_ZWAVE_FireIND_3_LastUpdate.postUpdate(lastPacketReceived.toString(strDateTimeFormat))
//checkResult = checkStateIsBefore.apply(DT_ZWAVE_FireIND_3_LastUpdate, lastPacketReceived, checkDateTime) as String
if (lastPacketReceived.isBefore(checkDateTime)) {
sb.append(String::format("2. Stock: %s\n", lastPacketReceived.toString(strDateTimeFormat)))
}
if (sb.length > 0) {
var String message = String::format("Rauchmelder Haus 75 sind offline:\n\n%s", sb.toString())
sendMail("test@test.com", "Rauchmelder Haus 75 offline", message)
}
end
rule "Target temperature"
when
Item SW_Bedroom_Sleep changed or
Item SW_Presence_David_Phone_Home changed or
Item SW_Presence_David_Phone_Work changed or
Item SW_Living_Manual_Temperature changed or
Item NUM_Living_Manual_Temperature changed or
Time cron "0 0 18 ? * MON-FRI"
then
var Number temp = 19
var Number hour = now.getHourOfDay()
//logError("Target temperature", "Rule triggered hour: " + hour.toString())
if (SW_Living_Manual_Temperature.state == ON) {
temp = NUM_Living_Manual_Temperature.state as DecimalType
} else if (SW_Bedroom_Sleep.state == ON) {
temp = 19.75
} else if(SW_Presence_David_Phone_Home.state == ON) {
temp = 20.5
} else if(SW_Presence_David_Phone_Work.state == ON && hour >= 18) {
temp = 20.5
}
if (NUM_Living_Target_Temperature.state == NULL) {
NUM_Living_Target_Temperature.postUpdate(19)
}
var Number currentTemp = NUM_Living_Target_Temperature.state as DecimalType
if (currentTemp != temp) {
NUM_Living_Target_Temperature.postUpdate(temp)
//logError("Target temperature", "Target temperature set to: " + temp.toString)
}
end
rule "Heat alert"
when
Time cron "0 0,30 * * * ?"
then
if (NUM_OneWire_Living_Temperature.state instanceof DecimalType) {
var Number currentTemp = NUM_OneWire_Living_Temperature.state as DecimalType
if (NUM_Living_Target_Temperature.state instanceof DecimalType) {
var Number targetTemp = NUM_Living_Target_Temperature.state as DecimalType
if(currentTemp <= 17 && SW_ZWAVE_Living_Heating.state == ON) {
var String message = String::format("Die Heitzung scheint nicht mehr zu funktionieren. Es sind %.3f °C. Zieltemperatur ist %.3f °C.", currentTemp.floatValue, targetTemp.floatValue)
sendMail("test@test.com", "!!!HEITZUNGSALARM HAUS 75!!!", message)
} else if (currentTemp >= 22 && SW_ZWAVE_Living_Heating.state == ON) {
var String message = String::format("Die Heitzung läuft zu lange. Es sind %.3f °C. Zieltemperatur ist %.3f °C.", currentTemp.floatValue, targetTemp.floatValue)
sendMail("test@test.comh", "!!!HEITZUNGSALARM HAUS 75!!!", message)
}
} else {
var String message = String::format("Achtung die Zieltemperatur ist nicht initialisiert. Es sind %.3f °C.", currentTemp.floatValue)
sendMail("test@test.com", "!!!HEITZUNGSALARM HAUS 75!!!", message)
}
}
end
rule "Lights cellar"
when
Time cron "0 0,15,30,45 * * * ?"
then
var Number LuminanceAverage = NUM_ZWAVE_Cellar_Luminance.averageSince(now.minusMinutes(15), "rrd4j") as Number
var State MotionMaximum = SW_ZWAVE_Cellar_Motion.maximumSince(now.minusMinutes(15), "rrd4j").state
//logError("Lights.cellar", String::format("Helligkeit %s, Bewegungssensor %s", LuminanceAverage, MotionMaximum))
if (MotionMaximum == OFF && LuminanceAverage > 25) {
var String message = String::format("Licht im Keller läuft noch (Helligkeit %.3f, Bewegungssensor %s)", LuminanceAverage.floatValue, MotionMaximum)
sendMail("test@test.com", "!!!Keller Licht!!!", message)
}
end
rule "UPS Pico"
when
Time cron "0 * * * * ?" or
Item SW_System_Pico_Active received update
then
if (SW_System_Pico_Active.state == ON)
{
var String strOutput = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/pico.py", 5000)
var strSplit = strOutput.split("\\|")
//logError("UPS Pico output", strOutput)
if (strSplit.size == 3) {
var Number numTemp = new DecimalType(strSplit.get(0))
//if (NUM_System_Pico_Temp.state != numTemp)
NUM_System_Pico_Temp.postUpdate(numTemp)
var Number numBattery = new DecimalType(strSplit.get(1))
//if (NUM_System_Pico_Battery.state != numBattery)
NUM_System_Pico_Battery.postUpdate(numBattery)
var String strPower = strSplit.get(2)
//if (ST_System_Pico_Power.state != strPower)
ST_System_Pico_Power.postUpdate(strPower)
}
}
end
rule "Z-Wave CAN hourly"
when
Time cron "0 0 * * * ?"
then
if (NUM_ZWAVE_Info_CAN.state != NULL)
{
var Number numCan = NUM_ZWAVE_Info_CAN.state as Number
var Number numCanLast = 0
if (NUM_ZWAVE_Info_CAN_Last.state != NULL)
{
numCanLast = NUM_ZWAVE_Info_CAN_Last.state as Number
}
NUM_ZWAVE_Info_CAN_Hourly.postUpdate(numCan - numCanLast)
NUM_ZWAVE_Info_CAN_Last.postUpdate(numCan)
}
end
rule "Memory check"
when
Time cron "0 0 17 * * ?"
then
if (NUM_System_Memory_Available_Percent.state != NULL)
{
var Number numMemoryAvailable = NUM_System_Memory_Available_Percent.state as Number
if (numMemoryAvailable <= 15)
{
sendMail("test@test.com", "Memoryauslastung Openhabian01", String::format("Memory frei: %s%%", numMemoryAvailable))
}
}
end
rule "Battery alert"
when
Time cron "0 0 16 * * ?"
then
val sb = new StringBuilder
G_All.allMembers.filter(d | d.state instanceof Number && d.name.endsWith("_Battery")).forEach[ batteryItem |
val Number numBattery = batteryItem.state as Number
if (numBattery < 15)
{
sb.append(String::format("Item: %s Batteriestand: %s\n", batteryItem.name, numBattery))
}
]
//logError("Battery alert", sb.length.toString())
if (sb.length > 0) {
var String message = String::format("Folgende Batterien sind bald leer:\n\n%s", sb.toString())
sendMail("test@test.com", "Alarm Batteriestand", message)
}
end