LUA script and selector switch

Moderator: leecollings

Post Reply
mackowiakp
Posts: 18
Joined: Friday 21 July 2017 19:26
Target OS: Linux
Domoticz version:
Contact:

LUA script and selector switch

Post 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 2011 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?
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: LUA script and selector switch

Post 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
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
mackowiakp
Posts: 18
Joined: Friday 21 July 2017 19:26
Target OS: Linux
Domoticz version:
Contact:

Re: LUA script and selector switch

Post by mackowiakp »

THX
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest