SpotifyPlus Custom Integration

I have developed a new SpotifyPlus Home Assistant custom component integration that expands the built-in Spotify capabilities. Since it’s a new integration name (e.g. SpotifyPlus) it won’t interfere with the built-in Spotify integration setup. It’s a simple install to the “custom_components” directory via a HACS UI custom repository installer.

I also developed the underlying SpotifyWebApiPython library that interfaces with the Spotify Web API.

The following Home Assistant media_player Platform services are supplied by this integration.

BROWSE_MEDIA
MEDIA_ENQUEUE
NEXT_TRACK
PAUSE
PLAY
PLAY_MEDIA
PREVIOUS_TRACK
REPEAT_SET
SEEK
SELECT_SOURCE
SHUFFLE_SET
VOLUME_SET

The following custom services are supplied by this integration.

Get Album
Get Album Favorites
Get Album New Releases
Get Artist
Get Artists Albums
Get Artists Followed
Get Browse Categories
Get Category Playlists
Get Featured Playlists
Get Player Devices
Get Player Queue Info
Get Player Recent Tracks
Get Playlist
Get Playlist Favorites
Get Show
Get Show Episodes
Get Show Favorites
Get Track Favorites
Get Users Top Artists
Get Users Top Tracks
Player Media Play Context
Player Media Play Tracks
Player Transfer Playback
Search Albums
Search Artists
Search Audiobooks
Search Episodes
Search Playlists
Search Shows
Search Tracks

It also has built-in media library browser support, as well as interfaces with my SoundTouchPlus integration to provide Spotify music services support for it.

What Speakers are Supported?

Any speaker that supports Spotify Connect functionality should be supported. I say “should be”, as I have only tested this with my Bose SoundTouch line of speakers that support Spotify Connect natively. These include the ST-10 and ST-300 products.

Please let me know if you run into any issues, or if it works with other speaker types (Sonos, Xiaomi, etc).

More Information Links

PyPi Install Instructions
Use the following to install just the Python 3 library if you wish:
$ python3 -m pip install spotifywebapiPython

3 Likes

Nice! Going to test this. One of the claims is faster response to user initiated player states; this is what is bothering me with the current integration because I am switching power of my speakers based on player state and that now takes a while. Hopefully your integration works better in that respect :+1:

@balk77
Good deal - let me know if you have issues with the states.

I place a small delay (.25 secs) just after a command (e.g. pause, skip next, etc) is issued, so that it give the Spotify Web API time to update status on its end before HA goes out to query it for a status update (which happens when a media player command is processed). The issue with the current Spotify is that there is no delay, and HA immediately goes out to check the status and the Spotify Web API has not had time to process the change that just happened.

I really wish Spotify would give us a websocket interface with player status updates, instead of having to poll every ‘n’ seconds. Unfortunately, that is beyond my control. :smiley:

I have problems activating the integration. Same issue as this one Spotify wont configure :: Invaid redirect URI - #9 by Marcus_Jansson

Are you forcing the use of the “my” url for activation?

I have it up and running. Tested a few services and also played through Media dashboard. Need to push now for a card that supports all this, especially search.

1 Like

@balk77

