Problem with variable Topic is solved

Moderator: leecollings

Post Reply
kish89
Posts: 2
Joined: Thursday 14 May 2020 9:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problem with variable

Post by kish89 »

Hello,

I have python script with list of online radio stations.
Python script takes one argument, like so: "python_script.py OnlineRadioStationName".
This works fine when executed in shell, but I have a problem linking this script to domoticz.

Here is the domoticz lua script:

Code: Select all

commandArray = {}

if (devicechanged['OnlineRadio'] == 'Off') then
    os.execute ("killall mplayer")
elseif (devicechanged['OnlineRadio']) then
     uservariables['OdabranaStanica'] = devicechanged['OnlineRadio'];  
    --os.execute ("runuser -l pi -c \'python /home/pi/online_radio.py Otvoreni' &> /dev/null")
    os.execute ("runuser -l pi -c \'python /home/pi/online_radio.py" ..OdabranaStanica.. "'&> /dev/null")
end

return commandArray
I have dummy selector switch with these options:
10- Off
20- RadioStation1
30- RadioStaion2
40- etc..

I can make script work by manually typing IF loop for each radiostation like so:
os.execute ("runuser -l pi -c \'python /home/pi/online_radio.py RadioStation1' &> /dev/null")
etc.
And this works!

However, I want more elegent way where RasioStationName argument will be variable which is populated from the status of dummy selector switch.
So, how to use variable in this case?
Script is triggered as Device, and then I get this error: 12: attempt to concatenate a nil value (global 'OdabranaStanica')

I can change trigger to User Variable, then there is no error, but also no response from the python script, it doesn't play radio station.
kish89
Posts: 2
Joined: Thursday 14 May 2020 9:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with variable

Post by kish89 »

Never mind, it's always happening when I ask for help.
This was the solution:
os.execute ("runuser -l pi -c \'python /home/pi/online_radio.py " .. devicechanged['OnlineRadio'] .. " &> /dev/null'")
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest