Habpanel Sonos Widgets

Tags: #<Tag:0x00007f5c98598660> #<Tag:0x00007f5c98598570> #<Tag:0x00007f5c98598458>

Great. Is it working apart from the icons?

thx again for your patience. Everything is working now…

Well was a little bit too fast .It IS working , execpt volume up and down.
that are working but not correctly

Great. Not working in what way?

pressing volume up steps one song forward.
vulome down does the same…Steps one song forward

I was debugging the volume issue (not turning up volume but skipping to next track) and found this.

      <div class="col-sm-2 modgrid">
         <button class="sonosbutton" style="background-image: url(/static/sonos/VolDown.png); background-size: contain; background-repeat: no-repeat;background-position: center center" 
            ng-click="sendCmd(config.media_player, 'NEXT')"
            ng-dblclick="sendCmd(config.media_player, 'PAUSE')">

So you are referring to the volume icon but link to a skip command.
I tried to fix it but I messed up the widget :open_mouth:

Oops! Thanks! Will have a crack at fixing that but might be a while as on hols at the moment and not sure I can access remotely! Glad you got the rest of it working.

Thank you for your effort. Great work.

SonosControlWithArt works more or less. Artwork shows up, play/stop works but volume +/- won’t work.

My questions are mainly about the other two widgets:

In SonosAlbumSelect I can see my icons but the playlists don’t work. Do the playlists need to have the same name as in the Sonos app or the way I named them in my OH items? When I click, nothing happens. How do I route the playlist to a certain speaker/ room?

In SonosSystemVolume I am lost. I only manage to see two volume controls (Vol 1 and 2 I guess), the rest does not show up. Can you post some explanation on how to use this widget? Do chill and loud need to be extra items in OH? And what need to be entered in group? One for each room?

Thank you and best regards, Max

It seems to be increasingly obvious that there are some small issues with the widgets but also that the underlying items and rules are quite specific and I haven’t specified them! Thank you for the feedback and patience, particularly as it has taken me quite a while to respond to these. In the next couple of posts I’m going to aim to document how to setup!


This widget provides a dashboard to control a set of Sonos speakers up to a maximum of 7 (because it fits neatly and is how many I have!)

It uses one speaker as the ‘master’ and moves other speakers in and out of the same group. In my example setup the ‘Dining Room’ speaker is the master and so must be treated differently because this speaker must always be part of the group by definition. Therefore this master speaker is always in the group, slave speakers are added and removed from the group but the master speaker is muted (i.e it still plays but at volume 0)

NB confusingly the bottom left speaker is my master bedroom and top right is the master volume whereas the Dining Room is the master of the other 6 slave speakers. This is not helpful to explaining but is a lot of work to change!!

