Page 1 of 1

Error executing script command lua returned: 512

Posted: Sunday 12 July 2015 15:40
by romeok01
I have problem with script in lua.

I write simple script in lua:

Code: Select all

commandArray = {}
 if (devicechanged['LED Zielona'] == 'On')  then
    commandArray['LED Czerwona']='On'
 end
 return commandArray
Name this file is: led.lua and i move this in folder: /home/pi/domoticz/scripts/lua

This is switch in my Domoticz
Image

I copy link for my script lua.led, to switch script, is: script://home/pi/domoticz/scripts/lua/led.lua

Image

When i turn on my LED Zielona sript led.lua not working :(

I have Domoticz v. 2.2653.
In log i have error:
Error executing script command (/home/pi/domoticz/scripts/lua/led.lua). returned: 512

When i run my script in console (sudo lua led.lua) i have error:
lua: led.lua:2: attempt to index global 'devicechanged' (a nil value)
stack traceback:
led.lua:2: in main chunk
[C]: in ?
Please help me.

Re: Error executing script command lua returned: 512

Posted: Sunday 12 July 2015 16:03
by roblom
Rename the la script to "script_device_led.lua".
Remove the link on the switch. Then it should work.
Lua knows the state of the switches so you don't have to let the switch start the script. The lua script executes when the switch is correctly programmed.

Re: Error executing script command lua returned: 512

Posted: Sunday 12 July 2015 16:19
by romeok01
Thank You Very Much roblom :)

Now its work :)

Re: Error executing script command lua returned: 512

Posted: Thursday 31 March 2016 17:10
by elgarne
I'm in the same situation (error 512) and this is a workaround not the solution to this problem.
As stated in other threads, each script_device* script is executed each time a device state is changed. Thus, the more script_device* scripts you have, the most time it takes. Hence having a non script_device* script is interesting since it is executed only when required.

Re: Error executing script command lua returned: 512

Posted: Thursday 31 March 2016 17:21
by jvdz
Not sure if there is a question in your post, but I am using one script_device_main.lua script which is the only script fired when a device changes. It has a bunch of if's which will run the appropriate LUA script when the if is true by using the dofile() command.
This keeps the number of ran script to a minimum and it did speed up the whole process.

Jos

Re: Error executing script command lua returned: 512

Posted: Thursday 31 March 2016 17:51
by elgarne
Yes, I understand but it is still a workaround.
domoticz is supposed to execute a script from a switch's "on" or "off" action, if the right path to the script is provided. Nevertheless, it returns a 512 error in such a case and I'd like to know how to fix this issue.

Re: Error executing script command lua returned: 512

Posted: Thursday 31 March 2016 18:15
by jvdz
So, why are you getting the 512? what are the error details?

Jos

Re: Error executing script command lua returned: 512

Posted: Thursday 31 March 2016 18:20
by elgarne
If the file is renamed to script_device_CheckPresence.lua and has an

Code: Select all

if devicechanged['mydevice']
statement, it works perfectly. But if executed through the on action of a dummy switch, then it generates the following error:

Code: Select all

Error: Error executing script command (/home/pi/domoticz/scripts/lua/CheckPresence.lua). returned: 512
I googled for this error and all the threads I found about it have a similar workaround than the one you suggested. Some suggest to make the file executable etc but no solution seems to fix the issue.

Re: Error executing script command lua returned: 512

Posted: Thursday 31 March 2016 18:25
by jvdz
That makes sense as these extra Tables are not available when the script is manually shelled or through the On/Off action of a switch.
They are only available when you use the standard lua event system by using script_trigger_name.lua and stored in domoticz\scripts\lua.

Jos