New on LUA

Help wanted!

Since my Vera proudly runs the LUUP release I begun to play around with LUA. I tried to rebuild a scene with LUA code but I didn’t found a piece of code for what I intended.

Here is what I want the scene to do:
On sunset a scene should start with
luup.call_action(“urn:upnp-org:serviceId:WindowCovering1”,“Down”,{ },32)
Then wait 20 seconds
luup.call_action(“urn:upnp-org:serviceId:WindowCovering1”,“Down”,{ },33)

Question: How can I define the delay?

A second question I have is how can I build a scene to toggle a device on and off x times? I tried something like:
do
local var, limit, step = 1, 4, 1
if not (var and limit and step) then error() end
while (step > 0 and var <= limit) or (step <= 0 and var >= limit) do
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },13)
wait
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },13)
block
var = var + step
end
end

That didn’t work.

Any ideas?

Really no one?

Yes, I’d like to know also…a system call to “sleep” perhaps?

See this post for some ideas for sleeping. :slight_smile:

http://forum.micasaverde.com/index.php?topic=2058.0

Excellent!
The luup.call_timer works perfectly!

Thanks for the tip!

Thanks!

For those who are looking for that piece of code:

function LightOn()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },13)
end
luup.call_timer(“LightOn”, 1 , “10”,“”,“”)

This switches device 13 after 10 seconds on.

huwu,

Can this code be put into a ‘LUUP scene’, or does it need to be within a ‘device’? And can variables be declared at the top and will the ‘timer’ callback be able to ‘see’ them?

Thanks,
Brian

Brian,
yes. Copy and paste it to scenes. You open that table by pushing the button “Luup scene”. Don’t forget to push “Update” at the page’s button and save all this.
Huwu