How to script a Spotify playlist on a Sonos speaker

I want to play a Spotify playlist on a Sonos speaker. Spotify Premium is a service in MA, Sonos speakers are there too. I can script an artist or album to play on the Sonos Play 5 (media_player.playroom_2), but not a playlist. The below shows the URI as copied from my desktop Spotify app. What am I doing wrong?

office_release_radar:
  alias: Office Release Radar Music
  sequence:
  - service: music_assistant.play_media
    data:
      entity_id: media_player.playroom_2
      media_id: spotify://playlist/abcdefghijklmnop123456789
      media_type: playlist

@mkjustuk
If you’re looking for alternatives outside of Music Assistant …

The SpotifyPlus Integration can easily handle this - note the Sonos limitations below.

Example YAML

The following will start the specified playlist on the Sonos 01 device name. See the Player Media Play Context service wiki docs for how to play other types (Audiobooks, Podcasts, Albums, Artists, etc), as well as the Player media Play Tracks service for how to play tracks and episodes.

service: spotifyplus.player_media_play_context
data:
  entity_id: media_player.spotifyplus_john_s
  context_uri: spotify:playlist:6M8n0Sp9895BXEE0MbGPde
  device_id: "Sonos 01"

Sonos Limitations

For Sonos devices, all content is played on the device using the local queue when the play context / tracks services are called. The local queue content that is currently playing will be different than what the Spotify Web API is currently reporting as playing. Unfortunately, Spotify developers disabled the ability to play context / tracks under Spotify control for Sonos devices (it’s considered a “restricted” device)! Note that the official Spotify Apps (Desktop / Web / Mobile) utilize the Spotify Embedded Client to control the device, which does not have these limitations like the Spotify Web API does.

Hope it helps!

I use this blueprint to play playlists on Sonos, works great.

Thanks both, it turns out the issue is if I reference the MA media player entity, I get nothing, but switching it for the Sonos media player entity for the same speaker, it works.