How to add:
Just make a new selector switch with your favorite name (in my example "Wohnzimmer > Radio"). Add your radio stations with name. Then add a new LUA script and select "Device only" as execution type. Copy the code and change the radio station addresses, the switch name and the switch selector names. Thats all.
--
-- This script play a streaming radio when the device is changed
-- Start files with "mplayer -noconsolecontrols radiostation.mp3 &> /dev/null"
-- Start playlists with "mplayer -noconsolecontrols -playlist radiostation.m3u &> /dev/null"
--
commandArray = {}
if (devicechanged['Wohnzimmer > Radio'] == 'Off') then
os.execute ("killall mplayer")
end
if (devicechanged['Wohnzimmer > Radio'] == '1FM') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols http://uk2.internet-radio.com:8358/ &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == '1LIVE') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols https://wdr-1live-live.icecastssl.wdr.de/wdr/1live/live/mp3/128/stream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'Bayern 3') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols http://br-br3-live.cast.addradio.de/br/br3/live/mp3/128/stream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'MDR Jump') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols http://mdr-284320-0.cast.mdr.de/mdr/284320/0/mp3/high/stream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'Radio Berg') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols http://edge.live.mp3.mdn.newmedia.nacamar.net/radioberg/livestream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'SWR1 Rheinland-Pfalz') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols http://swr-swr1-rp.cast.addradio.de/swr/swr1/rp/mp3/128/stream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'SWR3') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols http://swr-swr3-live.cast.addradio.de/swr/swr3/live/mp3/128/stream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'WDR2 Bergisches Land') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols https://wdr-wdr2-bergischesland.icecastssl.wdr.de/wdr/wdr2/bergischesland/mp3/128/stream.mp3 &> /dev/null")
end
if (devicechanged['Wohnzimmer > Radio'] == 'WDR4') then
os.execute ("killall mplayer")
os.execute ("mplayer -noconsolecontrols https://wdr-wdr4-live.icecastssl.wdr.de/wdr/wdr4/live/mp3/128/stream.mp3 &> /dev/null")
end
return commandArray
By the way: I trigger the script with an blocky script. This blocky script will be execute if an external bluetooth radio is connected. I can post the cronjob and blocky script too. Therefore I added the follwing code to every switch status:
Hi, I'm using a Raspberry Pi 2b with Bluetooth dongle (4.1) and a Panasonic Hifi System with Bluetooth (function is similar to Bluetooth speakers). Just connect the bluetooth speaker to your Raspberry and enjoy radio . Here is the code for bluetooth (for Rasbian Stretch). This code connect the Raspberry with your Bluetooth device and reconnect if connection is lost.
//sudo systemctl start bluetooth && sudo systemctl enable bluetooth
sudo bluetoothctl
power on
agent on
scan on
connect 00:11:22:33:44:55
trust 00:11:22:33:44:55
scan off
exit
Please some one help me
I have done everything like you said but I cannot make it play.
i will send all my info.
First of all I run the command on terminal and it plays the selected radio, then I do off on my dummy selector and it stop the radio.
My problem it is when I select a radio from selector it does not do nothing
your solution looks great, but... can you check the CPU usage during that script?
My understanding the LUA scripting tells me that the os.execute runs the stream and should keep busy the PI raising CPU, but my lack of knowledge in bash and linux system suggest me that the
mplayer -noconsolecontrols should slice the command as a service.. or something like that, so the LUA script should complete with no error and keep it free to be refired...
is that correct?
if so... you're solution is simply great!
you could even add a selector switch with the destination (BT Speacker, local speaker etc etc) to be evaluate and activate via alsa command... so you get a multiroom system
The most dangerous phrase in any language is:
"We always done this way"
0n370uch wrote: ↑Wednesday 28 February 2018 17:53
Ok everything looks good... One idea:
Add the "sudo" command to the two "os.execute" lines. You added the "sudo" command to your first "killall" too.
Hope this is the solution...
So friend I found that if a run the command with sudo on command line, the raspberry pi dont play anything. But if I run the command without sudo it plays.
Again I cannot understand why it dont play when call it on Domoticz
emme wrote: ↑Thursday 01 March 2018 8:24
My understanding the LUA scripting tells me that the os.execute runs the stream and should keep busy the PI raising CPU, but my lack of knowledge in bash and linux system suggest me that the
mplayer -noconsolecontrols should slice the command as a service.. or something like that, so the LUA script should complete with no error and keep it free to be refired...
is that correct?
Hi, yeah thats correct. We have two important options. The first one is the "-noconsolecontrols" to disable the controls. And the second more important option is "&> /dev/null". This second option will close the terminal without any output. The process is running in the background. Here you can see two pictures with and without running radio. The CPU load is very low.
With LUA radio script:
cpu load with radio.jpg (338.26 KiB) Viewed 9547 times
Without LUA radio script:
cpu load without radio.jpg (349.43 KiB) Viewed 9547 times
tukestolo wrote: ↑Thursday 01 March 2018 12:47
So friend I found that if a run the command with sudo on command line, the raspberry pi dont play anything. But if I run the command without sudo it plays.
Again I cannot understand why it dont play when call it on Domoticz
Ok seems like trouble with your user rights. Domoticz is running as user (in normal case). Please remove all "sudo" commands from your LUA script.
0n370uch wrote: ↑Thursday 01 March 2018 12:55
Hi, yeah thats correct. We have two important options. The first one is the "-noconsolecontrols" to disable the controls. And the second more important option is "&> /dev/null". This second option will close the terminal without any output. The process is running in the background. Here you can see two pictures with and without running radio. The CPU load is very low.
Thank you so much!!!
This kind of scenraio should be included natevely in Domticz by my personal opinion
The most dangerous phrase in any language is:
"We always done this way"
So friends I do more debug and I found another thing, the Env is different from command run on Domoticz(command don't work) and command run on console (Command works).
so I found that if a run Domoticz with init.d some commands on lua script don't work.
but if I start Domoticz with pi user and with ./domoticz command the lua commands work well....
Hi, sounds like a Domoticz global problem. Now I am at the end with my knowledge ...sry. Just one idea, check this: https://www.domoticz.com/wiki/Linux