Dummy selector, script not running

Moderator: leecollings

Post Reply
Blingoali
Posts: 3
Joined: Wednesday 17 January 2018 17:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Dummy selector, script not running

Post by Blingoali »

Hi,

First time post and I'm stumped..

I have a dummy selector switch called 'override'. I've set up values of 0, 10, 20, 30 with corresponding lua scripts of, e.g.,

Code: Select all

script:///home/pi/domoticz/scripts/lua/override30.lua
The lua scripts contain

Code: Select all

#!/usr/bin/lua
command Array = {}
print ('hello world')
return commandArray
Eventually they'll set different levels but for now, that's it. If I click one of the levels, my log shows:

Code: Select all

2019-02-18 16:54:55.872 Status: User: username initiated a switch command (60/Override/Set Level)
2019-02-18 16:54:56.081 Status: Executing script: /home/pi/domoticz/scripts/lua/override30.lua
but absolutely nothing else happens.

If I rename the override30.lua script to script_device_override.lua it fires every time I press the selector and displays 'hello world' but if I run it from the selector - nothing.

After Googling other peoples' similar problems, I've tried making the lua file executable by everyone (to eliminate one error) and adding the #! line to eliminate a second but now I'm stumped. Any help greatly appreciated.
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Dummy selector, script not running

Post by jvdz »

You are mixing up a couple of things here.
The commandarray script cannot be fired that way but need to be located in domoticz/scripts. See the wiki topic events for all details.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Blingoali
Posts: 3
Joined: Wednesday 17 January 2018 17:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dummy selector, script not running

Post by Blingoali »

Thanks for the quick reply, Jos, but I'm still a little puzzled. I suspect I've phrased my question incorrectly, so let me try again.

As per this section in the wiki,
By adding your own scripts to the scripts/lua/ dir in your domoticz installation folder
I have a dozen scripts (event, device, time) in /home/pi/domoticz/scripts/lua and they're all working correctly. I have a dummy switch called override which I would like to operate via a selector. I've created a selector with four levels: 0, 10, 20, 30

I've created a script called script_device_override.lua and, when I press any of the sensor buttons, the script prints 'hello world' in the log.

I've created four copies of this script and called them overrideoff.lua override10.lua override20.lua and override30.lua and tweaked them to print 'hello world 10' etc. Any of them runs correctly when it's renamed to the correct device script. I've then deleted script_device_override.lua and set them up in the selector like this:
selector.jpg
selector.jpg (64.4 KiB) Viewed 1175 times
Now, on pressing a button, I get a pop-up 'switching 30' (or whichever button I pressed) message, the log says

Code: Select all

2019-02-18 16:54:55.872 Status: User: username initiated a switch command (60/Override/Set Level)
2019-02-18 16:54:56.081 Status: Executing script: /home/pi/domoticz/scripts/lua/override30.lua
but no 'hello world' appears.

What I'm trying to get across is that the scripts all work correctly when set up as device scripts, but not when called - in the same folder - from the selector. I'm sure I'm doing something obviously wrong but, having read the events section of the wiki as you suggest (and many other pages besides), I can't see what I need to do to make this work.

Thanks again,

Keith
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Dummy selector, script not running

Post by jvdz »

Just remove those entries in the Device screen for Selector Actions, as the script_device_override.lua script will run each time the Override device changes. Then in the script you can do something like this:

Code: Select all

command Array = {}
print ('hello world... Device Override was fired and option '.. otherdevices_svalues['Override'] .. ' was selected')

if otherdevices_svalues['Override'] == "0" then
   print("---  do whatever 0 needs to do")
elseif otherdevices_svalues['Override'] == "10" then
   print("---  do whatever 10 needs to do")
elseif otherdevices_svalues['Override'] == "20" then
   print("---  do whatever 20 needs to do")
elseif otherdevices_svalues['Override'] == "30" then
   print("---  do whatever 30 needs to do")
end
return commandArray
You only need to use the Selector Actions ( or Switch Actions for switch devices) when you want to run an script outside of the Event subsystem.
All clear? :)
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Blingoali
Posts: 3
Joined: Wednesday 17 January 2018 17:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dummy selector, script not running

Post by Blingoali »

Many, MANY thanks. It was the reading of the selector value into the script that had eluded me.

All working and understood... now the fun really begins!

Keith
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest