OH2 Squeezeplayer with Radio/Playlist Select Button and dynamic visibility

Hello,
here is my take on a Dynamic Player in your Sitemap. If Playback is paused, a picture is shown and all other Player items are hidden. Press play and Radio Station / Playlist select buttons, Artist/Title/Stream info is shown.
There are other examples using Dropdown selects, but i like directly visible options better.
Also works for playlists.
It looks like so:
Player on Play:

Player on Pause:

The example will give you a generic setup for one player, which can easily be expanded to any amount of players you might have. There is one prerequisite for the Radio select to work: at least the items in Group ā€œgPlayerPlayListā€ need to be persisted.
So without further much ado,here it is:

//Items:
Group gPlayerPlayList
Group	gAllPlayersStream
//add as many as you need.
Number		squeezeSelect1Station "šŸ“»" <none> (gPlayerPlayList)
Number		squeezeSelect2Station "šŸ“»" <none> (gPlayerPlayList)
Number		squeezeSelect3Station "šŸ“»" <none> (gPlayerPlayList)
Number		squeezeSelect4Station "šŸ“»" <none> (gPlayerPlayList)

//Player 1
//for more players, cut and paste and replace "1" with "2" for instant added player,just add your UIDs
//of course you can use more meaningful names like "Kitchen" or "Bath"
Group gPlayer1
Player	squeeze1Control "Player"		<play>			(gPlayer1)		{ channel="squeezebox:squeezeboxplayer:xx:yy:control" }
Dimmer  squeeze1InfoVol "InfoVol [%d %%]" 													{ channel="squeezebox:squeezeboxplayer:xx:yy:notificationSoundVolume"}
Dimmer	squeeze1Volume "Vol [%d %%]"	<lautsprecher> 	(gPlayer1)		{ channel="squeezebox:squeezeboxplayer:xx:yy:volume" }
String	squeeze1Stream "Stream: [%s]"	<info>			(gPlayer1,gAllPlayersStream)		{ channel="squeezebox:squeezeboxplayer:xx:yy:stream" }
String	squeeze1Title "Titel: [%s]"	<info>			(gPlayer1)			{ channel="squeezebox:squeezeboxplayer:xx:yy:title" }
String	squeeze1Artist "von: [%s]"		<info>	(gPlayer1)	{ channel="squeezebox:squeezeboxplayer:xx:yy:artist" }
String	squeeze1RadioTitle	"Stream: [MAP(streams.map):%s]"	<info> (gPlayer1) { channel="squeezebox:squeezeboxplayer:xx:yy:remotetitle" }

//Rule:
var String RadioHR3="http://opml.radiotime.com/Tune.ashx?id=s57109&formats=aac,ogg,mp3&partnerId=16&serial=8ef15207e62082921048854d898a9367"
var String RadioSwissClassic="http://opml.radiotime.com/Tune.ashx?id=s25582&formats=aac,ogg,mp3&partnerId=16&serial=e16775754549cd827c15202ce6b569d6"
var String RadioSilenceNoGood="http://opml.radiotime.com/Tune.ashx?id=s230457&formats=aac,ogg,mp3&partnerId=16&serial=e16775754549cd827c15202ce6b569d6"
var String RadioYOUFM="http://opml.radiotime.com/Tune.ashx?id=s24878&formats=aac,ogg,mp3&partnerId=16&serial=8ef15207e62082921048854d898a9367"
var String RadioPlanet="http://opml.radiotime.com/Tune.ashx?id=s2726&formats=aac,ogg,mp3&partnerId=16&serial=8ef15207e62082921048854d898a9367"
var String RadioFFH="http://opml.radiotime.com/Tune.ashx?id=s223993&formats=aac,ogg,mp3&partnerId=16&serial=8ef15207e62082921048854d898a9367"
//For playlist, just this and fill in playlist name, spaces replaced with "%20"
//if need be, change path to your playlist location(can be found/set via LMS web frontend)
var String PlayListYourName="file:///volume1/music/playlists/Playlist%20Name%20here.m3u"

rule "playlist wechsle dich"
when
	Item squeezeSelect1Station received command or	
	Item squeezeSelect2Station received command or	
	Item squeezeSelect3Station received command or		
	Item squeezeSelect4Station received command
