Page 1 of 1

Listen to your favourite radios

Posted: Sunday 21 February 2016 15:50
by oliviers
Hi,
I would like to share with the community what I did to listen to my favourite radios via Domoticz...
Today, most radio stations can be "received" from the Internet via a live audio stream.
Here's what I did to receive these streams in my Domoticz ecosystem (Raspberry Pi 2B) :

1. Install MPLAYER : In a console window, enter:

Code: Select all

sudo apt-get update
sudo  apt-get install mplayer
2. Plug amplified speakers in the audio plug of the Raspberry. Connect the power cord to a 433Mhz or Zwave outlet, and create a physical switch in Domoticz to turn the speakers On and Off. It doesn't even need to be visible in the switch panel, but it's up to you.
Capture6.PNG
Capture6.PNG (2.29 KiB) Viewed 8151 times
3. For each radio that you want to listen, create a shell script such as next one, and save it in /home/pi/domoticz/scripts

Code: Select all

#!/bin/bash
# echo RTL2
wget "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=161&switchcmd=On" > /dev/null
sudo killall mplayer
mplayer -noconsolecontrols http://streaming.radio.rtl2.fr:80/rtl2-1-44-96 &
First line will turn the speakers on (put in the right idx, the one of your speakers).
Second line will stop any running instance of mplayer. This is necessary to zap between stations.
Third line will activate the audio stream. Make sure you don't forget the & to launch the player in background. For each radio, edit the script and put the right URL. (Here's a list of URLs for French radios: https://doc.ubuntu-fr.org/liste_radio_france )

4. Create a script to stop listening:

Code: Select all

#!/bin/bash
wget "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=161&switchcmd=Off" > /dev/null &
sudo killall mplayer > /dev/null &
5. Create a virtual selector switch in Domoticz, and create as many levels as you have radios you want to listen.
Assign the scripts created at step 3 to each level, and the "stop" script (step 4) to the "Off" level
Capture4.PNG
Capture4.PNG (139.08 KiB) Viewed 8151 times

6
. Here you go ...
Capture5.PNG
Capture5.PNG (30.04 KiB) Viewed 8151 times
Enjoy!
Oliviers

Re: Listen to your favourite radios

Posted: Sunday 21 February 2016 15:56
by nayr
very cool, arent the selector switches awesome?

have you looked into MusicPlayerDaemon aka MPD? it was designed for this. https://www.domoticz.com/wiki/MPD_%26_Domoticz

I did something similar with a real radio:
Image

Re: Listen to your favourite radios

Posted: Sunday 21 February 2016 16:11
by oliviers
Hello Nayr,
Thanks for pointing me at MPD.
Yes, selector switches are terrific.... In a previous version, I had one switch per radio station... Now I have a more compact swith panel.
Oliviers

Re: Listen to your favourite radios

Posted: Wednesday 24 February 2016 2:02
by HoLeeShiet
Great tutorial! Would it be possible to do this with a Chromecast Audio? Since I have my RPI hidden in the closet

Re: Listen to your favourite radios

Posted: Wednesday 24 February 2016 3:13
by nayr
no his solution requires local audio output.

Re: Listen to your favourite radios

Posted: Wednesday 24 February 2016 9:10
by deennoo
Same thing can be done to drive lms server on various player.

Thanks for the idea ! And thanx for selector !

Re: RE: Re: Listen to your favourite radios

Posted: Wednesday 24 February 2016 9:12
by deennoo
HoLeeShiet wrote:Great tutorial! Would it be possible to do this with a Chromecast Audio? Since I have my RPI hidden in the closet Image
Just set up an lms server, add you tunein radio account, and set up chromecast bridge lms plugin.

Then create a same kind of script but with lms API, and rock n roll

Re: Listen to your favourite radios

Posted: Wednesday 24 February 2016 11:32
by fergalom
I have something similar in place using forked-daapd and mpc on the RPi - can play to my airplay speakers :-)
Radio and tunes.

Good idea on the selector switch for radio stations!

Re: Listen to your favourite radios

Posted: Sunday 05 November 2017 16:50
by llheim
Thank you for sharing this. Only thing I changed (maybe of interest for people with a rpi3 and a bluetooth speaker) is to add some lines to your script to switch users. Domoticz runs as root on rpi3 and so do scripts called by it. By switching to a normal user mplayer can play my favorite morning radio show. :)

Re: Listen to your favourite radios

Posted: Sunday 14 January 2018 13:48
by 0n370uch
Hi, I build a new radio script without bash scripts. All done with one LUA script. Based on this idea :-).

Look here: https://www.domoticz.com/forum/viewtopi ... 38&t=21419