Multiple Spotify Accounts with Sonos speaker in automation

I created a NFC Tag reader to let my kids select which playlist is played on their sonos speaker.

This works pretty well with this automation:

alias: NFC play music tag url nfckizi1
description: NFC play music tag with url from nfckizi1 on Kinderzimmer 1
trigger:
  - platform: event
    event_type: esphome.music_tag
    event_data: {}
condition:
  - condition: template
    value_template: "{{ trigger.event.data.reader == nfckizi1 }}"
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.kinderzimmer_1
    data:
      media_content_id: "{{ trigger.event.data.url }}"
      media_content_type: music
    metadata: {}
  - service: light.turn_on
    target:
      entity_id: light.nfckizi1_2a0ee8_nfc_kizi1_led
    data:
      rgb_color:
        - 0
        - 0
        - 255
      flash: long
mode: queued
max: 10

Unfortunatelly most times it uses my main account which causes to interrupt the playback if a second stream starts.

So I want to select which account is used and added all accounts with his integration: Spotify - Home Assistant

But it seems that this integration currently does not support sonos speakers.
I’m able to use chromecast devices but the sonos speakers are not listed as source under media_player.spotify_accountname

I tried several attempts to workaround to be able to controll spotify accounts and sonos speakers.

I there anybody with a solution I may try?
May GitHub - music-assistant/hass-music-assistant: Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players. works?

Hey, I was thinking about doing something similar. Can you explain the above logic a bit further? Where did you get the “value_template” value from?

Ideally, spotify would be called through sonos, because sonos can play multiple streams on one account if called directly. But afaik this is not possible atm.

@mor3dr3ad
sure :slight_smile:
The NFC Tag reader decides on knows Tags to call event “esphome.music_tag” for all other “homeassistant.tag_scanned”

Using any https://open.spotify.com hyperlinks will cause the other players to stop.
Using the x-sonos-spotify:spotify media_id can only playback one singe track. I was not able find any documentation about this type of links. Does someone have any documentation?

I event tried the Spotify URI with spotify:trach:{TRACKID} spotify:playlist:{PLAYLISTID} and spotify:album:{ALBUMID} which seem sometimes tp work with parallel (at least used over on account)
Unfortunatelly spotify:user:{USERNAME}:playlist:{PLAYLISTID} is not working.

Any hint is welcome