then
       Thread::sleep(100) // give persistence time to save the update
	//get which players playlist should be changed
        //if you have several persistence services, you might need to specify the one to use like so: lastUpdate("mysql")
	val ThePlayList = gPlayerPlayList.members.filter[s|s.lastUpdate() != null].sortBy[lastUpdate()].last as NumberItem
	var PlayerStreamToChange=" "
	//logInfo("squeeze.rules","Player selected: "+ThePlayList.name.toString)
	switch (ThePlayList.name.toString){
		case "squeezeSelect1Station":PlayerStreamToChange="squeeze1Stream"
		case "squeezeSelect2Station":PlayerStreamToChange="squeeze2Stream"
		case "squeezeSelect3Station":PlayerStreamToChange="squeeze3Stream"
		case "squeezeSelect4Station":PlayerStreamToChange="squeeze4Stream"
	}
	switch (ThePlayList.state){
				case 1:{
					gAllPlayersStream.members.filter(s|s.name == PlayerStreamToChange).forEach[s | s.sendCommand(RadioHR3)]	
				}
				case 2:{
					gAllPlayersStream.members.filter(s|s.name == PlayerStreamToChange).forEach[s | s.sendCommand(RadioYOUFM)]
				}
				case 3:{
					gAllPlayersStream.members.filter(s|s.name == PlayerStreamToChange).forEach[s | s.sendCommand(RadioPlanet)]
				}
				case 4:{
					gAllPlayersStream.members.filter(s|s.name == PlayerStreamToChange).forEach[s | s.sendCommand(RadioFFH)]
				}
				case 5:{//this one selects a Playlist
					gAllPlayersStream.members.filter(s|s.name == PlayerStreamToChange).forEach[s | s.sendCommand(PlayListYourName)]
				}				
			}
end

//Sitemap:
Default item=squeeze1Control
//remove next line if you just want a "blank" screen. 
Image url="http://diddeli/daddeli.jpg"  visibility=[squeeze1Control==PAUSE]
Switch item= squeezeSelect1Station mappings=[1="HR3", 2="YOU FM",4="FFH"] visibility=[squeeze1Control==PLAY]
Switch item= squeezeSelect1Station mappings=[3="planet radio",5="Playlist"] visibility=[squeeze1Control==PLAY]
Slider item=squeeze1Volume visibility=[squeeze1Control==PLAY]
Text item=squeeze1Title visibility=[squeeze1Control==PLAY]
Text item=squeeze1Artist visibility=[squeeze1Control==PLAY]				
Text item=squeeze1RadioTitle visibility=[squeeze1Control==PLAY]

I hope some will find this useful,
Regards,
-OLI
EDIT: added playlist example

4 Likes

I started playing around with HABPanel, and as itā€™s the Futureā„¢ here is my take on a Squeeze Player Control, based on @Murpherā€™s MusicControl (Kudos for creating this one) together with a simple Radio select widget.
If on Pause, it displays a configurable temperatur item(or anything else you fancy), if on Play it displays Title and artist.
On Play:

On Pause:

The widgets will work with the example items and rules listed here. The Config labels should speak for themselves. NEXT and PREVIOUS are fixed; no need to set. Here you go:
SqueezeMusicControl.widget.json (4.4 KB)
RadioSelect.widget.json (1.8 KB)

Hope some will find this usefull,
Regards,
-OLI
P.S.: uploaded newer version of Radioselect: Now chosen station name gets highlighted, also there is a 2px space between the station rows. More shiny:

5 Likes

Glad it was of use

Great one! Iā€™ve moved your thread to the new HABPanel Examples category.

Thanks! :blush:
Maybe the original Alarm clock thingy would fit here as well?

Sure, just move it :wink: @ysc might be happy to some action in this new category :wink:

:joy:

Itā€™s true itā€™s not gotten much love until now. In fact, there are other threads in the ā€œAdd-ons > HABPanelā€ category which could easily be moved into ā€œExamplesā€, like this one:

and eventually this big old thread (even though thereā€™s a lack of explanations on how to achieve the results in the screenshots):

Btw: Great work @Oli!

Thank you sir :slight_smile:

LOLā€¦didnā€™t even know i could do that :pensive:

1 Like

I have moved (and renamed) both. It would be amazing if you could try to write a few more (the same goes for @Oli) . Also it might be a good idea to ask everyone who has posted a solution in the ā€œbig old threadā€ to open independent threads with their solution today.

P.S. let me know if more moderatorā€™y actions are needed :wink:

hi,
nice widget :slight_smile:
is it possible to bind an internet strem to it?
for example: I want to hear http://hr-hr3-live.cast.addradio.de/hr/hr3/live/mp3/128/stream.mp3 on my tablet if i push the HR3 button.
Thanks, Kersten Tams

Gude Kersten :slight_smile:
Indeed you can Stream HR 3 without problems.
Look at the example code further up; HR3 is allready there(and YOU FM, FFH, planet radioā€¦). It should work with cut&paste.
Regards,
-OLI

moin,
ok, it doesnā€™t. So I asked, because I am shure, I do some thing wrong.
I copied the ā€œitemsā€ section of your example to a file radio.items in the folder items. I copied the ā€œrulesā€ section of your example to rules/radio.rules.
I added the two widges and donā€™t know, what I had to write in the RadioSelect widged. ā€œNameā€ I think doesnā€™t matter but what to write at ā€œRadioNameā€?
I want to comprehend the example so I changed nothing.
In SqueezeMusicControl I bind the items as I understand it:

