call_delay is driving me crazy

Hi

I’ve read the prior posts on call_delay but I guess I’m being dense and just don’t get it. All I want to do is for my code to delay execution for 3 seconds and then to continue on with the next statement. What I have is a schlage lock. I have an event when the pin code is entered. The first thing I want to do is wait for 3 seconds to give the user a chance to unlock the door now that they’ve entered the pin. Then my code will read the status of the lock and if the lock is unlocked and it is night, then it will turn on an interior light.

All of this is working fine except I am driving myself crazy trying to get call_delay to work and halt execution of the lua code for 3 seconds. Any help with the correct syntax for call delay (or if that is not the right way to perform this kind of delay) would be greatly appreciated

Jay

something like this:

function afterdelay (xx)
  luup.log ("called after some time with:"..xx)
end

function start (....)
  .....
  local params = "some string data..."
  call_delay ("afterdelay", 3, params)
  luup.log ("continues immediately")
end

note that the first parameter to [tt]call_delay()[/tt] must be a string with the name of the function to call after the delay. the [tt]call_delay()[/tt] function itself returns immediately.

Thanks javier

It just made sense to me that there would be an “inline” delay rather than having to go through a function call. I could see code that required a bunch of different delays getting very difficult to follow but I guess that is just a limitation of lua.

Thanks again

Jay

Don’t think of call_delay() to mean “call for a delay”, it means “call function x after a delay”.

Thanks for everyone’s help. This is still driving me crazy. Here is my very basic test code for the event when a pin code is entered on the schlage lock. All it should do is to initiate a lighting scene that turns on a light for 10 seconds after a 3 second delay. I know the call to initiate the lighting scene works on it’s own. It just doesn’t work when I put it in the function. Any help would be greatly appreciated. The bruise from banging my head against the wall is getting very painful :slight_smile:

function afterdelay (junk)

luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{ SceneNum=“9” }, 0)

end

call_delay(afterdelay, 3, “x”)

the [tt]call_delay()[/tt] function takes a string with the name of the function, not the function itself.

change

call_delay(afterdelay, 3, "x")

with

call_delay("afterdelay", 3, "x")

Doh!!

Thanks!! I’ll give this a try back in the office on Monday.

Jay

Is there a max number of seconds that can be passed to call_delay? I tried to pass the following to call_delay:

startDelay = ((tonumber(x) * 60)
luup.call_delay(“someFunction”,startDelay, “”)

Where x = 20, it didn’t seem to work, but when I ran it with x =1, it worked fine. And when I ran it as a call_timer function with “20m”, it worked fine.

there’s no intentional limit… but if Luup gets restarted for any reason, the timer isn’t preserved. remember that every time you hit ‘save’, Luup is restarted.

in most cases, the code that calls [tt]call_delay()[/tt] is run again at startup, so the call is delayed again.