hklages / node-red-contrib-sonos-plus

A set of Node-RED nodes to control SONOS player in your local network.
MIT License
75 stars 14 forks source link

Add playbacksession support #265

Closed nficano closed 3 months ago

nficano commented 1 year ago

Description

I use Sonos using the Spotify app, which prevents controlling Sonos using NodeRed. I found the Sonos api exposes a playbackSession.suspend to end the existing session, which I suspect will allow the Universal nod to regain playback control.

As an aside, is it possible to invoke arbitrary api commands? The message topic leads me to believe raw api requests are possible, but the complex example is not in source.

What node/command (topic)/state (payload)

node: Universal command: N/A state: N/A

hklages commented 1 year ago

Hi.

I use Sonos using the Spotify app, which prevents controlling Sonos using NodeRed.

I don't understand that. Can you explain in more detail? Usually you register the Spotify Music Service for your SONOS household (for instance by using the SONOS app, settings, service & voices, add a service). Having done that SONOS does not care from where the request comes. So you can use NodeRED with this package to start a Spotify playlist, album, etc.

As an aside, is it possible to invoke arbitrary api commands? The message topic leads me to believe raw api requests are possible, but the complex example is not in source.

No. There is currently only one (new SONOS) api command implemented: player.play.clip. Maybe more will come in the future. The player.play.clip is a kind of pilot. The api commands need a developer key what makes it not so user friendly.

All other sonos-plus commands are based on the original SOAP UPNP api - see

nficano commented 1 year ago

I use Sonos using the Spotify app, which prevents controlling Sonos using Node Red.

Hi @hklages, Sorry for not being clearer:

I prefer using the Spotify Connect feature to play music when I only want to play something on a single amp (I have multiple S2 amps).

Screenshot 2023-05-03 at 2 12 23 PM

I found that controlling the Sono's amps using Spotify like this prevents invoking anything related to altering the queue (for example, calling group.queue.urispotify)

I dug in a bit more and found this is the expected behavior:

A Playback session gives your app semi-exclusive control over the music playing on a group. It is semi-exclusive because no other app can change the music (either by changing the station or modifying the list of songs in the queue) without either joining your session or creating a new one and evicting your session.

The API gives you access to suspend the session. The Sono app also exposes this functionality as a button within the app:

Once the session ends,group.queue.urispotify and such all work as expected.

hklages commented 1 year ago

Understand. I opened a feature request in ts-sonos - lets see.

nficano commented 1 year ago

Understand. I opened a feature request in ts-sonos - lets see.

The codebase looks tidy, let me see if I get a chance this weekend to contribute 🙂