Page 1 of 1

Scripting problem with switch - Off works, on does not work

Posted: Monday 07 January 2019 16:04
by crashingdutchman
I have a problem with setting the On position of a virtual switch through a script (tvswitch.lua). The script is a very simple LUA script that contains the following commands (I am just debugging here):

Code: Select all

commandArray = {}
print("test")
return commandArray
If I remember well, I did a chmod 755 on the tvswitch.lua.

When I set the switch in the Off position, I see the following lines in my Domiticz log:
2019-01-07 15:56:17.632 (@Home) Light/Switch (Televisie woonkamer)
2019-01-07 15:56:17.603 Status: User: admin initiated a switch command (43/Televisie woonkamer/Off)
The print("test") is not visible here (I am not sure if I should expect it in the log-file) and it seems that the script ran fine. Now when I set the switch in the "On" possition I see the following:
2019-01-07 15:57:03.365 (@Home) Light/Switch (Televisie woonkamer)
2019-01-07 15:57:03.336 Status: User: admin initiated a switch command (43/Televisie woonkamer/On)
2019-01-07 15:57:03.344 Error: SQLHelper: Error script not found '/lua/tvswitch.lua'
Both the On and Off scripts are defined in the switch settings as below (note the 3 slashes)

Code: Select all

script:///lua/tvswitch.lua
I have also tried it with 2 slashes instead of 3 for the script On/Off-actions and this results in more or less a similar behavior, the only difference is that settings the switch in the "On" position results in the error below.
2019-01-07 15:59:30.103 Error: Error executing script command (/home/pi/domoticz/scripts/lua/tvswitchon.lua). returned: 512
What am I doing wrong? Should this work? Any help is appreciated!

I have been testing this with Domotics version 4.10303 (which is a beta I think)

Re: Scripting problem with switch - Off works, on does not work

Posted: Monday 07 January 2019 17:19
by waaren
crashingdutchman wrote: Monday 07 January 2019 16:04 I have a problem with setting the On position of a virtual switch through a script (tvswitch.lua). The script is a very simple LUA script
What am I doing wrong? Should this work? Any help is appreciated!
This is not how the event System in domoticz works. The use of scripts in On/ Off blocks of switches are meant for OS type of script and the event system is internal domoticz. Please have a look at events wiki first. It is a bit outdated but it should give you an idea.

Re: Scripting problem with switch - Off works, on does not work

Posted: Tuesday 08 January 2019 9:24
by crashingdutchman
Okay, thank you very much. I switch to using a lua script from the events section. That solved it.