I do not force the use of the “my” url - that is done by the Home Assistant OAuth2 authorization service. You just need to make sure that the Home Assistant OAuth authorization service url prefix (see figure 1 below) exactly matches (case sensitive, no extra ending slashes, includes https:// prefix) the redirect uri value specified in your Spotify Developer Application Settings (see figure 2 below). You will also need to click the “Link Account” button on the “Link Account to Home Assistant”.

If you have multiple Spotify accounts defined, ensure that the account you are logging on to Spotify with when installing the integration is the same account for the specified Spotify Application Client ID and Secret. If it’s not, then click on the “Not you?” link on the “Agree” form, and re-login to Spotify with the correct account.

Note that you can specify multiple Redirect URI’s in the Spotify Developer Application Settings if you have to.

In my case, the redirect URI is https://my.home-assistant.io/redirect/oauth

Figure 1 - Home Assistant OAuth2 Authorization Service

Figure 2 - Spotify Developer Application Settings

If you still have issues after the above, please send me a screen capture of your Spotify Developer Application settings so I can see what you have defined for the Redirect URI value. Also send me a screen capture of the Home Assistant OAuth2 Authorization Service “Link Account” page (like Figure 2 above).

Hope it helps!

ok, I managed to get it configured. Testing time :slight_smile:

1 Like

FYI, I posted an Enhancement request to the card owner of the generic Spotify card. I plugged in the SpotifyPlus integration media_player and of course it works, but looking at all the new functionality makes me want to sing!

Searching? I mean this is perfect.

You may wish to leave behind suggestions, the more there are helps to drive whether the change will happen.

1 Like

Thanks @kbrown01, appreciate it.

I can add more services as are needed, as the ones the integration supports are only about 30% of the underlying services available. Check out the spotifywebapiPython library to see if anything else catches your eye and let me know.

Hi!
I entered the wrong Spotify authentication information and despite uninstalling the integration it takes me to the same point, I cannot change this information. So I’m stuck setting up Spotify Plus.
An idea?

image

@stban1983 It sounds like you entered the wrong application credentials maybe?
If you have multiple Spotify accounts defined, ensure that the account you are logging on to Spotify with when installing the integration is the same account for the specified Spotify Application Client ID and Secret. If it’s not, then click on the “Not you?” link on the “Agree” form, and re-login to Spotify with the correct account.

I would suggest that you do the following:

Give those a try and let me know how it goes.

Many thanks, it’s working!
I was missing this point:

1 Like

FYI - just released v1.0.8 of the SpotifyPlus integration:

  • Added service playlist_items_add to add one or more items to a user’s playlist. Items are added in the order they are listed in the uris argument.

This fulfills this Request made by user @ih8gates @OzStone @m4tthall73.

1 Like

Interesting. Can you talk about some of the interesting ways you use this, @thlucas?

I like, of course, the playlist_items_add that you added. I worked out my own kludgy version that talks to a PHP server since I understand PHP better than Python. But it’s kludgy for sure. But other than that, I’m not sure about how I’d use this.

@ih8gates The thought behind the playlist_items_add service is that you could easily click a button next to the media player to add the currently playing track to a “Liked Songs” playlist.

What HA really needs is a custom card (or even a built-in one) that can take advantage of the new service_response data features without having to use template sensors (16k limit). For example, I could build a card that populates “Made For You” Spotify playlist items, where the user clicks on one to play. Or create a card with Spotify Search functionality - a textbox to enter search criteria, a dropdown list to select the type of criteria (playlist, artist, album, etc), and a “Search” button to start the search. Display the results (from real-time service_response data) in a grid (with cover art) and clickable items to play content.

All kinds of stuff we could be doing with service_response data right now that no-one can take advantage of because it’s not fully supported yet.

To be clear I am not complaining - just hoping we can get that functionality soon.

Hope it helps.

I totally see the value of that playlist_items_add - I have a voice command / automation to “remember this song” when I’m listening to Discover Weekly, etc, and want to add it to a playlist.

I meant for your integration in general. What needs were met when you created this integration?

@ih8gates The reason I created the SpotifyPlus integration (or to be clear, cloned the built-in Spotify integration) was to add custom services to support my SoundTouchPlus integration. I was able to implement Spotify support into the Media Browser for SoundTouchPlus. It makes direct service calls to the SpotifyPlus integration to provide the media browser support.

I also didn’t like the responsiveness of the original Spotify integration, as it was slow to detect changes to the player state. My changes for player state improvement are not perfect either, but it’s the best I can do until Spotify releases a websocket API for real-time player updates (like Bose has for their SoundTouch products).

Hope that answers your question.

1 Like

Has anyone got any yaml examples on how to add this on a dashboard ?

The advanced features in your integration look promising, especially the music machine. :star_struck:

At the moment I’m using the official Spotify integration toghether with Spotcast. To you have a similar feature or do I still have to use Spotcast?

@j_d Spotcast requirement is determined by your speaker / receiver hardware. I do not need Spotcast to start playback on my Bose SoundTouch speakers. It should be able to start play on any device that is known to Spotify Connect, as it retrieves the device list from the Spotify Web API directly. I say “should be”, as I don’t have any other types of hardware besides my SoundTouch speakers to test with.

Other users have reported that Spotcast is required for playback on Google Chromecast devices. I have not had any feedback on Sonos or other types of hardware. I believe the Chromecast Spotcast requirement is needed because the speaker has gone into “sleep mode” and cannot be awakened to start play.