Page 1 of 1

LUA script and selector switch

Posted: Saturday 12 September 2020 9:00
by mackowiakp
I use virtual selector switch to turn on/off, channel up/down of radio receiver. My goal is to move appropriate commands from sensor definition to LUA script.
Below current definition of "Radio" sensor:
Selector.png
Selector.png (133.67 KiB) Viewed 2135 times
The LUA script as shown below, does not work. Of course in case of using LUA, actions definitions from sensor definition are removed.

Code: Select all

local sensor = 'Radio'

commandArray = {}

if (devicechanged[sensor] == 'Wyłączone') then
 os.execute ("/home/pi/Pobrane/radio 0")
elseif (devicechanged[sensor] == 'Stacja +') then
 os.execute ("/home/pi/Pobrane/radio 100")
elseif (devicechanged[sensor] == 'Stacja -') then
 os.execute ("/home/pi/Pobrane/radio 101")
end

return commandArray
What error I am doing? Any idea to correct/modify something?

Re: LUA script and selector switch

Posted: Friday 18 September 2020 11:08
by zicht
Hi

The lua script does not see the custom field names but sees the selector switch as level %
0 = off
10= first choice
20=second choice

start with : print(otherdevices[sensor])
Look in the log after switching and you will understand
once you have seen it then it is easy :)

so you will need something like

if (devicechanged[sensor] == 'Off') then
do somehing
else if (devicechanged[sensor] == 'Set Level 10%') then
do somehing
else if (devicechanged[sensor] == 'Set Level 20%') then

end

Re: LUA script and selector switch

Posted: Friday 18 September 2020 12:39
by mackowiakp
THX