SpotifyPlus Integration

@iratepuddle
Any entries in the Settings \ System \ Logs related to OAuth2?

I assume there are entries in the log that contain the connection_error message - anything within 30 lines before and after the connection_error message?

I would suggest rebooting HA, clearing your browser cache (including cookies, pages, etc), and retrying the integration install starting with the Step 4. Browser caching seems to be the cause of quite a few issues related to Application Credentials.

We could also try setting up a SmartInspect trace.

Hi community,

I was wondering, if I’m the only one experiencing this problem with Spotify in HA. I hope it’s not too off topic:

After reboot I cannot start the Spotify player via HA services. The player is unavailable und HA not listed under source. SpotifyPlus also stays switched off.
Once I start playing music on my mobile via Spotify app I can switch the source to HA and everything works great. The players (Spotify and Spotify Plus) get available and track info appears… until the next restart of HA.

Any ideas?

Thank you!

@brix29
After reboot I cannot start the Spotify player via HA services.

How do you normally start the Spotify player via HA services? Are you using SpotCast to start play on a device maybe? If so, there have been some Spotify authentication issues with the SpotCast service in the last couple of weeks.

Also, what kind of devices are you playing Spotify content on: Sonos? Bose Soundtouch? Etc.

Hi Todd!

I tried the above steps with just trying it on edge, a browser I haven’t used home assistant on or spotify and restarting my Home Assistant, and was able get passed the connection_error message, but now I get this message:


It happens after Step 4 too.

For the question numbers:
1-5: I get at the same point as iratepuddle. It happens when I click Link account in the HA callback window, and I’m getting no logs as well.
6: I’m using just an old ipad as my media player with spotify installed on it.

I’m also currently playing media in the spotify app on my ipad too.

Nevermind, after fully restarting my device, I was able to get it working again!

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.54 ] - 2024/08/22

  • Updated config_flow to correct a bug in the token authorization process that was introduced in v1.0.52 with the Token Cache file location change. This was preventing new instances of the integration to be setup due to connection_error exceptions in the Spotify OAuth2 authorization method.
  • Updated media_player.select_source service to correctly process the state of the player so that the player resume playing on the target source. Prior to this fix, play was not resumed (e.g. still paused) on the target source.

@iratepuddle @asvintheguy
Apologies, but it looks like I introduced a bug in v1.0.52 with the Token Cache file location change. This was preventing new instances of the integration to be setup due to connection_error exceptions in the Spotify OAuth2 authorization method.

The v1.0.54 will fix the connection_error exceptions.

1 Like

Hi Todd,

Thank you. I just identified it. I’m using Spotify Connect and Spotify Plus.
Spotify Connect has a problem with the credentials, so needs the mobile to get Spotify access:

ERROR librespot] Connection failed: Login failed with reason: Bad credentials
[07:56:12] WARNING: spotifyd crashed, halting add-on
[07:56:12] INFO: spotifyd stoped,

There is a bug reported:

Best,
Brix

1 Like

@brix29
Ya, unfortunately librespot is still having issues due to some changes that Spotify made to their API. I’m not sure where they are at on figuring it out, but you can check this link for librespot and this link for SpotifyConnect addon for more details.

1 Like

Hi todd,

Thanks for creating this integration, it looks like a lot of work, and it works with my Raumfeld Stereo S speakers. But I think I’m not quite understanding the bigger picture. The reason I installed is, is that it supports search according to your description. This is something I am really missing in the current Spotify integration in HA. I sometimes used predefined playlists, but often I just come up with a song I like, search it on Spotify, and switch on the song radio. I can do that on my phone or in the web app, but not in HA.
I now have the Spotify Plus integration running, but there is no ‘search’ button anywhere in the player. Do I need another custom UI component for this to be implemented? In truth, what I would like most is just a dashboard with a web page card that displays the spotify player page (open.spotify.com), that has all the interface elements I want to use. I tried making a web card that does that of course, but Spotify doesn’t allow this page to be embedded.
I do see that Spotify has a web playback API that might make this possible. Is there an easy way to create either an embbedded version of the spotify player page, or a dashboard card that emulates that (search bar, currently playing with playlist/queue, device selector, library browser with presets for tracks, lists, podcasts etc)?

Thanks, Allard

@allard77
Hi Allard - thanks for the kind words.

To answer your question, the SpotifyPlus integration provides the services to search for all kinds of things in Spotify (tracks, albums, artists, podcasts, audiobooks, playlists, etc). With that said, the SpotifyPlus integration is not a front-end UI interface to display those results; it’s the backend / under the covers engine that provides the results for a lovelace UI card to display and provide user-interaction.

I was hoping by this point that custom-card designers would be using the services provided by the integration to create some cool interfaces to Spotify, but sadly that has not happened yet. I am toying with the idea of writing my own custom card to do this, but am hesitant as Spotify already provides a nice UI with its web interface. The problem there (as you found out) is that Spotify does not allow it’s web UI to be embedded.

Sorry I do not have better news, but that’s the current situation.

Hi Todd, thanks for your reply. I was afraid already that this was the case. It’s a pity indeed there is such a limited interface to Spotify in HA. With so many users of Spotify around the world, and media playing such an important part of households, you would expect more. Especially if someone has already done the hard work of creating the backend.
I will also take a look at Music Assistant. That seems a bit overkill for what I want, but maybe it will do.

1 Like

I’ve deleted the previous post because i realized that i’ve overlooked the documentation where it is clearly stated that the service spotifyplus.player_set_shuffle_mode should be used instead of the standard media_player.shuffle_set to shuffle the playlist :sweat_smile:

1 Like

@Yes

The spotifyplus.player_set_shuffle_mode service should be used to set the shuffle mode if you want to target a specific Spotify Connect device id; otherwise, the media_player.shuffle_set service can be used to set the shuffle mode if you want to target the default (e.g. currently playing) Spotify Connect device.

Note that Shuffle and Repeat are not supported in the SpotifyPlus integration for Spotify Free accounts (Spotify Premium is required).

And to verify, you can select Shuffle and Repeat buttons in the official Spotify mobile / desktop application? And you are using a Spotify Premium account?

The media_player.shuffle_set service should be able to set the shuffle mode, assuming that a Spotify Premium account is used and a default device is in use.

Thanks for the spotifyplus integration and for responding.

And yes i have a premium account and that’s what i’m using.
Shuffling works fine with the spotifyplus.player_set_shuffle_mode service now.

When using the media_player.shuffle_set service I was getting something like “this device is not supported” or so. I thought it might had something to do with the fact that there was no shuffle icon available on the Lovelace overview dashboard for the spotify_plus mediaplayer entity.

That is somehow strange since the shuffle modes are available in the official Spotify apps on desktop and mobile.

FYI - just released a new version of the SpotifyPlus integration

There are quite a few service additions with this release, all in support of the SpotifyPlus UI Card that I am putting together. More on that to come, so stay tuned.

[ 1.0.55 ] - 2024/09/16

  • Added service check_album_favorites to check if one or more albums (or the currently playing album) exists in the current user’s ‘Your Library’ favorites.
  • Added service check_artists_following to check if one or more artists (or the currently playing artist) exists in the current user’s ‘Your Library’ favorites.
  • Added service check_audiobook_favorites to check if one or more audiobooks (or the currently playing audiobook) exists in the current user’s ‘Your Library’ favorites.
  • Added service check_episode_favorites to check if one or more episodes (or the currently playing episode) exists in the current user’s ‘Your Library’ favorites.
  • Added service check_show_favorites to check if one or more shows (or the currently playing show) exists in the current user’s ‘Your Library’ favorites.
  • Added service check_track_favorites to check if one or more tracks (or the currently playing track) exists in the current user’s ‘Your Library’ favorites.
  • Added service get_tracks_audio_features to get audio features for multiple tracks based on their Spotify IDs.
  • Updated service follow_playlist to make the playlistId argument optional; if not supplied, the currently playing playlist id value is used instead.
  • Updated service get_album to make the albumId argument optional; if not supplied, the currently playing album id value is used instead.
  • Updated service get_artist to make the artistId argument optional; if not supplied, the currently playing artist id value is used instead.
  • Updated service get_artist_albums to make the artistId argument optional; if not supplied, the currently playing artist id value is used instead.
  • Updated service get_playlist to make the playlistId argument optional; if not supplied, the currently playing playlist id value is used instead.
  • Updated service get_show to make the showId argument optional; if not supplied, the currently playing show id value is used instead.
  • Updated service get_show_episodes to make the showId argument optional; if not supplied, the currently playing show id value is used instead.
  • Updated service unfollow_playlist to make the playlistId argument optional; if not supplied, the currently playing playlist id value is used instead.
  • Added the following extra state attributes: sp_playlist_name, sp_playlist_uri, sp_user_country, sp_user_display-name, sp_user_email, sp_user_id, sp_user_product, sp_user_uri.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.95.
2 Likes

I thought the problem was the need to update this integration but instead even after the update I can’t understand why it doesn’t work. I get this error:

Since this is the action, I believe that Spotify Plus is not at least responsible, but I don’t know if I can replace the service with Spotify Plus to solve the problem:

data:
  account: vale
  force_playback: true
  start_volume: 30
  offset: 0
  device_name: Camera Linda
  repeat: "off"
  uri: spotify:playlist:4ufyQwaLq1MR49KvGRCNAo?si=f2bacb871a3d4ebc
enabled: false
action: spotcast.start

I tried this but it doesn’t work and I also see that I can’t select a specific player. What am I doing wrong?

action: spotifyplus.get_playlist
metadata: {}
data:
  entity_id: media_player.spotifyplus_paintervale
  playlist_id: 4ufyQwaLq1MR49KvGRCNAo?si=f2bacb871a3d4ebc

@Diegocampy
I believe spotcast uses librespot; unfortunately librespot is still having issues due to some changes that Spotify made to their API. I’m not sure where they are at on figuring it out, but you can check this link for more information .

Hope it helps!

1 Like

I didn’t understand why but it no longer recognized a token… I followed the spotcast guide again GitHub - fondberg/spotcast: Home assistant custom component to start Spotify playback on an idle chromecast device as well as control spotify connect devices and recovered new access codes sp_dc and sp_key which had strangely changed.
Now everything works again.
I was hoping to use spotifyplus to start a specific playlist on a specific media player, but I couldn’t, so I’m sticking with spotcast.

@Diegocampy

The spotifyplus.get_playlist is used to retrieve playlist details (not to play it). Also, the playlist_id: 4ufyQwaLq1MR49KvGRCNAo?si=f2bacb871a3d4ebc argument does not look like a valid Spotify playlist id.

If you are wanting to PLAY the playlist, then try something like the following (using spotifyPlus player).

action: spotifyplus.player_media_play_context
data:
  entity_id: media_player.spotifyplus_paintervale
  context_uri: spotify:playlist:5v5ETK9WFXAnGQ3MRubKuE
  device_id: "Camera Linda"

The context_uri: spotify:playlist:5v5ETK9WFXAnGQ3MRubKuE is one of my shared playlists, so you should be able to access it. If not, then go to Spotify Web and find the playlist that you want to play- copy the playlist id from the url, as shown in the following screenshot.

1 Like

Thanks, unfortunately it doesn’t work, then I understood the reason, I need to wake up the device, that’s why I was forced to use Spotcast, to be able to wake up the google home

As I do not have Google ChromeCast devices, are you able to use the SpotifyPlus service call to start playing the playlist on the device after it is awakened manually?