fondberg / spotcast

Home assistant custom component to start Spotify playback on an idle chromecast device as well as control spotify connect devices
Apache License 2.0
645 stars 94 forks source link

Better support for Sonos BEAM 2 #376

Open tYn0 opened 1 year ago

tYn0 commented 1 year ago

Bug Ticket

Describe the bug

Not sure if this is a bug or just needs to be better supported but here is what I found regarding Spotcast and Sonos BEAM 2 support. Beam has 3 modes in which it operates:

TV mode: As Beam is a soundbar it can play sounds from TV via HDMI. When Beam is used in this mode it is not registered on Spotify Connect so it is not shown in available devices on Web Spotify Player but it is shown under available devices in desktop Spotify app. Spotcast can't play music on Beam when Beam is in this mode.

State attributes:

source_list:
  - TV
group_members:
  - media_player.beam
volume_level: 0.33
is_volume_muted: false
media_content_id: x-sonos-htastream:RINCON_542A1BDE55EE01400:spdif
media_content_type: music
media_title: TV
source: TV
shuffle: false
repeat: 'off'
queue_size: 1
device_class: speaker
friendly_name: BEAM
supported_features: 981567

Spotify Connect mode: In this mode Beam works great with Spotcast. It is displayed in available devices on the Web Client and desktop app as well. Only way to switch Beam to this mode is to use desktop app.

State attributes:

source_list:
  - TV
group_members:
  - media_player.beam
volume_level: 0.33
is_volume_muted: false
media_content_id: >-
  x-sonos-vli:RINCON_542A1BDE55EE01400:2,spotify:c9c9de108d23193635dbdd9a675a83b0
media_content_type: music
media_title: Magyarország
source: Spotify Connect
shuffle: true
repeat: 'off'
queue_size: 1
device_class: speaker
friendly_name: BEAM
supported_features: 981567
media_duration: 238
media_position: 0
media_position_updated_at: '2023-02-10T20:41:25.193519+00:00'
media_artist: Alestorm
media_album_name: Seventh Rum of a Seventh Rum (Deluxe Version)
entity_picture: >-
  /api/media_player_proxy/media_player.beam?token=REDACTED

Sonos Spotify Connect mode This is a weird one. To switch to this mode you have to use media_player.play_media service. In this mode Beam is not registered on Spotify Connect (not shown under devices on Web Player but is shown on desktop app) and it is not synchronized with Spotify at all - no current track, no volume level synchronization etc. Spotcast can't play music on Beam when Beam is in this mode

Service call:

service: media_player.play_media
data:
  media_content_id: https://open.spotify.com/track/1nsFFVu0kypnIMsJBtIHYT?si=df35a641f223469d
  media_content_type: song
  enqueue: play
target:
  entity_id: media_player.beam

State attributes:

source_list:
  - TV
group_members:
  - media_player.beam
volume_level: 0.33
is_volume_muted: false
media_content_type: music
media_position: 0
media_position_updated_at: '2023-02-10T20:50:46.110373+00:00'
shuffle: true
repeat: 'off'
device_class: speaker
friendly_name: BEAM
supported_features: 981567
media_content_id: x-sonos-spotify:spotify%3atrack%3a1nsFFVu0kypnIMsJBtIHYT?sid=9&flags=8232&sn=2
media_duration: 249
media_title: Bite the Hook Hand That Feeds
media_artist: Alestorm
media_album_name: Seventh Rum of a Seventh Rum (Deluxe Version)
queue_position: 2
queue_size: 2
entity_picture: >-
  /api/media_player_proxy/media_player.beam?token=REDACTED&cache=03cf653118243601

Conclusion: The main takeaway is that the Beam is always shown under availalble devices in desktop app irregardless of the mode in which Beam currently is and the only way to switch Beam to Spotify Connect mode is to use the desktop app which is rather cumbersome. As Beam is always shown in the desktop app there must be a way to switch Beam Spotify Connect mode via code.

Troubleshooting

Make sure to validate all the elements before submitting the ticket (Exception to the steps marked as optional)

Environment

fcusson commented 1 year ago

@tYn0 Sonos has it's own very proprietary and unconventional way of connecting to Spotify. The Sonos integration is supposed to work out of the box with Spotify (don't know, don't have Sonos product). His there a reason you are trying to use Spotcast specifically with it?

tYn0 commented 1 year ago

That's the last mode I was describing - using media_player.play_media - this plays the requested Spotify song/playlist but it is not synchronized to Spotify Connect at all so it is not possible to control the volume/song etc. via Spotify apps or via media_player.spotify entity

tYn0 commented 1 year ago

Also, I didn't find a way to transfer current playback to Beam using the method above

fcusson commented 1 year ago

ok I see. Saddly, not having a sonos device, it's impossible for me to work on it. I'll mark your ticket has help wanted, but this would probably imply integrating the Sonos API in the project, so I don't know how quick someone would arrive with a PR for that.

LZStealth commented 1 year ago

I may be able to provide some additional info on this.

As @tYn0 did mention, using Sonos this doesn't 'link' with Spotify and essentially copies the playlist to Sonos keeping it separate.

I've been trying to integrate with my Sonos:1 also allowing me to transfer music around my house, but this will only succeed when using the deviceID (this should allow it to be transferred to your Beam... sometimes). It appears that only devices noted as 'Google Cast' can be played to using the name (or at least in my testing).

With this, the deviceID for the Sonos can only (easily) be found by using a browser version of Spotify by inspecting the network, which is then presented with a URL like below.

This is triggered by changing the target device to the Sonos and should give a URL something like the below. https://gew1-spclient.spotify.com/connect-state/v1/connect/transfer/from/<device1>/to/<sonosdevice>

However while this works. It has had one issue which I've experienced from time to time. If the device has not been used within the past 3 devices it will not play and the device has to be re-discovered by a Spotify client, meaning you might as well just open Spotify. As a side note this has not occurred when just transferring the music around my house so may also appear to be partly session based, I will need to test more to confirm this.

The issue I've come down to so far is around Spotify device discovery and this past 3 device thing, which may be bypassable by running a device search from HA. How to do that currently? I don't know is the short answer, but hope this helps.

tYn0 commented 1 year ago

In my experience using Spotcast to transfer playback to BEAM only works when the soundbar is already in the "Spotify Connect" mode - Play song on desktop app, change source via desktop app to BEAM (this sets it to Spotify Connect mode - second one I was describing in the original post).

Now you can transfer playback via Spotcast to any device including BEAM but only until BEAM is in this mode - if you start watching TV BEAM switches to TV mode and you can no longer use Spotcast to transfer playback or play music on BEAM

smarthomejunkie commented 1 month ago

In my experience using Spotcast to transfer playback to BEAM only works when the soundbar is already in the "Spotify Connect" mode - Play song on desktop app, change source via desktop app to BEAM (this sets it to Spotify Connect mode - second one I was describing in the original post).

Now you can transfer playback via Spotcast to any device including BEAM but only until BEAM is in this mode - if you start watching TV BEAM switches to TV mode and you can no longer use Spotcast to transfer playback or play music on BEAM

Same experience here.

s00500 commented 3 weeks ago

Related discussion: https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues/28