SpotifyPlus Custom Integration

@Fanful @staceydodds @stennajay @mhoogenbosch
FYI - just released a new version of the SpotifyPlus integration.

Note - If you are using the SoundTouchPlus integration, you will also need to update it as well since it uses the underlying Spotify Web API Python library.

[ 1.0.29 ] - 2024/06/21

  • Fixed a bug due to SpotifyConnect addon not properly returning a “Content-Type: application/json” header in it’s Spotify Zeroconf API responses. This was causing an error in the SpotifyPlus integration when trying to retrieve the Spotify Connect device list, and returning errors in the configuration options form.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.61.

In summary, if you had the “SpotifyConnect” addon installed, you would get an error in the SpotifyPlus configuration options of “Per Spotify Web API, there are currently no Spotify Connect devices active …”. This was due to the fact that SpotifyConnect does not properly return a “Content-Type: application/json” header in it’s Spotify Zeroconf API responses.

Can one of you verify that you can still select the SpotifyConnect addon device instance as an active player? I cannot verify this, as I am running my HA under a VMWare ESXI VM image, and don’t have anything hooked up to the audio output.

Please let me know.

Do I need to be on 2024.6? I haven’t updated yet to the latest version

Just updated and I’m getting this error, but I haven’t updated in a while so perhaps I need to scroll back up and look through some of the update notes.

I’m doing this remotely from work so I will probably have to look at this in further detail tomorrow

Here’s the error I’m getting currently:

Screen Shot 2024-06-21 at 1.51.02 PM

@staceydodds Should not have to be on 2024.6 …
Not sure what’s going on here - any messages in the System Log related to SpotifyPlus?

@staceydodds Just verified it works fine on the 2024.5.4 release (what my PROD HA is running).

Did you find anything in the System Log?

You might also post your dashboard card definition.

At the very least, I would suggest a reboot and clearing of your browser cache.

FYI - just released a new version of the SpotifyPlus integration.

Note - If you are using the SoundTouchPlus integration, you will also need to update it as well since it uses the underlying Spotify Web API Python library.

[ 1.0.30 ] - 2024/06/22

  • Updated config_flow to utilize the HA shared Zeroconf instance.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.62.

Apologies for the back-to-back updates, but the underlying spotifywebapiPython update fixes a potential memory leak with the Zeroconf discovery process.

With entering the information in the configuration of the Integration, my receiver ‘just works’ with SpotifyPlus. I totally love this!

Even when the receiver is turned off (standby) I can now just start a playlist item on the receiver and it turns on, and switches to the correct input, just like the ‘normal’ Spotify app does.


And for the back-to-back releases, please don’t apologize, this is great for us, any fix, update, love the pace!

1 Like

Does this info help?

This error originated from a custom integration.

Logger: custom_components.spotifyplus
Source: custom_components/spotifyplus/init.py:1991
integration: SpotifyPlus (documentation, issues)
First occurred: June 21, 2024, 1:47:32 PM (876 occurrences)
Last logged: 9:49:12 AM

SAM1003E - Spotify ZeroConf API returned an error status while processing the “GetInformation” method. Status: 503 - Client Error Message: “”
Traceback (most recent call last):
File “/usr/local/lib/python3.12/site-packages/spotifywebapipython/zeroconfapi/zeroconfconnect.py”, line 217, in _CheckResponseForErrors
raise SpotifyWebApiError(response.status_code, errMessage, methodName, response.reason, _logsi)
spotifywebapipython.spotifywebapierror.SpotifyWebApiError: SAM1001E - Spotify Web API returned an error status while processing the “GetInformation” method.
Status: 503 - Client Error
Message: “”

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/config/custom_components/spotifyplus/init.py”, line 1991, in _update_devices
scDevices = await hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/concurrent/futures/thread.py”, line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py”, line 7970, in GetSpotifyConnectDevices
info:ZeroconfGetInfo = zconn.GetInformation()
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/spotifywebapipython/zeroconfapi/zeroconfconnect.py”, line 558, in GetInformation
responseData:dict = self._CheckResponseForErrors(response, apiMethodName)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/spotifywebapipython/zeroconfapi/zeroconfconnect.py”, line 232, in _CheckResponseForErrors
raise SpotifyZeroconfApiError(response.status_code, responseUTF8, methodName, response.reason, _logsi)
spotifywebapipython.zeroconfapi.spotifyzeroconfapierror.SpotifyZeroconfApiError: SAM1003E - Spotify ZeroConf API returned an error status while processing the “GetInformation” method.
Status: 503 - Client Error
Message: “”

@staceydodds
The http status of “503” indicates a “Service Unavailable”. It appears that the API is not able to reach one of your Spotify Connect devices.

Please try the following:

  1. upgrade to the latest 1.0.30 version of SpotifyPlus. Make sure you reboot HA after the update, as well as clear your browser cache.
  2. verify you have set the Spotify Connect Device Username and password in the SpotifyPlus configuration options.

