runIn(), runOnce(), pause(msec) which one to use in this example

I’ll try and shed some light on this.

runIn() schedules a new execution of this SmartApp, calling the method specified in the number of seconds specified. With values less than 60 seconds, YMMV.

pause() simply suspends the current thread, for the number of milliseconds specified (not to exceed 15 seconds).

pause() is unsupported and should not be used. It will be removed in a future release. I considered adding it to the documentation with a big warning to not use it - but decided against documenting it at all.

Regarding the timeout you experienced - because any SmartThings code (SmartApps or Device Type Handlers) execute within the SmartThings ecosystem along with other SmartApps or Device Type Handlers, there must be limits in place to the resources they use, so they do not negatively impact any other SmartThings code. That’s why they are only allowed to execute for a certain amount of time before being limited (we have work planned to document this).

Bottom line - use runIn(), not pause(). pause() will be removed soon. If you’re wondering exactly why pause() is unsupported (aside from the discussion of the execution model above), I am working to verify the specifics around this specific case and will communicate it soon (I don’t want to communicate possibly inaccurate information). I know I’m the kind of person who needs to know the why behind things :smile:

I hope my long-winded explanation doesn’t cause more confusion, I just wanted to shed some more light on this :smile:

1 Like