The following items must be created per speaker (the ones shown are for my nursery with an equivalent set for each room. The speaker names can be amended in the widget setup. You’ll need to change the channel to match your Sonos setup of course.

Player SN_Nursery_Controller "Nursery Controller"  {channel="sonos:PLAY3:RINCON_000:control"}
Dimmer SN_Nursery_Volume "Nursery Volume" (gSonosVol) {channel="sonos:PLAY3:RINCON_000:volume"}
Switch SN_Nursery_Mute "Nursery Mute"  {channel="sonos:PLAY3:RINCON_000:mute"}
String SN_Nursery_Faves "Nursery Faves"  {channel="sonos:PLAY3:RINCON_000:favorite", autoupdate="false"}
Switch SN_Nursery_Group "Nursery Group"  
String SN_Nursery_currentartist "Nursery Current Artist [%s]"  {channel="sonos:PLAY3:RINCON_000:currentartist"}
String SN_Nursery_currenttitle "NurseryCurrent Title [%s]"  {channel="sonos:PLAY3:RINCON_000:currenttitle"}
String SN_Nursery_currentalbumarturl "Nursery Current Album Art Url [%s]"  {channel="sonos:PLAY3:RINCON_000:currentalbumarturl"}
String SN_Nursery_add "Nursery Add"  {channel="sonos:PLAY3:RINCON_000:add", autoupdate="false"}
Switch SN_Nursery_Standalone "Nursery Stand Alone"  {channel="sonos:PLAY3:RINCON_000:standalone"}
String SN_Nursery_Coord "Nursery Coordinator [%s]"  {channel="sonos:PLAY3:RINCON_000:coordinator"}

The following items need a single item created as follows. Keep these names the same although you can replace “DiningRoom” with the name of the speaker you intend to use as the master.

Dimmer SN_AllVolume
Switch SN_DiningRoom_MuteInvert "Dining Room Mute"
Switch SN_SetVolsLoud { autoupdate="false"}
Switch SN_SetVolsChill { autoupdate="false"}

The following rules must also be created:

Rule 1 - Add and remove a slave speaker from the master group when clicking the button in the widget. An equivalent rule must be created for each speaker, substituting the following:
SN_Nursery_Group -> The ‘group’ item of this speaker (created above)
SN_DiningRoom_add -> The add item of the master speaker
RINCON_000 -> The identifier of this slave speaker
SN_Nursery_Standalone -> The ‘Standalone’ item of this speaker (created above)

	rule "Add/Remove Group - Nursery"
		Item SN_Nursery_Group received command
		if(SN_Nursery_Group.state ==ON) {sendCommand(SN_DiningRoom_add, "RINCON_000")}
		if(SN_Nursery_Group.state ==OFF)  {sendCommand(SN_Nursery_Standalone, ON)}

For comparison here is the next one in the list:

	rule "Add/Remove Group - ManCave"
		Item SN_ManCave_Group received command
		if(SN_ManCave_Group.state ==ON) {sendCommand(SN_DiningRoom_add, "RINCON_001")}
		if(SN_ManCave_Group.state ==OFF)  {sendCommand(SN_ManCave_Standalone, ON)}

Rule 2 This rule keeps the widget up to date if you use the regular Sonos app by noticing if the ‘Coordinator’ speaker changes. Again needs an equivalent for each speaker.

SN_Nursery_Coord -> Slave Speaker name
RINCON_002 -> The identifier of the master speaker

rule "Sonos Nursery Changed"
	Item SN_Nursery_Coord changed
	if (SN_Nursery_Coord.state =="RINCON_002") {
} else {

Rule 3 and 4 Rules to set all speakers to a ‘Chill’ and ‘Loud’ volumes (rather than fiddle constantly). I went round each speaker when the system was playing and set them to a good volume then took the values of OpenHab Tail.
Substitute the name of each of your speakers and the volume you want in each instance.

rule "SN_SetVolsLoud"
Item SN_SetVolsLoud received command ON
		logInfo("Sonos","Loud Volume")
		sendCommand(SN_ManCave_Volume, 29)
		sendCommand(SN_MasterBedroom_Volume, 29)
		sendCommand(SN_Lounge_Volume, 32)
		sendCommand(SN_DiningRoom_Volume, 39)
		sendCommand(SN_Hall_Volume, 27)
		sendCommand(SN_Kitchen_Volume, 27)
		sendCommand(SN_Nursery_Volume, 27)

rule "SN_SetVolsChill"
Item SN_SetVolsChill received command ON
		logInfo("Sonos","Chill Volume")
		sendCommand(SN_ManCave_Volume, 15)
		sendCommand(SN_MasterBedroom_Volume, 15)
		sendCommand(SN_Lounge_Volume, 16)
		sendCommand(SN_Hall_Volume, 14)
		sendCommand(SN_Kitchen_Volume, 14)
		sendCommand(SN_Nursery_Volume, 14)

Rule 5 Finally a rule to invert the behaviour of the mute for the slave speaker so the red/green works and so it looks the same to a user.

rule "SN_DiningRoom_MuteInvert"
Item SN_DiningRoom_MuteInvert received command
		if(SN_DiningRoom_MuteInvert.state ==ON) {sendCommand(SN_DiningRoom_Mute, OFF)}
		if(SN_DiningRoom_MuteInvert.state ==OFF)  {sendCommand(SN_DiningRoom_Mute, ON)}

Writing that lot makes it clear why noone had any chance of making them work without notes!! I have a whole pile of other stuff so would appreciate any feedback on the above.

I will try and do the other two widgets when I have time.


This is a much simpler widget which simply plays a Sonos Favourite album through the ‘master’ speaker. Note that the items for the master speaker defined above (at least) must also be defined for this widget.

In addition the widget uses a definable set of changeable icons for each album.

  1. Create a folder called ‘Sonos’ in your \conf\html folder
  2. Into this folder add your icons for each album you want to use. Each must be a png file with no spaces in the filename
  3. Add the widget to your panel
  4. Add the sonos playlist names to the widget setup list (i.e Album1-8). Note that this must match the name of a ‘Sonos Favourite’ playlist not any playlist in a music service
  5. Add the corresponding icons to Icon1-8
  6. Reference your master speaker under ‘MasterFave’
  7. Enjoy!

SonosControlWithArt is a widget which shows the album art of the master speaker (or whichever you choose to specify) along with text for current title and artist and controls for volume, next/previous and play/pause.

Because of the difficulties in controlling the volume of the entire system in Sonos I have chosen to change the two volume buttons to ‘Chill’ and ‘Loud’ settings using the rules described above.

To setup:

  1. Create a folder called ‘Sonos’ in your \conf\html folder (unless done above already)
  2. Into this folder add your icons for the buttons. Each must be a png file with no spaces in the filename. The ones I used are linked above or you can use your own. You need names called (exactly) - Back, Fwd, Pause, Play, VolDown, VolUp
  3. If not already done created items for currentalbumart, controller, currenttitle, currentartist for the speaker to drive the buttons. Also create ChillButton and LoudButton items linked to rules also as defined above
  4. Add the widget
  5. Link the items to the widget as described in the settings page
  6. Enjoy!

Updated versions of the widgets are here with the following changes:

Volume buttons in SonosControlWithArt changed to link to Chill and Loud settings as reported by @Marijn_Oudijk and @BDE

SonosSystemVolume made changes to a mistake a made to show more than one speaker and so the error reported by @maxheartrate

Several under the hood changes made too

SonosAlbumSelect.widget (1).json (7.4 KB) SonosSystemVolume.widget (2).json (21.8 KB) SonosControlWithArt.widget (2).json (10.5 KB)


I have a little Problem with the Album Select Widget.
I have installed it for Test.

Bildschirmfoto 2020-01-09 um 12.57.49

It looks like this…The icon is okay, but I can’t get the connection to the playlist in my favorites. Is my favorites the same as my sonos?

here is my items text:
String SN_DiningRoom_Faves “DiningRoom Faves” {channel=“sonos:PLAY1:RINCON_7828CA2B4D4001400:favorite”}

here is my sitemap text:
Frame label=“Sonos” {
Switch item=SN_DiningRoom_Faves label=“R&B” mappings=[“R&B”=“R&B”]

The playlist name in my sonos is:R&B

In the widget Album1 and icon1 are both named R&B.
And the MasterFave is: SN_DiningRoom_Faves (like in your example)…!?

What is wrong with my thinking…!? :wink:


now it looks like this:

The icons work very good. In Basic UI the Switches like in the picture work very good too.
The only thing which I can’t set up, is the function of the playlist switching in Habpanel widget.
What am I doing wrong?

Interesting. I wonder if it struggles to cope with the ampersand? Might be worth testing RnB or something. If not will have another look.

thank you for your reply. It works now. The name of the playlist in the widget wasn‘t right.
Now ist works.
But I have another question. This widget is only for one group of Sonos…!? How can I make it work for more Groups? Do I need three widgets for three groups?
And how do I change the Items? And sidemap?

Glad you got it working. Yes it is only for one group of Sonos - in the widget settings you set the primary speaker in a group and it will set the playlist in that speaker. I only use one group and add or remove others to that group. If you have ideas about more than one group then let me know - it quickly becomes complicated.

I guess you could do the same thing twice? Ie two widgets set to different group controller speakers. I haven’t tried this though. Let me know if it works!

What do you mean by sidemap?

I tried it for other groups and it works too.
I changed the widget name and made a new import to the habpanel.
So like it is another widget.
Then I changed the items and sitemap like in the picture.
Works very good.

I changed also the command in the widget from “SN_Dining_Faves” to the name of the other room. For example SN_Bedroom_Faves.

Continuing the discussion from Habpanel Sonos Widgets:

Hello Everyone!

I’m new to openhabian but this panel is exactly what I have been looking for! I actually got it all setup and working - thank you@scootaash!

Here though a few issues/ suggestions/ questions:

  1. I Added a Rule to see if someone changed the main speakers mute in the sonos app so red/ green is right there too:
    rule "Sonos DiningRoom Mute Changed"
	Item SN_DiningRoom_Mute changed
	if (SN_DiningRoom_Mute.state ==ON) {
} else {
  1. I think there is still an issue with the “Album” widget, as the SN_DiningRoom_Faves is hardcoded for the Albums 2-8. I changed it in the widget for me and hardcoded it to “SN_Kitchen_Faves” and then it works fine, yet it’s not dynamic yet. This could be an easy fix though :slight_smile:

  2. I have some trouble with the alignments:

    Any idea why for example ‘master’ is so left in the widget?

Also in the code (json file) everything related to this section is in one line. In Visual Code Studio I can toggle ‘text wrap’ which makes it visible on the screen, but its still very hard to read as its one big block. Any idea how it can be more easily formatted?

  1. I have sometimes the issue that the “Group Add” does not seem to work and then the switch is green/ on but the player is not added. Any idea how to improve this?

Thanks and have a great one! (sorry if the questions are silly i just installed it all this weekend for the first time :slight_smile: