Page 1 of 1
lua error 512
Posted: Wednesday 25 January 2017 16:04
by liderbug
OK, I give up. I need help. Google has been less than helpful. I have Dom running and now I want to create a LUA script that says: if (nighttime) continue else return. So I added "script://lua/night.lua" (using a cut down example) to just 1 line: print("this will end up in the domoticz log"). What I get in the log is:
2017-01-25 07:42:06.938 User: Admin initiated a switch command (1/Patio/On)
2017-01-25 07:42:06.939 OpenZWave: Domoticz has send a Switch command! NodeID: 5 (0x05)
2017-01-25 07:42:06.942 (OZW) Light/Switch (Patio)
2017-01-25 07:42:07.934 Executing script: /home/cal/domoticz/scripts/lua/night.lua
2017-01-25 07:42:07.962 Error: Error executing script command (/home/cal/domoticz/scripts/lua/night.lua). returned: 512
I can, from the command line run: lua night.lua and get: this will end up in the domoticz log
Re: lua error 512
Posted: Wednesday 25 January 2017 22:28
by Siewert308SW
try script:///lua/night.lua
see the three slashes
Re: lua error 512
Posted: Thursday 26 January 2017 3:35
by liderbug
I had tried the "/"x3 before. With "/ / /" my logs say I turned the light on but the "print" line in the lua script doesn't show up - no error, no message. If I use only 2 slashes I get: "Error executing script command (/home/cal/domoticz/scripts/night.lua). returned: 512" in the logs. The thing is that link to night.lua is correct. I can copy and (lua) paste and get the message I should receive in the log.
Question: Does the "print" line in a lua script 'work'? Does a lua script "require" something else? an #include?? a return commandArray? a return 0? Although I think I've tried all combinations.
Do you have a MIN lua script?
Thanks
Re: lua error 512
Posted: Thursday 26 January 2017 8:22
by Nautilus
There are example scripts under ../domoticz/scripts/lua. Also, if you add a script via the event system screen in web UI you get a basic template.
To my understanding the on/off triggers behind the switches are not primarily meant to be used with Lua scripts although they should of course work when used correctly. The event system is designed to trigger Lua scripts based e.g. on "devicechanged" events (I think python is another language possibility if Domoticz is compiled to support that) and when triggered in that way it can use these
special tables such as devicechanged, otherdevices, uservariables etc. Then if you want to trigger e.g. bash, php etc. you can do it via the on/off actions. At least this is how I've understood it. Although, as said, nothing wrong as such triggering also Lua from on/off action (just need to remember the limitation concerning e.g. the special tables). If you search the forum you'll find more posts about the issue, strange that google didn't return these...
viewtopic.php?t=7252
And yes, Lua requires "return commandArray" as you can see in the example scripts. If you still have problems I'd suggest to share the entire script here

Re: lua error 512
Posted: Thursday 26 January 2017 15:22
by liderbug
Well I have it working but I have to believe there is a code problem bucause:
Code: Select all
-- comment
print("this will end up in the domoticz log")
commandArray = {}
return commandArray
logs:
Executing script: /home/cal/domoticz/scripts/lua/night.lua
2017-01-26 06:49:58.883 Error: Error executing script command (/home/cal/domoticz/scripts/night.lua). returned: 512
and nothing is logged.
So, what I have working is:
Code: Select all
On Action: script://lua/night.php On
Off Action: script://lua/night.php Off
note 2 slashes not 3. It runs:
Code: Select all
#!/usr/bin/php
<?php
echo "Now is the time\n";
$OO = $argv[1];
exec ("/usr/bin/curl -s -i -m 5 -H 'Accept: application/json' 'http://sg53:8080/json.htm?type=command¶m=switchlight&idx=1&switchcmd=$OO'", $ret);
foreach ($ret as $r)
echo "R= $r\n";
and log contains:
2017-01-26 06:18:52.854 OpenZWave: Domoticz has send a Switch command! NodeID: 9 (0x09)
2017-01-26 06:18:52.856 (OZW) Light/Switch (FrontDoor)
2017-01-26 06:18:52.878 OpenZWave: Domoticz has send a Switch command! NodeID: 8 (0x08)
2017-01-26 06:18:52.879 (OZW) Light/Switch (Kitchen Door)
2017-01-26 06:18:53.900 Executing script: /home/cal/domoticz/scripts/lua/night.php
2017-01-26 06:18:54.442 User: Admin initiated a switch command (1/Patio/Off)
2017-01-26 06:18:54.444 OpenZWave: Domoticz has send a Switch command! NodeID: 5 (0x05)
2017-01-26 06:18:54.446 (OZW) Light/Switch (Patio)
which is exactly what I wanted to see - except where is "Now is the time\n" and the several $ret lines? I'm running: PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
Well now I can move on to the end game which is daytime= driveway motion=On, announce/bell. nighttime= floodOn, KitchendoorOn, FrontdoorOn. And my Cucs are 3mm high, tomatoes are 0.01mm high (itty-bitty little white stem sticking out of seed) so I can start the coding for my hydroponic greenhouse.
Thanks for the pointers - Av'a ber on me.
Re: lua error 512
Posted: Thursday 26 January 2017 21:28
by Nautilus
I don't think you can print / echo to Domoticz log form "external" scripts (which the on/off action scripts essentially are). I assume only those scripts (lua / python) that are executed by the event system can do that. Ok, maybe if you somehow specify to write them directly to your Domoticz log file (/var/log/domoticz.log?) - still doubt the "in memory" log in web UI would show those as well.
As for the lua file, if you insist getting rid of the error, check if you have given proper permissions (i.e. sudo chmod 755 file). Still, don't think anything will ever end up to Domoticz log when the script is triggered like this and you only have the "print('Some text')" -type of command there...

Re: lua error 512
Posted: Wednesday 01 February 2017 15:58
by liderbug
Still, don't think anything will ever end up to Domoticz log when the script is triggered like this and you only have the "print('Some text')" -type of command there..
Thing is this: script_time_demo.lua:print('this will end up in the domoticz log')
would lead one to believe that it just might put a message in to log....
Re: lua error 512
Posted: Wednesday 01 February 2017 17:14
by Nautilus
liderbug wrote:
Thing is this: script_time_demo.lua:print('this will end up in the domoticz log')
would lead one to believe that it just might put a message in to log....
Yes, you'll see it in the log as long as you trigger the script via the event system, which to my understanding uses the internal lua engine. When you have it as on/off command it is basically executed as a(ny other) command line script and thus does not have "access" to Domoticz log. What I mean is those example scripts are meant to show what you can do with the event system...
