Runin() returns without delay

Hi!

I am new to the Smartthings platform and is now trying out some simple stuff. Wanted to write a program that at button press sends a notification with a certain delay. For this I am using the runIn() function. However when I capture the button press and call the runIn() with a delay, it instantly calls my function instead of delaying. It does not seem to matter what delay I use, it always returns instantly. What have I missed? Thanks!

def eventHandler(evt) {
log.debug “Notify got evt ${evt}”

//call with 5 min delay
runIn(5 * 60, sendMessage(evt))

}

private sendMessage(evt) {
String msg = messageText

if (!messageText) {
	msg = defaultText(evt)
}
log.debug "sendMessage called '$msg'"

//sendPush(msg)

}

Log:
21:36:56: debug sendMessage called ‘{{ triggerEvent.descriptionText }}’
21:36:56: debug Notify got evt physicalgraph.app.EventWrapper@1b9c1ea4

Ok, solved it. I get this behavior because of the sendMessage(Evt) in runIn call. It cannot pass an event, and I should only use the name of the function: runIn(5 * 60, sendMessage) for it to work. Confusing though that the sendMessage call was done.

Might I politely suggest you’ve overthought that one? Just as 5 * 60 gets evaluated and becomes 300, sendMessage(evt) gets evaluated and calls sendMessage.

1 Like

Hi!

True! However I expected that the whole expression would fail, since the second argument to runIn() is faulty. I thought the evaluation of that would generate an exception, which would have been helpful to find the fault. But clearly that is not how groovy works :slight_smile:

You can pass information via runIn. You have to do it like this:

runIn(delayTime, methodCalled, [data:"dataToPass"]

Replace dealyTime with the dealy you want (in integer)
Replace methodCalled with the function you want to run
Replace dataToPass with the data you want to pass but keep the brackets and the data:

You then use your called method like this:

def methodCalled(dataToPass){ }

That should work without a problem.