Sonos - playing from media_Iibrary

In 2024.5.0, the play_media functions in Sonos have been enhanced. The purpose of this article is to provide that documentation while we wait for PR to be merged into the HA docs.

Sonos Favorites support notes

The favorites sensor provides the names and media_content_id values for each of the favorites saved to My Sonos in the native Sonos app. This sensor is intended for users that need to access the favorites in a custom template. For most users, accessing favorites by using the Media Browser functionality and “Play media” script/automation action is recommended.

When calling the media_player.play_media service, the media_content_type must be set to “favorite_item_id” and the media_content_id must be set to just the key portion of the favorite item.

Example service call using the item id:

service: media_player.play_media
target:
  entity_id: media_player.sonos_speaker1
data:
  media_content_type: "favorite_item_id"
  media_content_id: "FV:2/31"

or using the Sonos playlist name:

service: media_player.play_media
target:
  entity_id: media_player.sonos_speaker1
data:
  media_content_type: playlist
  media_content_id: stevie_wonder

Sonos Music Library

If you have configured a Sonos music library; you can play music from it.

Play all albums by the Beatles.

service: media_player.play_media
target:
  entity_id: media_player.sonos
data:
  media_content_type: album
  media_content_id: A:ALBUMARTIST/Beatles

Play a specific album:

service: media_player.play_media
target:
  entity_id: media_player.sonos
data:
  media_content_type: album
  media_content_id: A:ALBUM/The Wall
  enqueue: replace

Or add a specific album by a specific artist to the queue. This is useful in case you have multiple albums with the same name.

service: media_player.play_media
target:
  entity_id: media_player.sonos      
data:
  media_content_type: album
  media_content_id: A:ALBUMARTIST/Neil Young/Greatest Hits
  enqueue: add

Play all albums by a composer.

service: media_player.play_media
target:
  entity_id: media_player.porch
data:
  media_content_type: composer
  media_content_id: A:COMPOSER/Carlos Santana
  enqueue: play
2 Likes

Is there a way to play one specific track?

Nevermind, I worked it out using the media browser & log file -

action: media_player.play_media
target:
  entity_id: media_player.sonos
data:
  media_content_type: music
  media_content_id: "x-file-cifs://10.0.x.x/full/path/to/file%20url%20encoded.mp3"

based on the URL protocol, I assume this will only work with SAMBA network shares

1 Like