Lua Code problem

Moderator: leecollings

Post Reply
ironrider
Posts: 11
Joined: Saturday 13 February 2016 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua Code problem

Post by ironrider »

Hi,

i have a very simple Lua Code but it wont run :

Code: Select all

commandArray = {}

swasserverbrauch = tonumber(uservariables['wasserverbrauch'])

if (devicechanged['Ventilator'] == 'On') then 

   swasserverbrauch = ( swasserverbrauch + 1 )

   commandArray['Variable:wasserverbrauch'] = tostring(swasserverbrauch)

  

   commandArray['OpenURL']='http://192.168.178.56:8080/json.htm?type=command&param=udevice&idx=118&svalue='..swasserverbrauch..''

end

return commandArray
I always get:

" Error executing script command (/home/pi/domoticz/scripts/lua/script_device_wasserverbrauch.lua). returned: 512
2017-09-02 18:27:47.238 Error: Error executing script command (/home/pi/domoticz/scripts/lua/script_device_wasserverbrauch.lua). returned: 512
2017-09-02 18:28:27.656 Error: Error executing script command (/home/pi/domoticz/scripts/lua/script_device_wasserverbrauch.lua). returned: 512
2017-09-02 19:14:27.871 Error: Error executing script command (/home/pi/domoticz/scripts/lua/script_device_wasserverbrauch.lua). returned: 512
2017-09-02 19:14:35.266 Error: Error executing script command (/home/pi/domoticz/scripts/lua/script_device_wasserverbrauch.lua). returned: 512

Can someone please help me ?
Thanks
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Lua Code problem

Post by zicht »

You could try using tostring(wasservebrauch) for openurl as you add an integer to a sting what does not
work

Second do you have password security enabled? Then you should add password string ( base64)

Hope it points you in the right direction
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Amsterdam020
Posts: 55
Joined: Saturday 05 March 2016 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5629
Contact:

Re: Lua Code problem

Post by Amsterdam020 »

Hi,

I try to get my first lua script to work but it fails. Can somebody give a hint how to get it working?

Code: Select all

os.execute('curl -s -H "Accept: application/json" -X PUT --data \'{"on":true, "sat":'254', "bri":'69',"hue":'0'}\'http://192.168.1.xx/api/my_api_key_here/lights/5/state')
2017-09-09 23:08:04.198 Error: Error executing script command (/home/pi/domoticz/scripts/lua/hue_light5.lua). returned: 512

I do not use a password and i believe there is also no error in the url as is mentioned in the soluation menetioned earlier.

I am grateful for your answers!
Rp3, youlesss, rfxcom, philips hue, dsb1820
Amsterdam020
Posts: 55
Joined: Saturday 05 March 2016 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5629
Contact:

Re: Lua Code problem

Post by Amsterdam020 »

Still stuggeling with my first lua script

On Action url: script:///lua/hue_light5.lua
2017-09-10 08:51:31.937 User: Admin initiated a switch command (670/huedummy/On)
2017-09-10 08:51:31.939 Error: SQLHelper: Error script not found '/lua/hue_light5.lua'
2017-09-10 08:51:31.946 (dummyhue) Lighting 1 (huedummy)

Off action url script://lua/hue_light5.lua (note same file but with only two slashes)
2017-09-10 08:51:33.878 User: Admin initiated a switch command (670/huedummy/Off)
2017-09-10 08:51:33.887 (dummyhue) Lighting 1 (huedummy)
2017-09-10 08:51:34.117 Executing script: /home/pi/domoticz/scripts/lua/hue_light5.lua
2017-09-10 08:51:34.130 Error: Error executing script command (/home/pi/domoticz/scripts/lua/hue_light5.lua). returned: 512

So i believe dubble slash is right. Why do i get an error 512 code and how to solve this error?
Rp3, youlesss, rfxcom, philips hue, dsb1820
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Lua Code problem

Post by simonrg »

Amsterdam020 wrote: Sunday 10 September 2017 9:02 On Action url: script:///lua/hue_light5.lua
Off action url script://lua/hue_light5.lua (note same file but with only two slashes)
As you are running on a Raspberry Pi:
Then 3 slashes is giving an absolute path (the 3rd / slash being the root) and should really be used i.e. /home/pi/domoticz/scripts/lua/hue_light5.lua
Then 2 slashes is a relative path so ./lua/hue_light5.lua - the running path may change so you would be better to use the fully qualified path.

While this is a Lua script you have written it is not a Lua Script that is run by Domoticz, the On Action is a way in Domoticz to get a script run at the command line, the command line running is Bash, so it will expect a Bash script - which this isn't and it also hasn't been made executable hence the 512 error.

I suggest on the you create a Bash script,

Code: Select all

curl -s -H "Accept: application/json" -X PUT --data '{"on":true, "sat":'254', "bri":'69',"hue":'0'}'http://192.168.1.xx/api/my_api_key_here/lights/5/state'
in a Bash directory and make the script executable. First test the exact command on the command line as I am not sure your use of quotes will work as stated.

Code: Select all

cd ~
cd domoticz/scripts
mkdir bash
nano hue_light5.sh
chmod +x hue_light5.sh

On Action: ///home/pi/domoticz/scripts/bash/hue_light5.sh

You should also test your lua script by running it outside Domoticz, by running the lua interpreter (command lua) - you will find that your quotes probably need adjustment.

Code: Select all

os.execute('curl -s -H "Accept: application/json" -X PUT --data \'{"on":true, "sat":'254', "bri":'69',"hue":'0'}\'http://192.168.1.xx/api/my_api_key_here/lights/5/state')
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
Amsterdam020
Posts: 55
Joined: Saturday 05 March 2016 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5629
Contact:

Re: Lua Code problem

Post by Amsterdam020 »

Thank you Simonrg y for all your advice. I got it working now with your instruction and i learned a lot in the meantime.

btw, changed the quotes to the following.

Code: Select all

#!/bin/bash
curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":4,"hue":1}' http://192.168.1.xxx/api/my_key/lights/5/state
Rp3, youlesss, rfxcom, philips hue, dsb1820
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest