SpotifyPlus Integration

Is this integration also supposed to generate a Spitify Connect device? I’d like to select HASS as a player in the Spotify App.

@petwri
No, SpotifyPlus is just a media player integration. It only detects existing Spotify Connect devices.

1 Like

@NicoLeOca
Thanks for bringing this to my attention.

There appears to be a bug in the spotifyplus.player_media_play_track_favorites service when the selected device is a Sonos device.

The Sonos device support is fairly new, so still working out a few kinks. I should have this fixed within a day or two - will keep you posted.

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.48 ] - 2024/08/10

  • Updated service player_media_play_track_favorites to transfer the Spotify users track favorites (200 max) to the queue for playing. Added support for playback on Sonos devices.

Sonos Limitations

For Sonos devices, the tracks (up to 200 max) are loaded to a local queue on the Sonos device and played from there. This can be a lengthy operation, depending on the number of track favorites that you have. It takes about 1 second to load 5 tracks, give or take based upon the speed of your network.

@NicoLeOca
This will fix the issue of playing track favorites on a Sonos device.

1 Like

@thlucas
Works very well, thank you

Two questions for you, if you may:
How does it pick the tracks to play amongst the full list?
Why can we pick 200 when the service tells us that we can only pick from 20 to 50?

Lastly, this integration seems to be able to replace Spotcast which is actively develop anymore, since the main owner passed away.
[EDIT] no it can’t really, as the way you add to clue does not use spotify connect at all. As a heavy Sonos user, there are consequences I need to investigate.

@NicoLeOca
The Spotify Web API Get Users Saved Tracks picks the tracks to return.

The SpotifyPlus Get Track Favorites service is used to retrieve the tracks, which calls the underlying Spotify Web API Get Users Saved Tracks endpoint. The Spotify Web API endpoint supports paging, which allows you to retrieve up to 50 tracks per request. The SpotifyPlus integration service supports auto-paging via the limit_total argument, which will retrieve all available items up to the limit specified (which is 200 for the Get Track Favorites service).

Check out the Sonos Brand Limitations wiki page for more information on Sonos limitations.

I’m having issues with finding audio devices. When I first installed this extension (v1.0.48) it listed all of my devices. And the first few times it worked. But then I selected a device, and the entire list disappeared. The only thing left in the list is “Home Assistant” which always throws an error when it tries to connect. Any assistance would be greatly appreciated.

@Ibgeek
Any errors in the system log related to Spotify or SpotifyPlus?
Have you installed any new integrations, or updated HA since devices last appeared?

You might want to open a new issue to track this as well.

1 Like

No errors in the log. This is a new install so there have been a lot of new integrations since the issue occurred but none between when it worked and when it didn’t. (was only one day)

I found that if I select a device using the Chromecast integration, then go to SpotifyPlus, it will have that option available. But only that one. I will open an issue. Just didn’t want to cause a fuss if the issue was newb error.

Ahhhhhh - ChromeCast; enough said. I suspect that the device is going into “sleep” mode or inactive state with Spotify Connect. Unfortunately, they do not show up after this as available devices in the Spotify Web API - this is why they are removed from the HA media player drop down list. The integration reports what the Spotify Web API says is available, and per the API the devices are no longer available.

With that said, you might be able to make them active again by utilizing the SpotifyPlus Zeroconf Device Connect service. You could set up an automation script that runs every 10 minutes to keep the device(s) “alive”.

For example:
Use the Zeroconf Discover Devices service to find the device IP info and CPath values.

service: spotifyplus.zeroconf_device_connect
data:
  entity_id: media_player.YOURSPOTIFYPLUSENTITYID
  host_ipv4_address: YOURDEVICEIPADDRESS
  host_ip_port: YOURDEVICEIPPORT
  cpath: YOURDEVICECPATH
  use_ssl: false
  username: [email protected]
  password: yourpassword
  loginid: yourspotifyloginid
  pre_disconnect: true

I do not have a ChromeCast device to test with, so not sure if the above will work - but it’s worth a shot.

1 Like

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.49 ] - 2024/08/16

  • Updated service zeroconf_device_connect to correctly process Spotify Connect requests for token type authorization_code devices. This requires you to setup a seperate OAuth2 authorization access token outside of Home Assistant in order to activate these devices. This (currently) only affects Sonos devices, as they are the only manufacturer (that I am aware of) that implements the authorization_code token type. More information can be found in the wiki documentation.
  • Added service get_spotify_connect_device to Get information about a specific Spotify Connect player device, and (optionally) activate the device if it requires it.
  • Updated service player_resolve_device_id with deprecated status, as the get_spotify_connect_device service offers the same (and more) functionality.
  • Updated service descriptions for services that specify a limit argument.
  • Added sortResult argument to the various services that return lists that can be sorted. If True (default), result items are sorted by name prior to returning to the caller; otherwise, results are left in the order that the Spotify Web API returned them.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.83.

This release brings new functionality for Sonos devices integration. There is some manual work involved with setting up the Sonos support though. This involves manually creating a Spotify authorization token (with the help of a Python script). Check out the OAuth2 Token for TokenType=Authorization_Code Devices wiki document on how to set it up.

Note that it is OK if you don’t want to setup the Spotify authorization token - you can still transfer playback to Sonos devices, but they will be under control of the Sonos local queue (and not Spotify Connect). The Spotify authorization token allows you to transfer playback to the Sonos device under the control of Spotify Connect.

