Help scripting lua/luup scene

Vera allows me the ability to turn “on” the motor of my cat feeder and then 15 seconds later turn it “off”.

The scene options only allow a predetermined number of seconds in the drop down box, i cant specify my own… (i.e. 10, 15, 30).

I would like to run the feeder motor for 20 seconds, this is not an option in vera. I am pretty sure this would be very easy to script in lua/luup, I just don’t know where to start. Can anyone point me in the right direction?

  1. switch it on

  2. Wait 20 s

  3. Switch it off

  4. and 3. should be trivial (http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_call_action).
    But you should check whether your jobs were successful if the life of your pets depends on it … But as far as I know the Luup job handling extensions are not implemented yet - or undocumented … (http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#Job_Handling).

Some ideas for 2. (untested):

Variant 1 (may block Vera for 20 s; may be removed by optimizers …):

nowplus20s = os.time() + 20
while os.time() < nowplus20s do end

Variant 2 (may work, but see http://forum.micasaverde.com/index.php?topic=2024.0):

os.execute(‘sleep 20’)

Variant 3:

Use an absolute Luup timer (http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_call_timer)

Thanks for the ideas, looks like ill be reading some of the wiki. I’ll let you know if I get any of this working :slight_smile:

I suspect it’ll be less taxing on Vera if you go with variant 3. You can get the code snippet/examples for the timer out of either TedStriker’s Ping Plugin, or the Weather Plugin.

You can also grab the Parameter logic (for a 20, 21, 25 second timer via config) from Ted’s codebase or from 325xi’s Sprinker controller.

Variant 1 will likely put Vera into High CPU, with lots of low level System CPU calls. Variant 1&2 will block, which is also undesirable.