LUA sequence execution order

I’ve got a scene written to trigger my door bell and open and close shades window shades when my motion control (MC) is tripped.

The flow should be -

MC tripped - via Vera Scene
ring door bell - via luup.call_action
open shades - via os.execute
wait 30 sec - via a function called sleep

function sleep(n) – seconds
local t0 = clock()
while clock() - t0 <= n do end

close shades via os.execute

that’s the order that the LUA code is written

What I get is

MC tripped
Open shades
wait 30 sec
ring bell
close shades

Any idea on how I can get this code to execute in the proper order??


Your problem is your sleep function, which is blocking the execution of anything else. The wonder is that Vera didn’t restart during this.

You need to refactor the delay function. One way to do this is to use the built-in luup.call_delay() function.

You can find a recent example of how to do this here:

thanks akbooer.

I got rid of the “sleep” and added the luup.call_delay but couldn’t get it to work. I eventually found out that you cannot pass two variables with the delay function (besides the amount of time to delay). I needed to pass two variables.

There are 4 discreet actions I needed to do, each with two variables and each action repeats with one different variable value after a specified time. In the interest of keeping the code short I wanted to pass both variables to the same function. I guess no can do.
I created 4 functions with 4 variables defined internal to each action. I just pass one variable with the delay command.

It works, but it’s not efficient.

Any idea where the best “primer” for LUA might reside on the web? I hate to keep asking for help with basic LUA things.

You can pass more than one variable, but you need to encode the variables to a single parameter first. Or to a serialized table. Here’s a link to a good discussion on this:,18679.msg154756.html#msg154756

© 2019 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy