Trouble Playing Plex Music to Sonos from HA

I am running the latest HA (2021.8.8) with Sonos and Plex integrations configured. Plex is set up in the Sonos system and works. I have a Plex pass, Plex is remotely accessible

However I am trying to send a service call from the Developer Tools to play Plex music on a Sonos speaker but am getting a 403 error in the logs and I can’t understand why.

Service call:

service: media_player.play_media
data:
  entity_id: media_player.living_room
  media_content_type: music
  media_content_id: 'plex://{ "library_name": "Music", "artist_name": "Adele", "album_name": "25", "track_name": "Hello" }'

Error in logs:

Logger: homeassistant.helpers.script.websocket_api_script
Source: components/plex/services.py:136
First occurred: 11:33:25 PM (3 occurrences)
Last logged: 11:37:24 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: (403) forbidden; https://sonos.plex.tv/resources Forbidden

Anyone else had this problem or can suggest something else to try?

Did this work previously?

Is the Plex integration perhaps configured with a user with limited access?

This is my first time using Sonos. I bought a Symfonisk speaker to see if I want to buy in to the whole system.

Plex is set up using the admin user.

Have you set up Plex as a music service in the Sonos app?

Please check your HA log file, too.

Yes, Plex is set up in Sonos and works.

Whole log entry:


Logger: homeassistant.helpers.script.websocket_api_script
Source: components/plex/services.py:136 
First occurred: August 27, 2021, 11:33:25 PM (3 occurrences) 
Last logged: August 27, 2021, 11:37:24 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: (403) forbidden; https://sonos.plex.tv/resources Forbidden
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 371, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 571, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 856, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 698, 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 28, in wrapper
    return funct(*args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sonos/media_player.py", line 532, in play_media
    play_on_sonos(self.hass, media_type, media_id, self.name)  # type: ignore[no-untyped-call]
  File "/usr/src/homeassistant/homeassistant/components/plex/services.py", line 136, in play_on_sonos
    sonos_speaker = plex_server.account.sonos_speaker(speaker_name)
  File "/usr/local/lib/python3.9/site-packages/plexapi/myplex.py", line 220, in sonos_speaker
    return next((x for x in self.sonos_speakers() if x.title.split("+")[0].strip() == name), None)
  File "/usr/local/lib/python3.9/site-packages/plexapi/myplex.py", line 214, in sonos_speakers
    data = self.query('https://sonos.plex.tv/resources')
  File "/usr/local/lib/python3.9/site-packages/plexapi/myplex.py", line 187, in query
    raise BadRequest(message)
plexapi.exceptions.BadRequest: (403) forbidden; https://sonos.plex.tv/resources Forbidden

Figured it out! More just my lack of following basic instructions!

Went through the documentation again and followed the ‘Sonos speakers linked to your Plex account’ step.

I misunderstood that step for setting up Plex in your Sonos app when it is actually setting up Sonos in your Plex app.

1 Like

Ah good. It’s a confusing process since you need to set it up in both directions. Glad it was something that makes sense.

Thanks to your log I should be able to catch this scenario and give better feedback on what to do.