How to add delays to LUA Script?

Hopefully this is a really simple one, I want to be able to control delays in lua code rather than GUI driven as these need to be conditional which I can only do by using code.

IE this is my LUA code for turning on a device,
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 11

How can I add a delay to this task in a LUUP script?

Thanks
Stu

For short delays you could use luup.sleep(900) adjusting the numbers for the period.

*Caveat. In my system I found that using luup.sleep and longer delay’s would cause a Vera restart.

JOD.

Thanks for the response JOD however I managed to figure out my nightlight scene by looking at the examples page here http://wiki.micasaverde.com/index.php/Luup_Scenes_Events#Lighting_and_Switch_Actions

my new luup code is as follows - Quick Tip use “if not (luup.is_night()) then” to do testing in daytime.

EDIT - This works however if the motion sensor is triggered again whilst the light is still on before the 3 minute timer, this is not reset, i will be investigating soon but for now im just going to increase delay duration so it stays on for 6 minutes as this should solve most bedtime bathroom stops!!

[code]skip = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,34)
function lightoffdelay51()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 51)
end

function lightoffdelay52()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 52)
end

if(skip==“1”)then
return false
else

light51 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,51)
light52 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,52)

if (luup.is_night()) then

if (light51 =="0") then
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 51)
luup.call_delay('lightoffdelay51', 180)
     
end                  

         if (light52 =="0") then
            luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 52)
	luup.call_delay('lightoffdelay52', 180)
                             
         end

return true
end

return false
end[/code]

Ok I have finally achieved what i wanted to do with the code I posted here.

[quote=“JOD, post:2, topic:171240”]For short delays you could use luup.sleep(900) adjusting the numbers for the period.

*Caveat. In my system I found that using luup.sleep and longer delay’s would cause a Vera restart.

JOD.[/quote]

Is this seconds or milliseconds?

The xxx value for luup.sleep( xxx ) is in milliseconds. If you put delays longer than a second or so into a scene, Vera will assume it has stalled and restart.