Per your System Log details, the error is occurring while trying to retreieve Spotify Connect details from a device.

If you are using Windows OS, you might also try running the following command (from an MS-DOS prompt) to display what Spotify Connect devices are available on the network:
dns-sd -B _spotify-connect._tcp. local.
It will produce something like this (my devices; yours will be different):

C:\Users\thluc>dns-sd -B _spotify-connect._tcp. local.
Browsing for _spotify-connect._tcp..local.
Timestamp     A/R Flags if Domain                    Service Type              Instance Name
12:11:29.922  Add     3  5 local.                    _spotify-connect._tcp.    Bose-ST10-2
12:11:29.923  Add     3  5 local.                    _spotify-connect._tcp.    Bose-ST300
12:11:29.923  Add     2  5 local.                    _spotify-connect._tcp.    Bose-ST10-1
12:11:30.038  Add     2  5 local.                    _spotify-connect._tcp.    HAVM-SpotifyConnect

That might give us some clues as to which device it is failing on.

Thanks Todd. I’ll give that a shot. I am pretty sure I likely changed my MusicCast devices after I did the initial integration so I’m guessing that’s likely the cause. I had two Yamaha WX-010 speakers that were in separate rooms and I moved them both to the living room and made them a stereo pair. Odd that this issue only came up though after I did the SpotifyPlus update.

I’ll grab my PC and run that script and report back.

Cheers

1 Like

@thlucas here you go:

Browsing for _spotify-connect._tcp.local.
Timestamp A/R Flags if Domain Service Type Instance Name
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Living Room Left
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Garage
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Media Player
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. (Linked) Media Player
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Living Room
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. (Linked) Living Room
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Patio
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Home Theater Room
10:18:46.967 Add 2 21 local. _spotify-connect._tcp. sonosRINCON_347E5C35D9DA01400

I wonder if it’s an issue with the (Linked) xxxx devices; I wonder if those are some sort of virtual device maybe?

Before doing any of the below, try the update to v1.0.30 first. It might solve the issue. If it doesn’t, then …

At this point, we need to find out with of those 9 devices is giving use the 503 status error. To do this, it’s a matter of issuing a getInfo request via a desktop browser to each instance name in the dns-sd -B _spotify-connect local list and send me the results. The getInfo request will be a little bit different for each instance name, as the IP Address, Port, and CPath could / will be different.

Using my environment as an example …

Step 1 - Get all Spotify Connect instances available on the network. You already completed this step:

Browsing for _spotify-connect._tcp.local.
Timestamp A/R Flags if Domain Service Type Instance Name
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Living Room Left
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Garage
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Media Player
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. (Linked) Media Player
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Living Room
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. (Linked) Living Room
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Patio
10:18:46.967 Add 3 21 local. _spotify-connect._tcp. Home Theater Room
10:18:46.967 Add 2 21 local. _spotify-connect._tcp. sonosRINCON_347E5C35D9DA01400

Step 2 - Issue a mDNS List command for each “Instance Name” to get the IP Address, Host, and CPath of each instance. So for my “Bose-ST10-1” instance, the command would be:
dns-sd -L "Bose-ST10-1" _spotify-connect._tcp local
and the output would look like:

C:\Users\thluc>dns-sd -L "Bose-ST10-1" _spotify-connect._tcp local
Lookup Bose-ST10-1._spotify-connect._tcp.local
 6:30:52.606  Bose-ST10-1._spotify-connect._tcp.local. can be reached at Bose-SM2-341513fbeeae.local.:8200 (interface 5)
 CPath=/zc VERSION=1.0

The mDNS List command for your first device instance would be:
dns-sd -L "Living Room Left" _spotify-connect._tcp local

Step 3 - Issue a getInfo http request url from a desktop browser to retrieve the Spotify Connect device information for the instance. From the information obtained in step 2, the request url would look like:
http://Bose-SM2-341513fbeeae.local.:8200/zc?action=getInfo
and the output would look like:

{"status":101,"statusString":"OK","spotifyError":0,"version":"2.7.1","deviceID":"30fbc80e35598f3c242f2120413c943dfd9715fe","remoteName":"Bose-ST10-1","activeUser":"31l77y2al5lnn7mxfrmd4bpfhqke","publicKey":"zd0izOw8jxpj/ijpB/KWS/vU4WGoZYYSXC7VVesZ+jmVTRzGYnibTWGs0pdSIzIc6gA4HzA7QkDvkmEJWeDAfPJYGzyGuEGRARw1laEmqQ3tTAsNOmwCxLFl6MEo4qxV","deviceType":"SPEAKER","libraryVersion":"3.88.29-gc4d4bb01","accountReq":"DONTCARE","brandDisplayName":"Bose","modelDisplayName":"Soundtouch","resolverVersion": "0","groupStatus": "NONE","tokenType": "accesstoken","clientID": "79ebcb219e8e4e9a892e796607931810","productID":70001,"scope": "streaming","availability": "","voiceSupport": "YES"}

