I posted the same code before, though with a different question… this time I wonder if the rules are actually multi-entrant.
Why does this code:
timerLockEmailLocus_1 and blnEmailLockLocus_1 are properly defined outside the rule
// if within 400 metres of Locus_1
if (DistanceFromLocus_1.state < 0.400) {
logInfo("Geo.3.3", "DistanceFromLocus_1....: {}", DistanceFromLocus_1.state)
// if we haven't sent an email yet
if (blnEmailLockLocus_1 == false) {
logInfo("Geo.3.4", "Send email at Locus_1")
sendMail(emailToMax, "Max is 20 minutes away", "Max is roughly 20 minutes away")
blnEmailLockLocus_1 = true
logInfo("Geo.3.5", "set blnEmailLockLocus_1 to true (={})", blnEmailLockLocus_1)
// start timer to reset blnEmailLockLocus_1 to false in 120 seconds
timerLockEmailLocus_1 = createTimer(now.plusSeconds(120), [|
blnEmailLockLocus_1 = false
logInfo("Geo.3.6", "set blnEmailLockLocus_1 to false (={}) in 120s timer", blnEmailLockLocus_1)
timerLockEmailLocus_1 = null
])
}
}
produce this result:
2018-11-21 06:05:30.823 [INFO ] [g.openhab.model.script.Geo.3.3] - DistanceFromLocus_1....: 0.199
2018-11-21 06:05:31.870 [INFO ] [g.openhab.model.script.Geo.3.4] - Send email (at Locus_1)
2018-11-21 06:05:37.606 [INFO ] [g.openhab.model.script.Geo.3.3] - DistanceFromLocus_1....: 0.199
2018-11-21 06:05:37.616 [INFO ] [g.openhab.model.script.Geo.3.4] - Send email (at Locus_1)
2018-11-21 06:05:43.888 [INFO ] [g.openhab.model.script.Geo.3.3] - DistanceFromLocus_1....: 0.018
2018-11-21 06:05:43.898 [INFO ] [g.openhab.model.script.Geo.3.4] - Send email (at Locus_1)
2018-11-21 06:05:47.258 [INFO ] [g.openhab.model.script.Geo.3.3] - DistanceFromLocus_1....: 0.018
2018-11-21 06:05:47.268 [INFO ] [g.openhab.model.script.Geo.3.4] - Send email (at Locus_1)
2018-11-21 06:05:49.275 [INFO ] [g.openhab.model.script.Geo.3.5] - set blnEmailLockLocus_1 to true (=true)
2018-11-21 06:05:50.851 [INFO ] [g.openhab.model.script.Geo.3.5] - set blnEmailLockLocus_1 to true (=true)
2018-11-21 06:05:56.433 [INFO ] [g.openhab.model.script.Geo.3.5] - set blnEmailLockLocus_1 to true (=true)
2018-11-21 06:05:57.561 [INFO ] [g.openhab.model.script.Geo.3.3] - DistanceFromLocus_1....: 0.215
2018-11-21 06:06:00.192 [INFO ] [g.openhab.model.script.Geo.3.5] - set blnEmailLockLocus_1 to true (=true)
2018-11-21 06:06:04.486 [INFO ] [g.openhab.model.script.Geo.3.3] - DistanceFromLocus_1....: 0.396
2018-11-21 06:07:52.817 [INFO ] [g.openhab.model.script.Geo.3.6] - set blnEmailLockLocus_1 to false (=false)
2018-11-21 06:07:53.260 [INFO ] [g.openhab.model.script.Geo.3.6] - set blnEmailLockLocus_1 to false (=false)
2018-11-21 06:07:56.444 [INFO ] [g.openhab.model.script.Geo.3.6] - set blnEmailLockLocus_1 to false (=false)
2018-11-21 06:08:00.202 [INFO ] [g.openhab.model.script.Geo.3.6] - set blnEmailLockLocus_1 to false (=false)
It looks to me that the rule gets hit and before the lock is set to true, it is triggered a few more times… and then the rest of the rule (see log 3.5 and 3.6) kick in. Also indicating the timer is set multiple times (4 times in this example).
What do I need to do to have this code set the email lock after the first time I am in the <400m radius?
What I have done is moving the email lock = true before the sending of the email; however, I can test and report the result only the next morning…
If this works, then the rule is entered in at every GPS event, is then held up by the sending of the email, and once that’s sent, it continues with setting the lock to true (As it currently does), and then finishes the (four) timers 120 seconds later. – It sort of seems to work like that!?