You see, I am very new to OH2 and Habpanel. May be there are stupid questions, but I hope you can be patient and show me the way :wink:

The ā€œNameā€ in the select widget is the unique player name, in the example given it is ā€œ1ā€.
So if you have, for example one player in kitchen and one in bath, you would name them e.g. squeezeBathVolume and squeezeKitchenVolume and the widgets would be named ā€œBathā€ and"Kitchen"
In the SqueezeMusicControl widget you did everything right :+1:
I assume you edited this part: :xx:yy: of the items to reflect your setup?

If not, this is most likely your problem. You need to go to paperUI, configuration, things and replace :xx:yy: with values from your player thing. It will look something like this in paperui:

If you did this and it still doesnā€™t work, please provide more info. Is it just the select widget which is not working, or is the radio control also unresponsive? What is happening in openhab and events log when you press the button?

Thanks for your help!
ok, I see the problem. I installed the sqeezebox binding, but I donā€™t have a squeezebox player. And so I canā€™t see a player in habpanel things. After I read many about squeezebox player, server bridge and so on, I am totally confused.
If I understand it right, I must have a player installed (squeeze lite for example). I installed OH2 on a RPi3. I control it with a tablet in an other room.
I want to hear radio in this room through the loud speakers of the tablet (its the kitchen, so quality is good enough).
If I understand it right, that is with squeezebox not possible, right?
Its not as easy as copy a link in a browser, right?

No, that is definitly possible. On the rpi, you Can Install squeezelite and
on the Tablet (Android?!) Squeezeplayer. Both will be detected by the
binding and then you Can Control them. I Use Old phones and the Most cheap
40ā‚¬ Tablet in my rooms with squeezeplayer ( on Play Store 5ā‚¬) and ist is
working great.

Am 06.06.2017 10:14 nachm. schrieb ā€œKersten Tamsā€ <bot@community.openhab.org

:grinning: at least I got it to run. But only the SqeezeMusicControl. But that is not so sad, because I want to hear FFN and NDR2 not HR3 or FFH :wink:
Now I use four normal Button widges to choose my favorite Radio stations. As the action I send the stream url to the player.
Thanks alot for your help.

No sweat. If everything else works exept the select widget, itā€™s most likely because the items arenā€™t persisted - that is a prerequesit for the logic to work. But since you found another solutionā€¦

Hi there!
i made some modifications to this great widget and now i wanted to remove the table borders (above title and artist).
But i donā€™t even get where they come from?
Could you help me out, @Oli ?

Cheers,
Peter

Hi & sorry for late reply. in case you havnā€™t found it yet, its this table;

<div>
  <table class="table">
<tr>
    <td class="text-left" ng-if="itemValue(config.status_item) =='PLAY'">Title: <strong>{{itemValue(config.title_item)}}</strong></td>
    <td class="text-center" ng-if="itemValue(config.status_item) !='PLAY'"><strong>{{config.temp_name}}</strong></td>
  </tr>
  <tr>
    <td class="text-left" ng-if="itemValue(config.status_item) =='PLAY'">Artist: <strong>{{itemValue(config.artist_item)}}</strong></td>
    <td class="text-center" ng-if="itemValue(config.status_item) !='PLAY'"><strong>{{itemValue(config.temp_item)}} Ā°C</strong></td>
  </tr>
</table>
  <div class="btn-group">
    <label class="btn-pad btn-lf" ng-click="sendCmd(config.action_item,('PREVIOUS'))"><i class="glyphicon glyphicon-step-backward"></i></label>
  	<label class="btn-radius btn-danger" ng-if="itemValue(config.status_item) !='PLAY'" ng-click="sendCmd(config.action_item,'PLAY')"><i class="glyphicon glyphicon-play glyphicon-text"></i></label>
    <label class="btn-radius btn-warning" ng-if="itemValue(config.status_item) =='PLAY'" ng-click="sendCmd(config.action_item,'PAUSE')"><i class="glyphicon glyphicon-pause glyphicon-text"></i></label>
    <label class="btn-pad btn-rt" ng-click="sendCmd(config.action_item,('NEXT'))"><i class="glyphicon glyphicon-step-forward"></i></label>
  </div>  
 <div class="div-slider" ng-init='model={"item": (config.volume), "floor": 0, "ceil": 100, "step":(config.step)}'>
  <widget-slider ng-model="model" />
</div>
</div>

i guess you could either set the border to be invisible, or remove the table alltogether. Iā€™s personally try setting invisible firstā€¦
Regards,
-OLI