Trying to play Spotify album on Sonos

Enqueueing is ok for me. But maybe play immediately should be implemented too. To make it a bit more polished.

I will have a look at the shuffle example, but I guess I will no be able to contribute to the media_player that easily.

I updated the custom integration, now enqueue: true is no longer required.

Let me have a go at adding media_player support for repeat mode.

great, thank you. Let me know if I can help…

Setting of the repeat mode is now merged for 0.117: https://github.com/home-assistant/core/pull/41735

1 Like

Great… thanks a lot :slight_smile:

For my reference, is your Sonos system on S1 or S2?

It‘s all on S2

1 Like

Just tried it with 0.117 and it works!
Thanks @amelchio

For reference, my automation for magic cards:

- alias: Play Sonos Item from Magic Cards
  trigger:
    - platform: event
      event_type: magic_card_scanned
  condition:
    condition: template
    value_template: "{{ 'spotify:' in trigger.event.data.card_uri }}"
  action:
    - service: media_player.play_media
      data_template:
        entity_id: media_player.sonos_kitchen
        media_content_id: "{{ trigger.event.data.card_uri }}"
        media_content_type: music

1 Like

Yea just done the same thing after hours of “wasted” research! It works beautifully! Thank you

Hi guys! I have a RFID jukebox up and running, but it seems impossible to play the music on my Sonos. I was wondering if it would be possible to alter this YAML to play the music on my kitchen Sonos:


alias: NFC jukebox
description: Build our own NFC jukebox
trigger:
  - platform: event
    event_type: tag_scanned
condition:
  - condition: template
    value_template: '{{ trigger.event.data.tag_id in tags }}'
  - condition: template
    value_template: '{{ trigger.event.data.device_id in media_players }}'
action:
  - variables:
      media_player_entity_id: '{{ media_players[trigger.event.data.device_id] }}'
      media_content_id: '{{ tags[trigger.event.data.tag_id].media_content_id }}'
      media_content_type: '{{ tags[trigger.event.data.tag_id].media_content_type }}'
  - service: media_player.play_media
    data:
      entity_id: '{{ media_player_entity_id }}'
      media_content_id: '{{ media_content_id }}'
      media_content_type: '{{ media_content_type }}'
  - delay: '2'
mode: single
max_exceeded: silent
variables:
  media_players:
    8e66dd521db611eb80e95bdaeaa39894: media_player.spotify_svanjr
  tags:
    04-DE-13-BA-58-49-80:
      media_content_id: 'spotify:album:2DGzTm2R2v3G0IjnxXtP3Y'
      media_content_type: album
    77-AC-8F-A7:
      media_content_id: 'spotify:playlist:37i9dQZF1DX0q1RHoDiZBg'
      media_content_type: playlist
    FA-66-EA-80:
      media_content_id: 'spotify:album:0xtOxVRRaA0kW7X4PlbtuP'
      media_content_type: album

You do not describe what goes wrong (like any error messages) but I think you should at least use media_content_type: music.

@amelchio

Hey there! Play by URI isn’t working for me. Here is what I am trying:

service: media_player.play_media
entity_id: media_player.master_bedroom
media_content_id: https://open.spotify.com/album/1bt6q2SruMsBtcerNVtpZB
media_content_type: music

Here is what I see in my logs:

2020-11-10 22:19:49 ERROR (SyncWorker_48) [homeassistant.components.sonos.media_player] Error on play_media with UPnP Error 800 received:  from 192.168.1.103

Any tips?

That error is being investigated her: https://github.com/home-assistant/core/issues/42538

You can help by adding information about your setup.

1 Like

The UPnP Error 800 should now be fixed in Home Assistant 0.118.

This may very well be impossible, but I figured it’s worth an ask.

Is there any way to use HA to command the Sonos device play Spotify Connect? In other words, not command it to play a specific album on Sonos, but have it play what would be the same as pressing Play in the Spotify app.

If I already started playing something on that Sonos speaker through the Spotify app and then pause it, then media_player.media_play_pause does indeed resume playing the Spotify music on the Sonos speaker. But if I then play another source (for example TV on my beam Sonos speaker) and then pause it… media_player.media_play_pause won’t do anything because that speaker is in “TV” source instead of the Spotify connect source. Any ideas how to get it back to the Spotify source without using the Spotify app or without commanding Alexa to “play spotify”?

Sorry, there is no support for actions where you otherwise have to use the Spotify app.

Thanks for your response. May be slightly off-topic but can you think of a way to call “Alexa play spotify” on the speaker without actually saying it verbally? Somehow Alexa does have the API (or other) access to play Spotify Connect music on the Sonos. I’ve been searching myself and haven’t found a way to do that.

When trying to play a playlist with saved podcasts in I get an error message.

Error on play_media with UPnP Error 701 received: Transition not available from 192.168.76.124

When playing a playlist with normal songs in it it works perfectly.

This is how my code look likes.

      - service: media_player.play_media
        data:
          entity_id: media_player.kok
          media_content_id: https://open.spotify.com/playlist/50Z5z6ISa97VBrY1qRqEDC
          media_content_type: music

is there any news here? Im converting from HS4 to HA and this is the last bit of the puzzle to shut down my HS4:)

If you notice an error, create a GitHub issue with all the requested details and we will try to fix it. Feel free to tag me as I might not see it otherwise.