Hope it makes sense. Please let me know if you have questions - just make sure you read the OAuth2 Token for TokenType=Authorization_Code Devices docs first, as it goes into detail how the functionality works.

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.50 ] - 2024/08/18

  • Updated service select_source to refresh the Spotify Connect device list prior to selecting the new source.
  • Updated service player_transfer_playback to refresh the Spotify Connect device list prior to transferring playback to the target device.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.84.

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.51 ] - 2024/08/18

  • Updated service player_transfer_playback to check Sonos transport status after transferring playback to the target device, and play / pause the transport as designated by the play argument.

Apologies for the back-to-back releases, but we are trying to nail down some Sonos-related issues.

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.52 ] - 2024/08/19

  • Changed storage location of authorization Token Cache file to prevent data loss on version updates. The file was moved from \config\custom_components\spotifyplus\data\tokens.json to \config\.storage\spotifyplus_tokens.json, which will allow it to persist between version updates. Note that you can simply copy the Token Cache file from the old location to the new location prior to this update, so that you don’t have to re-run the AuthTokenGenerator.py script again.
  • Added service remove_audiobook_favorites to remove one or more audiobooks (or the currently playing audiobook) from the current user’s ‘Your Library’ favorites.
  • Added service remove_episode_favorites to remove one or more show episodes (or the currently playing episode) from the current user’s ‘Your Library’ favorites.
  • Added service remove_show_favorites to remove one or more shows (or the currently playing show) from the current user’s ‘Your Library’ favorites.
  • Added service save_audiobook_favorites to save one or more audiobooks (or the currently playing audiobook) to the current user’s ‘Your Library’ favorites.
  • Added service save_episode_favorites to save one or more show episodes (or the currently playing episode) to the current user’s ‘Your Library’ favorites.
  • Added service save_show_favorites to save one or more shows (or the currently playing show) to the current user’s ‘Your Library’ favorites.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.86.

If you have ran the AuthTokenGenerator.py script, do the following before upgrading so you don’t have to rerun the script:
The Token Cache file was moved from \config\custom_components\spotifyplus\data\tokens.json to \config\.storage\spotifyplus_tokens.json, which will allow it to persist between version updates. Note that you can simply copy the Token Cache file from the old location to the new location prior to this update, so that you don’t have to re-run the AuthTokenGenerator.py script again.

1 Like

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.53 ] - 2024/08/20

  • Added DefaultDeviceId processing to set the default device id (or name) to use for player transport methods (e.g. play, pause, skip, etc) that do not specify a device id and there is no active Spotify player detected. This should avoid the No Active Device exceptions returned from the Spotify Web API when playback transport methods are called after long pauses of inactivity.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.88.
1 Like

Hey Todd!

I’m getting a very generic “connection_error” message when attempting to add the Integration in HA (downloaded 1.0.53 via HACS). I’m using a Client ID/Secret/Callback URI that works well with the basic Spotify integration. I tried also creating a separate Spotify Developer application, using a different browser, using a different machine, deleting and re-downloading the integration, and deleting and re-adding the application credential in HA. Nothing mentioning SpotifyPlus in the HA system logs either.

I have not yet tried installing previous versions to see if this is something that came up in the most recent version or something to that effect.

Any thoughts? I know not much to go on here. Thanks for the help!

I’m also getting the “connection_error” message. I tried other versions, but I’m unable to connect my spotify account.

@iratepuddle @asvintheguy
I believe this is due to one or more of your Spotify Connect devices not being available on the network, even though they are still registered to Zeroconf / mDNS. You might try rebooting all of your Spotify Connect devices, playing a track briefly on each device, then try the integration setup again after playing on the last device. This will ensure that they are available on the network.

I will look at putting some defensive code in the underlying API to account for this scenario, as others have reported the same thing as well. It should be available in the next release (v1.0.54).

Will keep you posted.

@iratepuddle @asvintheguy
Sorry, may have jumped the gun here with my previous response …

Questions:

  1. At what point in the integration install process are you receiving the connection_error?

  2. Is it in the Step 3 - Home Assistant Application Credential(s) flow that the error appears?

  3. Or is it in the Step 4 - Integration Install step?

  4. Do you make it past the Spotify authorization piece where it prompts you for your Spotify login and asks you to authorize your application id for access?

  5. Any entries in the Settings \ System \ Logs related to SpotifyPlus?

  6. What Spotify Connect devices are being used? Are they defined via SnapCast or SpotCast (that use librespot)? Or are they direct connections to the manufacturer device (e.g. Sonos, Bose, Yamaha, Onkyo, etc)?

I know there are currently issues with librespot and Spotify authentication at the moment, which could be causing this.

Please advise.

  1. At what point in the integration install process are you receiving the connection_error?

  2. Is it in the Step 3 - Home Assistant Application Credential(s) flow that the error appears?

  3. Or is it in the Step 4 - Integration Install step?

  4. Do you make it past the Spotify authorization piece where it prompts you for your Spotify login and asks you to authorize your application id for access?

Between Steps 4e and 4f, after clicking Link account in the HA callback window.

  1. Any entries in the Settings \ System \ Logs related to SpotifyPlus?

No entries in the logs related to SpotifyPlus at all

  1. What Spotify Connect devices are being used? Are they defined via SnapCast or SpotCast (that use librespot)? Or are they direct connections to the manufacturer device (e.g. Sonos, Bose, Yamaha, Onkyo, etc)?

None at all - I have two computers running Spotify typically and Spotify will let me send the playback to either one, but during this testing, I force quit the application on one of them to try to isolate the issue. For clarity, my “Spotify: connect to a device” window is completely empty on my computer and says “No other devices found”

I did try restarting each and playing a track to get them both available on the network per your previous reply, but no change in that case either.