Page 1 of 1

Script execution : nothing happens

Posted: Friday 10 March 2017 9:35
by St7ven
Hi,

I have called the lua script through a dummy device, but nothing happens. I use a simple script found in the /script/lua/script_device_demo.lua

2017-03-10 09:20:08.826 (Dummy) Light/Switch (Selector)
2017-03-10 09:20:10.111 Executing script: scripts\lua\script_device_demo.lua

It should appear a text (print('this will end up in the domoticz log')) at least.

I'm running domoticz on windows 7.

---------
note : before, I have associated .lua with sublime text, and when domoticz executed script: scripts\lua\script_device_demo.lua. Sublime text open the lua file. I removed this link, but I didn't get any improvement.


Could you help, please.

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 9:55
by DomoHouse
If you want to run scripts as on or off action, you need to start the command line with

script://

in your case, the command would look as follows:

script:///home/pi/domoticz/scripts/lua/script_device_demo.lua

I am not sure if you can execute lua scripts directly. If not, your command should look like:

script:///usr/bin/lua /home/pi/domoticz/scripts/lua/script_device_demo.lua

Keep in mind that when running LUA scripts from the command line (this is what you are actually doing here), you don't have access to the domoticz DB using commands such as otherdevices, otherdevices_svalues, etc. If you'd want to access Domoticz status, variables, etc. from a commandline, you have to revert to HTTP requests and processing the JSON return value.

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 9:57
by DutchHans
Hi, change the name of the script without the word "demo" ...this "demo" prevents the eventsystem from executing the script..

Cheers,Hans

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 11:28
by St7ven
Because i'm running Domoticz on windows, I assume that the command look like :

script://scripts\lua\nameofscript.lua
(found on a french forum : https://easydomoticz.com/domoticz-et-wi ... ction_off/)

I removed the _demo suffix. But I did not get any improvement. :cry: :cry:

Thank you for your help.

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 11:33
by jvdz
It looks like the script is ran, which you could easily check by writing a line to a log file in your script.
What is the script supposed to do that doesn't happen? Maybe show the script?
It should appear a text (print('this will end up in the domoticz log')) at least.
Why do you expect this? I don't think this will work that way and only happen when you use the buildin event handler of Domotics!
This means the script is properly named and put in the LUA subdirectory. Only then you will have all defined Tables available as described in the Event Wiki.

Jos

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 11:55
by St7ven

Code: Select all

print('this will end up in the domoticz log')

commandArray = {}
if (devicechanged['MyDeviceName'] == 'On' and otherdevices['MyOtherDeviceName'] == 'Off') then
	commandArray['MyOtherDeviceName']='On'
end
return commandArray
This is the code of the script_device_demo.lua file, renommed script_device_try.lua . As you can seen, I call the print function but nothing appear on the log file.

I call the script through the switch dummy device as it :

Image

So, if I understand wright, Lua script can not be executed this way and have to be called from the event handler ?

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 12:06
by jvdz
Correct, so simply remove the lines in the ON/Off action and things should still be ran by the internal event system as explained in the WikI: https://www.domoticz.com/wiki/Events

Jos

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 12:23
by St7ven
I change the switch type to "selector"

So, I ran the script for the event manager and the script work. But not only the event script but also the one in action.

Then, I have deleted the script in the event manager and let the script in the action in place as describe in : https://forum.mysensors.org/topic/4933/ ... tutorial/2

Here is the action place on level 3 :
script://scripts\lua\script_device_try.lua

Here is the script :

Code: Select all

print('this will end up in the domoticz log')

commandArray = {}

return commandArray
Here is the log

Code: Select all

2017-03-10 12:18:38.872 User: Admin initiated a switch command (9/Selector/Set Level)
2017-03-10 12:18:38.907 LUA: this will end up in the domoticz log
2017-03-10 12:18:38.872 (Dummy) Light/Switch (Selector)
2017-03-10 12:18:41.188 User: Admin initiated a switch command (9/Selector/Set Level)
2017-03-10 12:18:41.298 LUA: this will end up in the domoticz log
2017-03-10 12:18:41.188 (Dummy) Light/Switch (Selector)
2017-03-10 12:18:42.962 User: Admin initiated a switch command (9/Selector/Set Level)
2017-03-10 12:18:43.111 LUA: this will end up in the domoticz log
2017-03-10 12:18:42.978 (Dummy) Light/Switch (Selector)
2017-03-10 12:18:44.908 User: Admin initiated a switch command (9/Selector/Set Level)
2017-03-10 12:18:44.991 LUA: this will end up in the domoticz log
2017-03-10 12:18:44.908 (Dummy) Light/Switch (Selector)
2017-03-10 12:18:46.206 Executing script: scripts\lua\script_device_try.lua
2017-03-10 12:18:46.942 User: Admin initiated a switch command (9/Selector/Set Level)
2017-03-10 12:18:46.980 LUA: this will end up in the domoticz log
2017-03-10 12:18:46.942 (Dummy) Light/Switch (Selector)
As you can see, the script is called whatever level I selected (the log display the print(...) place in the script). When I call the level3, this time, I get a additionnal line : Executing script: scripts\lua\script_device_try.lua

Why are the "LUA: this will end up in the domoticz log" appear even if the script is not called on this level ?

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 12:33
by jvdz
Since this script is a Device script, it will be ran whenever any of your devices have a change of the status.
So the first thing to do is to ensure your device script's logic is only executed when the appropriate device has changed.
Just read all about it in the event wiki I pointed you to.

Jos

Re: Script execution : nothing happens

Posted: Friday 10 March 2017 12:45
by St7ven
Ok,

Thank you for you help !