I thought this integration was an option https://www.home-assistant.io/integrations/spotify/ ?
But Spotify acts as a media player device, not as a source.
I have used https://github.com/jishi/node-sonos-http-api for magic cards (runs as a docker container)
Thinking about turning the nodes sonos http api into a HA addon.
If you add the Spotify album to My Sonos it should appear as a source in Home Assistant.
I’ve done that before, add to My Sonos so that HA recognizes the playlist (which can be an album). But I don’t know if I want 50 albums in My Sonos just for the HA integration. A great advantage is that it can be anything Sonos supports.
Not having to add to My Sonos would be one less step. Although you’ll need to get the album ID from Spotify doing it the other way. So that’s also cumbersome.
Even in My Sonos there is a limit - I wanted to use this method to add some albums and it seems there is a limit around 60-70 favorites in My Sonos.
The only solution I see is to integrate the node sonos http api project into Home Assistant as it allows to chose spotify albums for Sonos via the spotify URI. If you find the time to do this @DavidDeSloovere it would really be awesome!
In the meanwhile I found a workaround involving a spotify connect device other than the Sonos speaker (e.g. echo dot).
See my post on this thread: Playing Spotify playlist on Sonos triggered by automation
@DavidDeSloovere @rcma @patrickse
I just added the ability to enqueue Spotify albums to the Sonos integration. You can try it out as a custom integration with HACS, see https://github.com/amelchio/sonos
- service: media_player.play_media
data:
entity_id: media_player.office
media_content_id: https://open.spotify.com/album/1bt6q2SruMsBtcerNVtpZB
media_content_type: music
- service: media_player.play_media
data:
entity_id: media_player.office
media_content_id: spotify:track:7rPzEczIS574IgPaiPieS3
media_content_type: music
enqueue: true
Note, so far it only adds to the queue; you will have to make another service call to make it play.
That really sounds great. But why is the media_entity_id not in the form of
spotify:album:1bt6q2SruMsBtcerNVtpZB
. Anyway, sounds awesome and I will test it tomorrow.
I am building an automation where my kids can start a random paw patrol album on Spotify playing on their Sonos speakers by pressing a push button.
That form works as well, I listed two examples
I am working on making it play immediately when dropping enqueue: true
but I will be busy with other things for a few days.
Started wondering whether it should be media_content_type: music
or media_content_type: playlist
like in the OP. I am not quite sure what each is supposed to mean.
Anyway. Great work. thanks a lot. I will try to embed it into my automation this weekend.
Got my scripts working. It´s a mixture of the Tags example with a random selection of an album from artist. My kids are happy, they can now switch between playing Paw Patrol and Super Wings and everytime a card is scanned it will play a random story…
There´s only another thing I am still missing. Maybe you can give me a hint how I can achieve this. My wife always activates the “repeat mode” on the sonos speaker. I haven´t found a way to disable repeat mode by using scripts or automation…
Do you have an idea where to start?
@amelchio don‘t want to stress you. But I forked your repo and implemented the feature for my installation. I‘ve implemented in a Sonos service like this
sonos.set_play_mode
With the data field like this
data:
entity_id:
play_mode: NORMAL
I guess that this is not the best way to do it. If you point me in a direction how the service should be called and if you‘re open for contributions, I could finalize this feature on my own.
What do you think?
Great that you got it working! Is enqueueing okay for you or are you missing a way to play immediately?
There is already a shuffle mode so I think you should implement repeat mode orthogonal to that. There is a repeat
property in pysonos that you can use: https://github.com/amelchio/pysonos/blob/a63c4edbce8867f747fd3f6fd2682b8cfb9577d0/pysonos/core.py#L439-L453
However, I think repeat is fairly common so it should probably be implemented at the media_player
level which is a bit more work.
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
Great… thanks a lot
It‘s all on S2
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