Delay Command

Here’s what I’m trying to do…I would like a motion event to run a command that I’ve written (the command works fine) at a specified period of time after the motion event occurs. Basically I want the app to make sure a door is not opened during the “window” of time that I set and I have the check working properly, but currently it checks for the previous time the door opened immediately after the motion event, which isn’t helpful. I want it to wait for at least one minute to see if the door opens before triggering the push/text alert. I have not been able to figure this out on my own and I’m pretty new to this language (all languages really).

So if anyone could help with some syntax to add that will set off a command at an interval that I determine after a motion event occurs, that would be great. Thanks!

If what you want to do is “do the check one minute after a motion event is detected”, try something like

def myMotionEventHandler( evt ) {
   // 60 seconds
   runIn( 60, myCheck )

instead of

def myMotionEventHandler( evt ) {

If there are multiple motion events within the window, and you only want the last motion event to trigger the check, you’ll have to

unschedule( myCheck )

before the runIn command. (In my experience, later runIn for a function gets dropped if there is already one pending/running for the function. Don’t know if that’s by design or by accident).

@apostlepd can you post the code for checking prior to the event? I’ve been trying to make that happen! but for accelerometer for both events. Thanks.