Page 1 of 1
Lua script did not return a commandArray
Posted: Saturday 09 September 2017 10:59
by bigmak
SOLVED
What I have:
Raspberry Pi 2
Linux raspberrypi 4.9.24-v7+
GNU bash, version 4.3.30(1)-release
Node v6.0.0
Domoticz V3.8153
Xiaomi Humidifier
In directories on Raspberry Pi:
I did step-by-step from this topic
viewtopic.php?f=56&t=17498 about Xiaomi Humidifier.
All my commands work perfect
from command line in terminal. Humidifier works correctly without Domoticz.
In Domoticz:
I did Dummy switch (selector) with name 'Humidifier'.
I made 4 selector levels - off, Silent, Medium, High.
I left empty selector actions.
Am I right?
When I put Lua script in "Setup->More options->Events", I found error in log:
>Error: EventSystem: Lua script Humidifier did not return a commandArray
My code is:
Code: Select all
commandArray = {}
-- Humidifier
if devicechanged['Humidifier'] == 'Silent' then
os.execute ('screen -S humidifiertemp -d -m bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent')
end
if devicechanged['Humidifier'] == 'Medium' then
os.execute ('screen -S humidifiertemp -d -m bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on medium')
end
if devicechanged['Humidifier'] == 'High' then
os.execute ('screen -S humidifiertemp -d -m bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on high')
end
if devicechanged['Humidifier'] == 'Off' then
os.execute ('screen -S humidifiertemp -d -m bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 off')
end
return commandArray
All files were chmoded ($ chmod +x...).
Nothing work from Domoticz.
Everything work perfect from command line. Where is the mistake?
PS. I found that Lua changed to dzVents, but I don't know how to adapt Lua-code for dzVents.
Please, help me!
Thank you.
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 11:24
by lonebaggie
puts some print commands to debug before you test values
val = devicechanged['Humidifier']
print ("Humidifier Value is " .. val)
check logs
Suspect you may need to test on level values
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 11:35
by bigmak
lonebaggie wrote: ↑Saturday 09 September 2017 11:24
puts some print commands to debug before you test values
val = devicechanged['Humidifier']
print ("Humidifier Value is " .. val)
check logs
Suspect you may need to test on level values
Ok. I put this strings instead of my "os.execute" code.
Code: Select all
2017-09-09 12:29:58.876 dzVents: Humidifier Value is Medium
2017-09-09 12:29:58.878 (Humidifier) Light/Switch (Humidifier)
2017-09-09 12:30:00.611 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:5: attempt to concatenate global 'val' (a nil value)
2017-09-09 12:30:00.616 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:4: attempt to index global 'devicechanged' (a nil value)
2017-09-09 12:30:03.147 User: Admin initiated a switch command (30/Humidifier/Set Level)
2017-09-09 12:30:03.383 dzVents: Humidifier Value is High
2017-09-09 12:30:03.385 (Humidifier) Light/Switch (Humidifier)
2017-09-09 12:30:13.954 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:5: attempt to concatenate global 'val' (a nil value)
2017-09-09 12:30:14.077 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:5: attempt to concatenate global 'val' (a nil value)
2017-09-09 12:30:27.925 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:5: attempt to concatenate global 'val' (a nil value)
2017-09-09 12:30:28.047 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:5: attempt to concatenate global 'val' (a nil value)
2017-09-09 12:30:30.535 Error: EventSystem: in Humidifier: [string "commandArray = {}..."]:5: attempt to concatenate global 'val' (a nil value)
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 12:02
by jvdz
How did you implement this LUA script? When you used the internal editor, did you change the Event dropdown from All to Devices?
... else what did you name the script and where is it located?
Jos
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 12:16
by bigmak
jvdz wrote: ↑Saturday 09 September 2017 12:02
How did you implement this LUA script? When you used the internal editor, did you change the Event dropdown from All to Devices?
... else what did you name the script and where is it located?
Jos
I tried both ways:
1. I used internal editor and i changed from "All" to "Device". Checked many times.
and
2. I put script in ~/domoticz/scripts/lua/script_device_humidifier.lua
-rwxr-xr-x 1 pi pi 767 Sep 9 12:43 script_device_humidifier.lua
Even used both ways at the same time...
In file and in internal editor I used same code.
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 12:44
by jvandenbroek
It seems that dzVents log line is printed instead of Lua, which sometimes seem to occur for yet unknown reason (it's harmless). So the example/test script is working, it just tries to match on all device changes, which results in those nil value messages.
Try to add the full path to screen in os.execute, eg. /usr/bin/screen
Edit: But that wouldn't explain that it didn't return commandArray, sorry, that seems to be wrong. But if you don't get that message without the os.execute line, it seems that the script exits / disappears before completing, possible caused by screen. Could you try those lines just without using screen?
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 13:22
by bigmak
jvandenbroek wrote: ↑Saturday 09 September 2017 12:44
It seems that dzVents log line is printed instead of Lua, which sometimes seem to occur for yet unknown reason (it's harmless). So the example/test script is working, it just tries to match on all device changes, which results in those nil value messages.
Try to add the full path to screen in os.execute, eg. /usr/bin/screen
Edit: But that wouldn't explain that it didn't return commandArray, sorry, that seems to be wrong. But if you don't get that message without the os.execute line, it seems that the script exits / disappears before completing, possible caused by screen. Could you try those lines just without using screen?
Ok. What i did:
1. Kill script-file in /domoticz/scripts/lua/script_device_humidifier.lua
2. Insert code via internal editor with sub-menu "Device":
Code: Select all
commandArray = {}
-- Humidifier
if devicechanged['Humidifier'] == 'Off' then
os.execute ('bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 off')
end
if devicechanged['Humidifier'] == 'Silent' then
os.execute ('bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent')
end
if devicechanged['Humidifier'] == 'Medium' then
os.execute ('bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on medium')
end
if devicechanged['Humidifier'] == 'High' then
os.execute ('bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on high')
end
return commandArray
3. Restart Domoticz.
4. Press many times selectors from "off" to "Silent", etc.
Nothing. Nothing in error log, nothing changed with physical humidifier.
2017-09-09 14:17:06.009 User: Admin initiated a switch command (30/Humidifier/Set Level)
2017-09-09 14:17:07.551 (Humidifier) Light/Switch (Humidifier)
2017-09-09 14:17:42.671 User: Admin initiated a switch command (30/Humidifier/Set Level)
After rebooting I have just 2 errors:
2017-09-09 14:02:51.661 Error: Exception starting shared server: resolve: Host not found (authoritative)
2017-09-09 14:02:58.832 Error: EventSystem: in dzVents.lua: cannot open dzVents.lua: No such file or directory
I tried to add the full path to screen in os.execute, eg. /usr/bin/screen - nothing.
For example, those commands still work
perfect from command line:
>>>$ bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on medium
>>>$ /usr/bin/screen -S humidifiertemp -d -m bash ~/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent
Any ideas?
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 13:58
by jvandenbroek
What about /bin/bash? And the cannot open dzVents.lua error is suspicious, something seems wrong with your installation. Could try disabling dzVents under settings -> other, restart domoticz and see if at least that error message is gone?
Verstuurd vanaf mijn SM-N930F met Tapatalk
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 14:16
by bigmak
jvandenbroek wrote: ↑Saturday 09 September 2017 13:58
What about /bin/bash? And the cannot open dzVents.lua error is suspicious, something seems wrong with your installation. Could try disabling dzVents under settings -> other, restart domoticz and see if at least that error message is gone?
1. Disabling dzVents -> Just have 1 error:
2017-09-09 15:07:04.779 Error: Exception starting shared server: resolve: Host not found (authoritative)
I need to update dzVents?
I have
>>>$ ~/domoticz/scripts/dzVents
drwxr-xr-x 8 pi pi 4096 июл 16 11:05 .
drwxr-xr-x 8 pi pi 4096 сен 9 13:45 ..
drwxr-xr-x 2 pi pi 4096 июн 27 16:05 data
drwxr-xr-x 2 pi pi 4096 июл 27 13:05 documentation
-rw-r--r-- 1 pi pi 706 апр 16 16:05 dzVents_settings_example.lua
drwxr-xr-x 3 pi pi 4096 июл 27 13:05 examples
drwxr-xr-x 2 pi pi 4096 сен 8 21:57 generated_scripts
-rw-r--r-- 1 pi pi 227 июл 16 11:05 .gitignore
drwxr-xr-x 6 pi pi 4096 июл 27 18:05 runtime
drwxr-xr-x 2 pi pi 4096 апр 16 16:05 scripts
2. Made change in the internal editor code '/bin/bash...'
3. Checked this command in command line
>>>$ /bin/bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent
It works perfect from terminal.
3. Restart Domoticz and try to change selectors on Dummy switch.
Nothing changed.
Am i right that Selector actions (script://...) are empty?
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 14:29
by jvandenbroek
You could try using those actions instead, but that doesn't explain why it's not working with Lua..
When using script:// you should set it like this: script:///bin/bash etc (triple / and full path to bash). It might work for you, because it calls the scripts without Lua involved.
If in doubt, I would move the current domoticz installation folder and conpletely re-install, because you shouldn't get that dzVents.lua not found message (the other error doesn't seem relevant in this matter). Just copy over domoticz.db afterwards to get your data back.
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 14:44
by bigmak
jvandenbroek wrote: ↑Saturday 09 September 2017 14:29
You could try using those actions instead, but that doesn't explain why it's not working with Lua..
When using script:// you should set it like this: script:///bin/bash etc (triple / and full path to bash). It might work for you, because it calls the scripts without Lua involved.
If in doubt, I would move the current domoticz installation folder and conpletely re-install, because you shouldn't get that dzVents.lua not found message (the other error doesn't seem relevant in this matter). Just copy over domoticz.db afterwards to get your data back.
If dzVents - not a main problem - i will fix it after solving the problem with script.
Can you tell me - for Domoticz is it equal (1-3):
1. LUA script in folder ~/domoticz/scripts/lua...
2. Script in internal editor
3. Link in Scripts Action "script:///...'
?
Can I choose just one way (1-3)?
Re: Lua script did not return a commandArray
Posted: Saturday 09 September 2017 14:49
by jvandenbroek
bigmak wrote:jvandenbroek wrote: ↑Saturday 09 September 2017 14:29
You could try using those actions instead, but that doesn't explain why it's not working with Lua..
When using script:// you should set it like this: script:///bin/bash etc (triple / and full path to bash). It might work for you, because it calls the scripts without Lua involved.
If in doubt, I would move the current domoticz installation folder and conpletely re-install, because you shouldn't get that dzVents.lua not found message (the other error doesn't seem relevant in this matter). Just copy over domoticz.db afterwards to get your data back.
If dzVents - not a main problem - i will fix it after solving the problem with script.
Can you tell me - for Domoticz is it equal (1-3):
1. LUA script in folder ~/domoticz/scripts/lua...
2. Script in internal editor
3. Link in Scripts Action "script:///...'
?
Can I choose just one way (1-3)?
I understand that dzVents is not being used, but if that fails, more things might be wrong with the installation (since it's part of the main installation, not something you could update separately).
First 2 are equal, last one uses different functions and might work for you. You should only use one at a time (so not both Lua and script://).
Re: Lua script did not return a commandArray
Posted: Sunday 10 September 2017 10:54
by bigmak
jvandenbroek wrote: ↑Saturday 09 September 2017 14:49
If in doubt, I would move the current domoticz installation folder and conpletely re-install, because you shouldn't get that dzVents.lua not found message (the other error doesn't seem relevant in this matter). Just copy over domoticz.db afterwards to get your data back.
Thanks, i fixed problem with dzVents
>>> Error: EventSystem: in dzVents.lua: cannot open dzVents.lua: No such file or directory
1. Found 2 files and kill them:
~/domoticz/scripts/dzVents/runtime $
-rw-r--r-- 1 pi pi 572 апр 16 16:05 device_scripts_dispatcher.lua
-rw-r--r-- 1 pi pi 571 апр 16 16:05 timer_scripts_dispatcher.lua
More info about problem with dzVents.lua
viewtopic.php?t=18322
2. Go to
~/domoticz $
and update by ./updatebeta
BUT!
My first problem with script still here.
I made small script just for one button "Medium".
When I click to "Medium" on my dummy switch i have it on log:
Code: Select all
2017-09-10 11:50:18.369 User: Admin initiated a switch command (30/Humidifier/Set Level)
2017-09-10 11:50:18.596 Executing script: /home/pi/domoticz/scripts/test_script.sh
No errors. And nothing changed with my humidifier.
Do you have any working test-script with os.execute that I can use for testing my domoticz?
Re: Lua script did not return a commandArray
Posted: Sunday 10 September 2017 16:38
by jvandenbroek
You could try something simple like this, it should print the current date in /tmp/test.log:
Code: Select all
#!/bin/bash
echo $(date) > /tmp/test.log
If you update to the latest beta, the mix-up of dzVents / Lua lines showing up in the log should be solved (but that has nothing to do with your issue, just to make things less confusing)
Re: Lua script did not return a commandArray
Posted: Monday 11 September 2017 9:18
by bigmak
jvandenbroek wrote: ↑Sunday 10 September 2017 16:38
You could try something simple like this, it should print the current date in /tmp/test.log:
Code: Select all
#!/bin/bash
echo $(date) > /tmp/test.log
You know what? Your code is working... I don't know why, but I created dummy switch and made "on action" script
Script:///home/pi/Xiaomi/test.sh
with your code.
And it works....... aaaaaa!!!!!
jvandenbroek wrote: ↑Sunday 10 September 2017 16:38
If you update to the latest beta, the mix-up of dzVents / Lua lines showing up in the log should be solved (but that has nothing to do with your issue, just to make things less confusing)
I didn't catch the idea about "showing up in the log should be solved".
I updated to the v 3.8390 and what? Please, write a little bit more about it?
Thank you!
Re: Lua script did not return a commandArray
Posted: Monday 11 September 2017 11:31
by jvandenbroek
bigmak wrote: ↑Monday 11 September 2017 9:18
I didn't catch the idea about "showing up in the log should be solved".
I updated to the v 3.8390 and what? Please, write a little bit more about it?
Thank you!
I meant the line which prints 'dzVents' in your second post, while it should print 'LUA'. This is pure cosmetic, but fixed in the latest beta
(or at least I hope it is)
Not sure why nothing happens, while executed manually it works fine.. Maybe you could try "script:///bin/bash -x /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent" and start Domoticz in a seperate terminal (just with ./domoticz instead of start-up script) to get a trace of what's executed, this might give you an idea where is goes wrong.
Re: Lua script did not return a commandArray
Posted: Monday 11 September 2017 11:53
by bigmak
jvandenbroek wrote: ↑Monday 11 September 2017 11:31
Not sure why nothing happens, while executed manually it works fine.. Maybe you could try "script:///bin/bash -x /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent" and start Domoticz in a seperate terminal (just with ./domoticz instead of start-up script) to get a trace of what's executed, this might give you an idea where is goes wrong.
Dear jvandenbroek,
thank you for your help! Less then 10 minutes before your reply I tried a hundredth variant of my code and it started working!
I made 4 scripts (for each level) and put it on the "Level Actions" "script:///...".
Final code for one of the level is:
Code: Select all
#!/bin/sh
# Humidifier
# Set Power off
sudo /home/pi/.nvm/versions/node/v6.0.0/bin/node /home/pi/Xiaomi/humidifier.js 192.168.1.40 power off /dev/null
exit 0
What I've been changed:
1. "Bash" -> "Sh"
2. Put "sudo" an the beginning
3. Made full path to the file and command "node"
4. Put "/dev/null" at the end.
And now it works perfect from Domoticz.
Thank you very much!
Re: Lua script did not return a commandArray
Posted: Monday 11 September 2017 12:04
by jvandenbroek
Ah interesting, thanks for letting us know! I think the full paths to both node and js file would be sufficient? Or is it really necessary to use sh?
Re: Lua script did not return a commandArray
Posted: Monday 11 September 2017 15:50
by bigmak
jvandenbroek wrote: ↑Monday 11 September 2017 12:04
Ah interesting, thanks for letting us know! I think the full paths to both node and js file would be sufficient? Or is it really necessary to use sh?
Necessary:
- full path
- one '/dev/null' at the end of LUA-code.
I rewrite my code and now it works from LUA editor:
Code: Select all
commandArray = {}
-- Humidifier
if devicechanged['Humidifier'] == 'Silent' then
os.execute ('sudo screen -S humidifiertemp -d -m /bin/bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on silent')
end
if devicechanged['Humidifier'] == 'Medium' then
os.execute ('sudo screen -S humidifiertemp -d -m /bin/bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on medium')
end
if devicechanged['Humidifier'] == 'High' then
os.execute ('sudo screen -S humidifiertemp -d -m /bin/bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 on high')
end
if devicechanged['Humidifier'] == 'Off' then
os.execute ('sudo screen -S humidifiertemp -d -m /bin/bash /home/pi/domoticz/scripts/humidifiercontrol.sh 192.168.1.40 off /dev/null')
end
return commandArray
And! Lua script did not return a commandArray - shame on me, because I didn't change "All" to 'Device" in the internal editor.
Thanks to all!