We have moved at community.getvera.com

Author Topic: Lua code not running within scene  (Read 662 times)

Offline shaddow

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Lua code not running within scene
« on: July 21, 2018, 07:18:06 pm »
I am quite new to all this, so sorry if it is a basic error!  I have spent a few days looking and can not find a solution to my problem. :-[

I am using Vera Plus UI7 (1.7.4001) and AltUI (2.29.2418).

All I want to do is create a scene that is manually triggered and will run a simple LUA code and nothing else.

I can not get any code to work within a scene, it does work when I test the code outwith the scene. 

For an example of the issue I have used some code from the wiki pages which should turn on a device, wait 2 seconds, then turn off the device.  When I run the code in the 'LUA code test' it runs fine and performs as expected.  However when I copy that same code into the LUA code section within a new scene, and trigger the scene manually, it does not work.  What am I doing wrong??

Here is the code, identical to how I paste it into the 'LUA scene code' box withing the scene;

local device  = 34
-- Switch on device 34:
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device)
luup.call_delay( 'switch_off', 2) -- Call the switch off function after a delay of 2 seconds
function switch_off()
   luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device)

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Lua code not running within scene
« Reply #1 on: July 22, 2018, 03:11:24 am »
You should not use luup.call_delay() in scenes, but instead use the delayed action option when defining the scene itself.  You don't need Lua code for this at all.

Whether this is actually the root cause of your problem, I couldn't say.  Did you try the scene with only the switching on part, and no delay?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline shaddow

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Lua code not running within scene
« Reply #2 on: July 22, 2018, 06:20:29 pm »

It was a fundemental error.  I use the RFXtrx device to comunicate with Lightware devices.  I did not have the USB device plugged into my VERA as I am reconfiguring the system in a different location and I havent started on the Lightware devices yet.

As soon as I pluged the USB device back in to VERA all LUA code within scenes started to preform as I had expected them to.  Rookie error!

Now I can explore the power of LUA code!