How to reset timer if state changes?

I have a routine that locks a door if the door is closed but remains unlocked for 15 minutes.

Back when I had webcore, I had a piston that did the same thing, but if it was waiting on the timer and, say, the door opened, it would cancel the timer and start it over again.

With the new routine, the timer just keeps ticking and when the 15 minutes is up and the door is closed, it locks it, even if I just opened and closed it a minute before.

How can I get it to lock the door only if it has stayed closed for the fill 15 minutes like webcore used to do?

Here is how I do it:

As you can see, mine is set at 2 minutes instead of 15, but the concept is the same. If the front door lock remains unlocked for 2 minutes and the front door contact sensor remains closed for 2 minutes, then lock the front door. Opening and closing the door at any point restarts the 2 minute timer for the contact sensor.

I also have a virtual switch as a precondition, which allows me to pause the auto-lock for times when I want it to stay unlocked.

Hm. Ok, I will give that a try. I confess I’m not entirely clear on when to use preconditions. I guess I was using them incorrectly before. Also, how do I create a virtual switch? That sounds like a handy thing to have.

You can create a Virtual Switch in the SmartThings app by clicking Menu, then Labs, then Virtual Switch

But I prefer to use @TAustin’s “vEdge Creator: a virtual device generator for end users”, it is much more robust and useful. You can learn more about it here:

Very cool. Thanks. I’ll stick with the Samsung labs stuff for now until I dream up something that needs the fancy stuff. My needs are pretty simple at this point.

Is there a tutorial on writing routines that might cover topics like what preconditions are for and how to use them? I’m still unclear on that.

Here is an good explanation of what preconditions are: