Maybe Iâm looping but Iâd rather askâŚ
Letâs consider 2 pair of the rules that supports one of my gates eventsâŚ
rule "Gate Opening"
when
Item Stan_bramy_garazowej changed to OFF
then
logInfo("KWI.debug.rules","REGRUN: Ruch bramy garaĹźowej - Otwarta")
if(tRBG === null) {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 1 (" + tRBG + ")")
nRBG = 0
logInfo("KWI.debug.rules","R_DEBUG: tRBG 2 (" + tRBG + ")")
tRBG = createTimer(now, [|
logInfo("KWI.debug.rules","R_DEBUG: tRBG 3 (" + tRBG + ")")
nRBG += 1
logInfo("KWI.debug.rules","R_DEBUG: tRBG 4 (" + tRBG + ")")
switch (nRBG.intValue) {
case 1 : {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 5 (" + tRBG + ")")
Stan_bramy_garazowej_N.sendCommand(ON)
Brama_garazowa_LOG.postUpdate(ON)
if(PARTITION_PW_Piwnica_ARMED.state == OFF) {
logInfo("rules.IB","Brama garaĹźowa zostaĹa otwarta.")
InfoToRead.sendCommand("Brama garaĹźowa zostaĹa otwarta.")
} else {
logInfo("rules.IB","Brama garaĹźowa zostaĹa otwarta w trybie czuwania alarmu!")
InfoToRead.sendCommand("Brama garaĹźowa zostaĹa otwarta w trybie czuwania alarmu!")
}
CCTV_CamFront_Pos2.sendCommand(ON)
logInfo("KWI.debug.rules","R_DEBUG: tRBG 6 (" + tRBG + ")")
tRBG.reschedule(now.plusSeconds(4))
logInfo("KWI.debug.rules","R_DEBUG: tRBG 7 (" + tRBG + ")")
}
case 2 : {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 8 (" + tRBG + ")")
if(PARTITION_PW_Piwnica_ARMED.state == OFF) {
sendTelegramPhoto("Karol", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=xxxxx", "Brama garaĹźowa zostaĹa otwarta. - ZdjÄcie nr 1 i..." )
sendTelegramPhoto("Ewelina", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=xxxxx", "Brama garaĹźowa zostaĹa otwarta. - ZdjÄcie nr 1 i..." )
} else {
sendTelegramPhoto("Karol", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=xxxxx", "Brama garaĹźowa zostaĹa otwarta w trybie czuwania alarmu. - ZdjÄcie nr 1 i..." )
sendTelegramPhoto("Ewelina", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=xxxxx", "Brama garaĹźowa zostaĹa otwarta w trybie czuwania alarmu. - ZdjÄcie nr 1 i..." )
}
logInfo("KWI.debug.rules","R_DEBUG: tRBG 9 (" + tRBG + ")")
tRBG.reschedule(now.plusSeconds(2))
logInfo("KWI.debug.rules","R_DEBUG: tRBG 10 (" + tRBG + ")")
}
case 3 : {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 11 (" + tRBG + ")")
CCTV_CamFront_Pos1.sendCommand(ON)
logInfo("KWI.debug.rules","R_DEBUG: tRBG 12 (" + tRBG + ")")
tRBG.reschedule(now.plusSeconds(3))
logInfo("KWI.debug.rules","R_DEBUG: tRBG 13 (" + tRBG + ")")
}
case 4 : {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 14 (" + tRBG + ")")
sendTelegramPhoto("Karol", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=xxxxx", "...zdjÄcie nr 2." )
sendTelegramPhoto("Ewelina", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=xxxxx", "...zdjÄcie nr 2." )
logInfo("KWI.debug.rules","R_DEBUG: tRBG 15 (" + tRBG + ")")
tRBG.reschedule(now.plusSeconds(2))
logInfo("KWI.debug.rules","R_DEBUG: tRBG 16 (" + tRBG + ")")
}
case 5 : {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 17 (" + tRBG + ")")
CCTV_CamFront_Pos5.sendCommand(ON)
logInfo("KWI.debug.rules","R_DEBUG: tRBG 18 (" + tRBG + ")")
tRBG.reschedule(now.plusSeconds(1))
logInfo("KWI.debug.rules","R_DEBUG: tRBG 19 (" + tRBG + ")")
}
default: {
logInfo("KWI.debug.rules","R_DEBUG: tRBG 20 (" + tRBG + ")")
tRBG = null
logInfo("KWI.debug.rules","R_DEBUG: tRBG 21 (" + tRBG + ")")
}
}
])
}
end
rule "Gate Closing"
when
Item Stan_bramy_garazowej changed to ON
then
logInfo("KWI.debug.rules","REGRUN: Ruch bramy garaĹźowej - ZamkniÄta")
logInfo("KWI.debug.rules","R_DEBUG: tRBG 22 (" + tRBG + ")")
tRBG?.cancel
logInfo("KWI.debug.rules","R_DEBUG: tRBG 23 (" + tRBG + ")")
Stan_bramy_garazowej_N.sendCommand(OFF)
Brama_garazowa_LOG.postUpdate(OFF)
if(PARTITION_PW_Piwnica_ARMED.state == OFF) {
logInfo("rules.IB","Brama garaĹźowa zostaĹa zamkniÄta.")
InfoToRead.sendCommand("Brama garaĹźowa zostaĹa zamkniÄta.")
} else {
logInfo("rules.IB","Brama garaĹźowa zostaĹa zamkniÄta w trybie czuwania alarmu.")
InfoToRead.sendCommand("Brama garaĹźowa zostaĹa zamkniÄta w trybie czuwania alarmu.")
}
SendNotification_Triggr.sendCommand(ON)
logInfo("KWI.debug.rules","R_DEBUG: tRBG 24 (" + tRBG + ")")
end
rule "Gate Guard - Opening"
when
Item Stan_bramy_garazowej changed to OFF
then
if(tSOBG === null) {
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 1 (" + nSOBG + ") (" + tSOBG + ")")
logInfo("KWI.debug.rules","REGRUN: StraĹźnik otwartej bramy garaĹźowej")
nSOBG = 0
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 2 (" + nSOBG + ") (" + tSOBG + ")")
lBramaGarazowaTOpened = now
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 3 (" + nSOBG + ") (" + tSOBG + ")")
tSOBG = createTimer(now.plusMinutes(20), [|
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 4 (" + nSOBG + ") (" + tSOBG + ")")
nSOBG = nSOBG + 1
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 5 (" + nSOBG + ") (" + tSOBG + ")")
switch (nSOBG.intValue) {
case 1 : {
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 6 (" + nSOBG + ") (" + tSOBG + ")")
lBramaGarazowaTPassed = Math::round(( now.millis - lBramaGarazowaTOpened.millis ) / 60000).intValue
logInfo("rules.IB","Gate remain open for " + lBramaGarazowaTPassed.intValue + " minutes!")
InfoToRead.sendCommand("Gate remain open for " + lBramaGarazowaTPassed.intValue + " minutes!")
Read_Trigger.sendCommand(ON)
CCTV_CamFront_Pos1.sendCommand(ON)
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 7 (" + nSOBG + ") (" + tSOBG + ")")
tSOBG.reschedule(now.plusSeconds(6))
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 8 (" + nSOBG + ") (" + tSOBG + ")")
}
case 2 : {
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 9 (" + nSOBG + ") (" + tSOBG + ")")
sendTelegramPhoto("Karol", "http://192.168.1.100/tmpfs/snap.jpg?usr=admin&pwd=XXXXX", "Gate remain open for " + lBramaGarazowaTPassed.intValue + " minutes!" )
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 10 (" + nSOBG + ") (" + tSOBG + ")")
tSOBG.reschedule(now.plusSeconds(2))
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 11 (" + nSOBG + ") (" + tSOBG + ")")
}
case 3 : {
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 12 (" + nSOBG + ") (" + tSOBG + ")")
CCTV_CamFront_Pos5.sendCommand(ON)
nSOBG = 0
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 13 (" + nSOBG + ") (" + tSOBG + ")")
tSOBG.reschedule(now.plusMinutes(20))
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 14 (" + nSOBG + ") (" + tSOBG + ")")
}
}
])
}
end
rule "Gate Guard - Closing"
when
Item Stan_bramy_garazowej changed to ON
then
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 15 (" + nSOBG + ") (" + tSOBG + ")")
logInfo("rules.IB","Guard: Gate closed.")
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 16 (" + nSOBG + ") (" + tSOBG + ")")
tSOBG.cancel
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 17 (" + nSOBG + ") (" + tSOBG + ")")
lBramaGarazowaTOpened = null
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 19 (" + nSOBG + ") (" + tSOBG + ")")
tSOBG = null
logInfo("KWI.debug.rules","R_DEBUG: tSOBG 19 (" + nSOBG + ") (" + tSOBG + ")")
end
Question is, that should I cancel timer from âOpeningâ in âClosingâ scenarioâŚ
Letâs asume that Gate Guard is running in endles loop and monitor gate status and opening time. Next gate closes and trigger timer cancelation in âGate Guard - Openingâ rule. Lets assume that this rule was somewhere in the middle, executing lines of code, for example reading via TTS gate status info, so:
a. waiting on timer (in one of caseâs),
b. or executing lines just before reschedulig it.
What will happen if we cancel that timer then:
a. Timer is canceled and rule is ended, or some of inside lines of code will be yet executed?
b. Rest of lines (to another reschedule?/case?) will be executed?
So finally⌠Should I or not and when:
a. cancel timer (?.cancel/.cancel/.cancel()),
b. set handle to ânullâ?
c. how should I exit neverending loop in âGate Guardâ?
Sory if those are stupid questions. I have the impression that I am wandering around. ;-/