Assistance Needed with openHAB Sonos Binding for Playing Playlists and Stations

Hello Forum Members

A persistent cold has given me some downtime, which I’ve used to transition from my previous MQTT-based solution to the openHAB binding for Sonos. My goal is to simplify my setup, and while I’ve had some success, a few challenges remain.

Current Setup

I have five Sonos speakers in my system, primarily used for streaming music. I’ve predefined the standard content to play in a YAML file. While basic controls such as volume adjustment, pause, play, and stop work seamlessly, I’ve encountered significant difficulties when trying to play specific content.

What I’m Trying to Achieve

I’d like to be able to play:

  • Playlists from Tidal
  • Playlists from Spotify
  • Sonos Radio Stations

I know it’s possible to save playlists as favorites in the Sonos app, but the distinction between “Sonos Favorites” and general “Favorites” is a bit unclear.

Issues Encountered

Despite several attempts, I’ve been unable to play any of the desired content. For example:

  • Sending commands to the playuri channel using URIs such as x-sonosapi-radio:2997?sid=303&flags=0&sn=9 hasn’t worked as expected.
  • Using predefined favorites, playlists, or radio channels doesn’t yield the desired results either.

Configuration Details

Here are some of the items I’ve defined for controlling Sonos:

Switch Sonos_TV_Rummet_Play_Queue             "Play queue [%s]"                   <switch>           (G_Sonos) {channel="sonos:Arc:Sonos_TV_Rummet:playqueue"}       // Play the songs from the current queue
String Sonos_TV_Rummet_Favorite               "Play favorite [%s]"                <text>             (G_Sonos) {channel="sonos:Arc:Sonos_TV_Rummet:favorite"}        // Play the given favorite entry. The favorite entry has to be predefined in the Sonos Controller app
String Sonos_TV_Rummet_Radio                  "Play radio [%s]"                   <text>             (G_Sonos) {channel="sonos:Arc:Sonos_TV_Rummet:radio"}           // Play the given radio station. The radio station has to be predefined in the Sonos Controller app
String Sonos_TV_Rummet_Playlist               "Play playlist [%s]"                <text>             (G_Sonos) {channel="sonos:Arc:Sonos_TV_Rummet:playlist"}        // Play the given playlist. The playlist has to predefined in the Sonos Controller app
String Sonos_TV_Rummet_Play_Uri               "Play URI [%s]"                     <text>             (G_Sonos) {channel="sonos:Arc:Sonos_TV_Rummet:playuri"}         // Play the given URI
String Sonos_TV_Rummet_Tunein_Station_Id      "Tunein station ID [%s]"            <text>             (G_Sonos) {channel="sonos:Arc:Sonos_TV_Rummet:tuneinstationid"} // Provide the current TuneIn station id or play the TuneIn radio given by its station id

Documentation Challenges

The official documentation on the openHAB website does include an example, such as playing a German radio station:

Sonos_PlayUri.sendCommand("x-rincon-mp3radio://https://streams.egofm.de/egoFMBW-hq")

This example works, but I’ve found the number of available channels and their uses somewhat confusing. I’ve been unable to locate examples or clear guidance on playing playlists or streaming services like Tidal or Spotify.

Request for Help

I’m reaching out to see if anyone else has successfully configured openHAB to play Tidal or Spotify playlists and Sonos radio stations. Are there specific URIs, item configurations, or approaches I might have overlooked? If you’ve managed to make this work, I would be incredibly grateful for any tips or examples you could share.

Thank you so much for your time and assistance!

Warm regards

In the (Windows) Sonos app, I “added” a playlist “to Sonos playlist”:


The next window is a bit confusing, but you need to click “New playlist”:

This opens up a pop-up, in which you name your new playlist:
image

Now, this playlist is visible here:

See:

I have a playlist, which (in a JavaScript rule) I can start with:

items.getItem("Sonos_de_Beweeglijke_Playlist").sendCommand("Millie")

Where Sonos_de_Beweeglijke_Playlist is of course the item linked to the Play Playlist channel of my Sonos Move thing. Mind you, this is an advanced channel.


I haven’t tried playing radio stations, though…

So for radio channels, I expected channel Radio to do the trick, but I must not have configured my favorite radio channels “correctly”. But considering my radio channels are all located in “Sonos favorites”:


Apparently, I can rename these “favorites”. But let’s use a simple one: “Klara”.

I tried channel Favorite, and this JavaScript code:

items["Sonos_de_Beweeglijke_Favorite"].sendCommand("Klara")

And it works!

Thanks @ErikDB for your kind help.

Playing Sonos Favorites and Sonos Playlists works as you described. I need to define either a Sonos Favorite or a Sonos Playlist for everything that I want to stream and it seems to cover all my needs actually! So. thanks a lot!

Thinking about this afterwards, I assume just using the ‘Favorite’ route would also work for playlists… That way, you would not need to add a playlist.

But I haven’t tested that. I just discovered that way yesterday myself :slight_smile:

Thanks, @ErikDB!

I’m currently testing that out. In Sonos Favorites, I have a TIDAL playlist, and it seems to be working well, it’s a great playlist, by the way. In Sonos Playlists, I’ve saved all the songs from the TIDAL playlist. Keeping it as a Favorite has the advantage of automatically updating whenever TIDAL updates the playlist, unlike the static version in Sonos Playlists.

I’m really happy with the Sonos Binding in OpenHAB overall. However, one thing that bothers me is the UPnP setup. To get those pesky UDP broadcasts working, I had to add an extra network interface for the IOT VLAN on my OpenHAB virtual server. The IOT VLAN is where all my less secure IoT devices are located. It’s not an ideal solution security wise, it feels like a workaround.

Now that the Sonos devices are already discovered, I’m wondering if I can remove the IOT VLAN interface and rely on routing traffic through the firewall instead. Has anyone tried this before and can share their experience? My concern is whether the UDP broadcasts will still be necessary for future functionality.

Hello,

Great tip in this topic, thanks!

In my openHAB config I used the Sonos Radio channel. That did not work any more. Now I discovered that using the Favorite channel I can also play the radio stations (which have to be in the Sonos favorites).

I’m afraid I can’t help you there. I have no idea what UPnP or UDP means… :slight_smile: