I'm getting a NoSuchElementException and can't quite tell why. The rule works fine if I omit trying to use a PB to avoid overlapping runs but when I add that in I see the error. Am I doing something wrong? Is there a better way to write this?
Rule settings and state
I think your problem is that you are entering a delay multiple times without canceling the first one. So, when you unlock the door, the condition is true that the door is closed...so the rule will immediately begin the 20 second delay. Then you open the door, triggering the rule again and the other delay keeps running. I think there's a way to do this without a wait.
Triggers would remain the same.
Then for the action:
Cancel Delayed Actions
If contact sensor is closed and Lock is Unlocked THEN
Delay actions by 20 Seconds (Cancelable)
If the contact sensor is reopened or the lock is locked, the rule will not execute the action because they are part of the trigger. And it will only cause the lock to lock if the door is closed and the lock is unlocked. So, this would also relock the door if you unlocked it but never opened it, which i assume you want as well.
If you are trying to prevent that from happening, use the EVENT door is closed. Then it wouldn't enter the delay until the door was closed after being unlocked. Otherwise, I think your wait for condition and the uncanceled delay is what is causing your problem, I'm pretty sure.
Ironically this works fine with multiple delays; it only fails when I try to add the private Boolean to avoid running more than once which doesn’t make a lot of sense to me. You can use virtual devices to reproduce and if you remove the outer
if and the two private Boolean commands, it works ok.
I originally had a rule very similar to what you drafted but changed to using a wait but I can’t recall the exact problem that caused me to switch. I’ll give it another try and see how it goes.
@johnwick this seems to work as intended, thanks for the tip!
FWIW, the error I originally mentioned seems to have come up before too... However, there are no errors in your solution so that works for me.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.