Able to play plex media on Chromecast, but get an error on sonos. Was working until recently

I have had good sucess with playing sonos reliably for some time, however a few weeks ago this stopped working. I have some time to investigate and I see this error in the logger:

Logger: homeassistant.core
Source: components/sonos/helpers.py:64
First occurred: 03:57:16 (16 occurrences)
Last logged: 04:35:03

Error executing service: <ServiceCall media_player.play_media (c:d8dbeda909e494fad9d1c4b23c6e8782): device_id=['0c2b4bd38e0097031b9d0409a9356c60'], extra=, media_type=PLAYLIST, media_id=plex://{"playlist_name": "All Music", "shuffle": 1}>
Error executing service: <ServiceCall media_player.play_media (c:fd94bed0f5d1b2c3e53226d1e9506439): device_id=['0c2b4bd38e0097031b9d0409a9356c60'], extra=, media_type=PLAYLIST, media_id=plex://{"playlist_name": "All Music", "shuffle": 1}>
Error executing service: <ServiceCall media_player.play_media (c:2d921d918fe03606e4f8eac8e44d7545): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{"playlist_name": "All Music", "shuffle": 1}>
Error executing service: <ServiceCall media_player.play_media (c:d4aab9b401506499c44a6b8a4412aa05): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{"playlist_name": "All Music", "shuffle": 1}>
Error executing service: <ServiceCall media_player.play_media (c:8e680290c2710c0491ecc7d1941919ee): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{"playlist_name": "All Music", "shuffle": 1}>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sonos/helpers.py", line 46, in wrapper
    result = funct(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sonos/media_player.py", line 558, in play_media
    plex_plugin.play_now(media)
  File "/usr/local/lib/python3.9/site-packages/soco/plugins/plex.py", line 109, in play_now
    position = self.add_to_queue(plex_media, add_next=True)
  File "/usr/local/lib/python3.9/site-packages/soco/plugins/plex.py", line 180, in add_to_queue
    response = self.soco.avTransport.AddURIToQueue(
  File "/usr/local/lib/python3.9/site-packages/soco/services.py", line 207, in _dispatcher
    return self.send_command(action, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/soco/services.py", line 515, in send_command
    self.handle_upnp_error(response.text)
  File "/usr/local/lib/python3.9/site-packages/soco/services.py", line 568, in handle_upnp_error
    raise SoCoUPnPException(
soco.exceptions.SoCoUPnPException: UPnP Error 800 received:  from 10.0.19.207

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1648, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 720, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sonos/helpers.py", line 64, in wrapper
    raise HomeAssistantError(message) from err
homeassistant.exceptions.HomeAssistantError: Error calling SonosMediaPlayerEntity.play_media on media_player.mbed: UPnP Error 800 received:  from 10.0.19.207

Also UPnP error 800 is reported from the sonos Roams IP.

I’m able to play media to the chromecast audio and android TV just fine using the same playlists, I can also play this “AllMusic” playlist from plex using the sonos connection. I can also play it from the sonos app without issue.

A lot has changed in Homeassistant in the last month, so I’m expecting this is a new method. I recently had to update and re-deploy all my nodered mobile app notifications because they ran into an API error without changing anything. No luck with re-deploying this or calling the service from the tools.

I’ve also reauthorized my sonos account to plex

In 2022.2.0, the API used to play Plex media on Sonos devices was changed from a cloud-based Plex API to the local UPnP Sonos API (see https://github.com/home-assistant/core/pull/63357). This removed the requirement for a Plex Pass to play Plex music on Sonos devices.

Can you confirm you’ve set up the Plex music service in the native Sonos app and can successfully browse/play using that? Have you tried playing back tracks or albums or only playlists?

Trying to dig into this some more

  1. I can play playlists and music albums/tracks from the media browser to Sonos/chromecast
  2. I reconnected my Plex server after deleting the integration and reauthenticating on plex.tv
  3. I cannot play playlists to chromecast now either, I get media not found when selecting a playlist using the plex uri format
  4. I can’t play even albums to chromecast and sonos using node-red or the devveloper tools

Funny example of what doesn’t work

service: media_player.play_media
data:
  media_content_type: 'music'
  media_content_id: 'plex://{ "library_name": "Music", "artist_name": "NSYNC", "album_name": "Celebrity" }'
target:
  entity_id: media_player.mbed

Not being able to play a playlist is pretty frustrating.

I’ve just re-tested casting various Plex media to both Sonos and Cast devices in my local setup using 2022.3.1 and I had no issues with tracks, albums, or playlists. Check your home-assistant.log file for more details in case a more specific reason was shown there. BTW, I’ve put in a PR to make troubleshooting this a bit easier.

Even more complex queries work fine such as this random album search:

service: media_player.play_media
data:
  media_content_id: >-
    plex://{"library_name": "Music", "libtype": "album", "sort": "random"}
  media_content_type: music
target:
  entity_id: media_player.shield_cast

Here’s the trace I get with sonos trying to play a playlist. When I play the NSYNC track or any other track, Sonos will look like it’s queued up or even pause music already playing, but won’t play the track.

I did find that the playlist title has to be exact, I have some that are autogenerated, so it seems that an extra space was added in some “BILLIONS CLUB - Spotify” vs “BILLIONS Club - Spotify”. I would like to be able to be fuzzy on the selection. However even after accounting for this issue, I still get these errors on Sonos.

Logger: homeassistant.core
Source: components/sonos/helpers.py:62
First occurred: 09:44:33 (20 occurrences)
Last logged: 14:58:21

Error executing service: <ServiceCall media_player.play_media (c:58d4c2da9a66bd2e1d7cf92147c7717f): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{ "playlist_name": "All Music" }>
Error executing service: <ServiceCall media_player.play_media (c:0fcc718cfe120bf7f31aea5471760d9b): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{ "playlist_name": "All Music" }>
Error executing service: <ServiceCall media_player.play_media (c:ffadfbd458cd57c55540f4b20f135839): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{ "playlist_name": "All Music" }>
Error executing service: <ServiceCall media_player.play_media (c:8b417e7afead4116065450e5ace8461d): entity_id=['media_player.mbed'], extra=, media_type=playlist, media_id=plex://{ "playlist_name": "All Music" }>
Error executing service: <ServiceCall media_player.play_media (c:9427939a76014231296dd7280aa1ef8d): entity_id=['media_player.mbed'], extra=, media_type=PLAYLIST, media_id=plex://{"plex_server": "0xCBF Whatbox", "playlist_name": "All Music", "shuffle": 1}>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 281, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 451, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 340, in _raise_timeout
    raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='10.0.19.207', port=1400): Read timed out. (read timeout=9.5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sonos/helpers.py", line 48, in wrapper
    result = funct(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sonos/media_player.py", line 581, in play_media
    plex_plugin.play_now(media)
  File "/usr/local/lib/python3.9/site-packages/soco/plugins/plex.py", line 109, in play_now
    position = self.add_to_queue(plex_media, add_next=True)
  File "/usr/local/lib/python3.9/site-packages/soco/plugins/plex.py", line 180, in add_to_queue
    response = self.soco.avTransport.AddURIToQueue(
  File "/usr/local/lib/python3.9/site-packages/soco/services.py", line 207, in _dispatcher
    return self.send_command(action, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/soco/services.py", line 487, in send_command
    response = requests.post(
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 532, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='10.0.19.207', port=1400): Read timed out. (read timeout=9.5)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1654, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1673, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 931, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 721, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sonos/helpers.py", line 62, in wrapper
    raise SonosUpdateError(message) from err
homeassistant.components.sonos.exception.SonosUpdateError: Error calling SonosMediaPlayerEntity.play_media on media_player.mbed: HTTPConnectionPool(host='10.0.19.207', port=1400): Read timed out. (read timeout=9.5)

I’ve narrowed it down. I’m sorry for the confusing back and forth, I had two issues come up at the same time

  1. My auto playlist tool actually created two copies of each playlist recently. I hadn’t noticed and this probably was causing the issue with Chrome cast
  2. The issue with Spotify is actually with playing dynamic playlists with a huge number of items. My collection has grown exponentially since I started using the sonos as an alarm, so 54,000 tracks in a playlist does not work. It would be nice if there was some kind of responce indicating "playlist length exceeded.
    I don’t even get an error when trying to play it from the sonos app, it just dies, and I don’t ever use the app so I wasn’t sure how it should have behaved.

Gotcha. Yeah, (2) is hitting a limitation on the Sonos side that’s going to fail with a non-specific error. Queuing up 54k tracks is a lot and it seems reasonable to me that it’s choking on that playlist.