repeat Step 2 and Step 3 for each “Instance Name” in the dns-sd -B list. One of those entries should generate a “503” error.

Note that if you don’t want to do the above, I can show you how to set up a SmartInspect Trace that would capture what the SpotifyPlus integration is doing to a trace file. You could then send that file to me for diagnosis.

Either way, we have to determine which device instance is failing and why before I can offer a solution (or fix a bug if need be).

1 Like

I also opened up a new issue on the SpotifyPlus GitHub Issues page to track this, so we don’t fill up the community forum with troubleshooting info.

1 Like

FYI - just released a new version of the SpotifyPlus integration .

Note - If you are using the SoundTouchPlus integration, you will also need to update it as well since it uses the underlying Spotify Web API Python library.

[ 1.0.31 ] - 2024/06/24

  • Updated underlying spotifywebapiPython package requirement to version 1.0.64.
  • The underlying spotifywebapiPython update changes the way Spotify Connect Zeroconf API return codes are processed. It now processes the Spotify Zeroconf API status code from the JSON response instead of processing the HTTP request status code. It has been found that some Spotify Connect manufacturers return different HTTP status codes than other manufacturers; but the Spotify Connect status, statusString and spotifyError JSON properties seem to be consistent across the board.
  • The underlying spotifywebapiPython update also filters out duplicate Spotify Connect Device entries for devices that have been grouped together. For example, the “Bose-ST10-1” and “Bose-ST10-2” are grouped as a stereo pair; there will be two Zeroconf discovery result entries with different instance names, but their Zeroconf getInfo endpoint url will be the same. This was causing two entries to appear in the device list, when there should have been only one.

For those that want the DJ, just use a mouse click CLI tool like I’m doing on my Mac. I leave Spotify running on a dedicated desktop always in the same space and the DJ is pinned- it doesn’t need to be on the server. On supervised it looks like you could use xdotools and Spotify for Debian.

@fmon
Not for certain, but I think Spotify added the DJ to the playlist favorites.
It shows up for me in the various places:

Get Playlist Favorites service

service: spotifyplus.get_playlist_favorites
data:
  entity_id: media_player.spotifyplus_todd_l
  limit_total: 100

Output:

    - collaborative: false
      description: All kinds of music, picked by your own AI DJ.
      external_urls:
        spotify: https://open.spotify.com/playlist/37i9dQZF1EYkqdzj48dyYq
      href: https://api.spotify.com/v1/playlists/37i9dQZF1EYkqdzj48dyYq
      id: 37i9dQZF1EYkqdzj48dyYq
      images:
        - url: https://lexicon-assets.spotifycdn.com/DJ-Beta-CoverArt-300.jpg
          height: null
          width: null
      name: DJ
      owner:
        display_name: Spotify
        external_urls:
          spotify: https://open.spotify.com/user/spotify
        followers: {}
        href: https://api.spotify.com/v1/users/spotify
        id: spotify
        type: user
        uri: spotify:user:spotify
      public: true
      snapshotId: AAAAAAAAAACzEDPzO+U0nKHNdhOvJfpi
      tracks:
        href: https://api.spotify.com/v1/playlists/37i9dQZF1EYkqdzj48dyYq/tracks
        total: 0
      type: playlist
      uri: spotify:playlist:37i9dQZF1EYkqdzj48dyYq

Spotify.com web:

Home Assistant Media browser

http://homeassistant.local:8123/media-browser/media_player.spotifyplus_todd_l/spotify_user_playlists%2Cspotify_user_playlists

Interesting, does that href or uri work if you try to play it?

If you right-click the DJ in the application you can pin it on the left side under playlists (which is how I know where to cliclick).

Yes, clicking on the item in the media browser will start play.

I don’t think I pinned the DJ - it just showed up in my playlist favorites.

No I mean can you use:

  - service: media_player.play_media
    target:
      entity_id: media_player.spotifyplus
    data:
      media_content_type: playlist
      media_content_id: <href or something>

Both of these service calls work to play the DJ playlist.

Also note that the HA Media Browser issues the same call to the media_player.play_media service under the covers to start play.

HA play_media service

service: media_player.play_media
data:
  entity_id: media_player.spotifyplus_todd_l
  media_content_type: playlist
  media_content_id: spotify:playlist:37i9dQZF1EYkqdzj48dyYq

SpotifyPlus Player Media Play Context service

service: spotifyplus.player_media_play_context
data:
  entity_id: media_player.spotifyplus_todd_l
  context_uri: spotify:playlist:37i9dQZF1EYkqdzj48dyYq
  device_id: Bose-ST10-1

2 Likes