SONOS: The easiest way of setting playlist or radio streams

Hi all,

while researching I’ve seen a lot of threads discussing how to set e.g. Spotify playlists or radio streams in Sonos using HA. Most of them where quiet “complicated” using the media_content_id attribute from the play_media function while looking up the URL from the local Sonos API. As far as I know this does not even work with Spotify playlist, since they don’t offer a native URL.

Once I noticed in the dev-state, that every Sonos component had a Source List (marked blue):

and that this source list was completely identical to my Sonos-Favorites (on the right):

I just tried to use the select_source function from the Media Player component using the string I saw in the dev-states and what shall I say, it worked!

One example from a script of mine:

      - service: media_player.select_source
        data:
          entity_id: media_player.kinderzimmer
          source: 'KiRaKa - KiRaKa - Der KinderRadioKanal des WDR.'

I tested it for radio streams as well as for Spotify playlist and everything worked. I guess its working for every kind of service Sonos supports, as long as you have it in your Sonos favorites. This should also work in scenes, but I have not tested that yet.

So, whenever you want a playlist or stream to be available easily in HA, just add it to your Sonos favorites, look up the string and your it as a source! :slight_smile:

3 Likes

The Sonos component now has support for favorites in the ‘Source’

I’m not sure if this is all encompassing but have a look as it may help simplify your scripts.

Hey, do you know what version this was added in (basically is it in a release version yet)? I’ve been concentrating on other things and my HASS is still on 0.28.x (and not broken), but this feature will probably encourage me to update and deal with all the breaking changes I’ve avoided so far.

Great work here…

Its on my todo list

Anyone worked out input sliders for volume control for Sonos on the main screen? (Not the popup?)

1 Like

It is. I’m on .35 and it’s there.

2 Likes

I’m on 0.35.2. Actually all updates worked quiet good for me in the last weeks.

1 Like

This is awesome, thanks! I have just been resuming what was last played when I get home, now I can control what is played at what time :slight_smile:

Doesn’t seem to work with Spotify playlists, even if they are in your Sonos favourites and appear in dev-state

1 Like

I tested it with a Spotify playlist when I created this thread and it worked.
But actually I just noticed, that it failed today in an automation rule. Strange!

1 Like

Tried it for the first time today, and, running 0.36.1, this does not work for Spotify playlists. It works with Google Play Music and TuneIn though.

Here’s what can be found in the log when trying to select a Spotify playlist:

17-01-23 20:15:04 soco.services: UPnP Error 714 received: Illegal MIME-Type from 192.168.1.41
Traceback (most recent call last):
  File "/home/pat/.homeassistant/deps/soco/services.py", line 408, in send_command
    self.handle_upnp_error(response.text)
  File "/home/pat/.homeassistant/deps/soco/services.py", line 469, in handle_upnp_error
    error_xml=xml_error
soco.exceptions.SoCoUPnPException: UPnP Error 714 received: Illegal MIME-Type from 192.168.1.41
17-01-23 20:15:04 homeassistant.core: Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 1054, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/media_player/__init__.py", line 364, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/media_player/sonos.py", line 845, in select_source
    self._player.play_uri(src['uri'], src['meta'], src['title'])
  File "/home/pat/.homeassistant/deps/soco/core.py", line 104, in inner_function
    return function(self, *args, **kwargs)
  File "/home/pat/.homeassistant/deps/soco/core.py", line 483, in play_uri
    ('CurrentURIMetaData', meta)
  File "/home/pat/.homeassistant/deps/soco/services.py", line 181, in _dispatcher
    return self.send_command(action, *args, **kwargs)
  File "/home/pat/.homeassistant/deps/soco/services.py", line 408, in send_command
    self.handle_upnp_error(response.text)
  File "/home/pat/.homeassistant/deps/soco/services.py", line 469, in handle_upnp_error
    error_xml=xml_error
soco.exceptions.SoCoUPnPException: UPnP Error 714 received: Illegal MIME-Type from 192.168.1.41
1 Like

Did you resolve this? I’m getting the same error.

In my research I found that someone else (@arsaboo) had this issue, but resolved it by updating to 0.32.3. Here I am having the same issue on 0.38.3!

The service call that is giving me grief (with sonos speakers) is:

service: media_player.play_media
data:
  entity_id: media_player.living_room
  media_content_id: 'http://cbc_r1_mtl.akacast.akamaistream.net/7/35/451661/v1/rc.akacast.akamaistream.net/cbc_r1_mtl'
  media_content_type: channel
1 Like

Hi, I have managed to do it, very dirty though :smiley:
Put together with automations and input sliders and some code from @pautomate

https://hastebin.com/zilugayena.pl

You can see my updated automation that work perfectly with Sonos on my repo here

This is exactly what I was looking for… however I am struggling to get it working…

I have attempted this…

- alias: "Play Jazz"
  trigger:
    platform: state
    entity_id: binary_sensor.switch_158d0001103c82
    to: 'on'
  action:
    - service: media_player.select_source
      data:
        entity_id: media_player.kitchen
        source: 'Jazz Classics'

then I tried this…

- alias: "Play Jazz"
  trigger:
    platform: state
    entity_id: binary_sensor.switch_158d0001103c82
    to: 'on'
  action:
    - service: media_player.play_media
      data:
        entity_id: media_player.kitchen
        source: 'Jazz'

Am I missing anything to get this playlist to play when I hit the button? do I need to do

find playlist, set volume, then media player play as three operations?

Any help would be much appreciated!!

1 Like

Any updates?

1 Like

This works.

1 Like

Is that a Spotify playlist you are trying to play? There is a current bug that makes selecting a Spotify source result in an error. For me, most of my playlists are Spotify :frowning: I gave up and just installed an Alexa-Sonos skill from Github instead. :slight_smile:

Sorry. I’m not sure about Spotify as I don’t use that.

I’m new to sonos but what happens if you put a Spotify Playlist URL in source?

I have spent multiple hours trying to get a spotify sleep playlist to play through my sonos speakers. It is kind of ridiculous how difficult it is to do such a simple thing. Back before using home assistant, I just used the node-http-sonos-api by Jishi on github and it was so easy… Is there really no solution to this problem yet as it seems like most people with Sonos would want to be able to send a playlist directly to it…