Gladly. I assume you have the Yamaha binding configured and the main zone is working. I use an update interval of 1 second. For the “virtual radio tuner”, I use three channels of the Yamaha thing:
// These items are connected to channels of the Yamaha main zone thing.
// They are not actually defined in the config files, but via PaperUI.
Switch WohnzimmerYamahaReceiver // connected to "Power"
String WohnzimmerYamahaReceiver_Input // connected to "Input source"
Dimmer WohnzimmerYamahaReceiver_Volume // connected to "Volume"
Additionally, I defined two more items in my items config files (you can ignore the groups):
// These two items are defined in the items file and are belong
// to the "virtual radio":
// The first is a "power switch" for the virtual radio:
Switch WohnzimmerVirtuellesRadio "Radio" (gZ_Wohnzimmer, gF_Multimedia)
// The second is a string that stores the current station:
String WohnzimmerVirtuellesRadio_Station "Radiosender" (gZ_Wohnzimmer, gF_Multimedia)
I use a file called “vtuner.map” in conf/transform
to map station names to stream URLs:
Radio\ Bob!=http://streams.radiobob.de/bob-shlive/mp3-192/vtuner.mp3
R.SH=http://streams.rsh.de/rsh-live/mp3-192/vtuner.mp3
Delta\ Radio=http://streams.deltaradio.de/delta-live/mp3-128/vtuner.mp3
N-JOY=http://ndr-njoy-live.cast.addradio.de/ndr/njoy/live/mp3/128/stream.mp3
NDR\ Blue=http://ndr-ndrblue-live.cast.addradio.de/ndr/ndrblue/live/mp3/128/stream.mp3
Kiel.FM=http://radio.oksh.de:8000/kielfm.mp3
Radio\ Bob!\ 90er\ Rock=http://streams.radiobob.de/bob-90srock/mp3-192/vtuner.mp3
Now, most of the magic happens in the rules of course:
// This rule turns on the receiver, sets the input to "SERVER" and sets
// an appropriate volume if the virtual radio power switch
// (item WohnzimmerVirtuellesRadio) is turned on. It then plays the stream
// according to the station name in item WohnzimmerVirtuellesRadio_Station.
rule WohnzimmerVirtuellesRadioAn
when
Item WohnzimmerVirtuellesRadio changed from OFF to ON
then
if (WohnzimmerYamahaReceiver.state == OFF){
WohnzimmerYamahaReceiver.sendCommand(ON)
}
WohnzimmerYamahaReceiver_Input.sendCommand("SERVER")
WohnzimmerYamahaReceiver_Volume.sendCommand(20)
var stream = transform("MAP", "vtuner.map", WohnzimmerVirtuellesRadio_Station.state.toString())
executeCommandLine("/usr/bin/python /usr/bin/dlnap.py --ip 192.168.178.12 --play " + stream)
end
// This rule turns the receive off if the virtual radio is turned off.
rule WohnzimmerVirtuellesRadioAus
when
Item WohnzimmerVirtuellesRadio received command OFF
then
WohnzimmerYamahaReceiver.sendCommand(OFF)
end
// If the receiver is turned off (by remote, other rules...), set the virtual
// radio power to off.
rule WohnzimmerVirtuellesRadioYamahaAus
when
Item WohnzimmerYamahaReceiver changed from ON to OFF
then
WohnzimmerVirtuellesRadio.postUpdate(OFF)
end
// This is the most essential rule. It is triggered when the station is
// changed and starts playing the station's stream. It will trigger the
// rule WohnzimmerVirtuellesRadioAn (the first one) if the virtual
// radio was previously off.
rule WohnzimmerVirtuellesRadioAndererSender
when
Item WohnzimmerVirtuellesRadio_Station received update
then
if (WohnzimmerVirtuellesRadio.state == OFF){
WohnzimmerVirtuellesRadio.sendCommand(ON)
}
var stream = transform("MAP", "vtuner.map", WohnzimmerVirtuellesRadio_Station.state.toString())
executeCommandLine("/usr/bin/python /usr/bin/dlnap.py --ip 192.168.178.12 --play " + stream)
end
// If the receiver input is set to an input other than "SERVER", set the
// virtual radio power to off.
rule WohnzimmerVirtuellesRadioAndererEingang
when
Item WohnzimmerYamahaReceiver_Input changed
then
if (WohnzimmerYamahaReceiver_Input.state.toString() != "SERVER"){
WohnzimmerVirtuellesRadio.postUpdate(OFF)
}
else {
WohnzimmerVirtuellesRadio.postUpdate(ON)
}
end
// This is a convenience rule. We have really bad FM reception at our place,
// so whenever the receiver's tuner is selected, (e.g. by remote), the rule
// will immediately switch to one of the streams.
rule WohnzimmerVirtuellesRadioTunerAn
when
Item WohnzimmerYamahaReceiver_Input changed
then
if (WohnzimmerYamahaReceiver_Input.state == "TUNER") {
WohnzimmerVirtuellesRadio_Station.sendCommand("Radio Bob!")
}
end
The station can be changed via Habpanel and a slection in a sitemap, that is defined like this:
Selection item=WohnzimmerVirtuellesRadio_Station label="Radiosender" mappings=["Radio Bob!"="Radio Bob!", "Delta Radio"="Delta Radio", "N-JOY"="N-JOY", "NDR Blue"="NDR Blue", "R.SH"="R.SH", "Kiel.FM"="Kiel.FM"]
That’s all! If you have questions or comments, feel free to ask!