SpotifyPlus Custom Integration

And why not use music assistant?

FYI - just released v1.0.20 of the SpotifyPlus integration

[ 1.0.20 ] - 2024/06/06

  • Changed all media_player.schedule_update_ha_state(force_refresh=True) calls to schedule_update_ha_state(force_refresh=False) to improve performance. Suggested by @bdraco, along with an explanation of why. Thanks @bdraco!
  • Changed logic to call session.hass.config_entries.async_update_entry via a hass.add_job call instead of calling directly. This fixes the issue of Detected that custom integration 'spotifyplus' calls hass.config_entries.async_update_entry from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt that was introduced with HA 2024.6 release.
  • Changed logic to access local file system files via a hass.async_add_executor_job call. This fixes the issue of Detected blocking call to open inside the event loop by custom integration 'X' ... that was introduced with HA 2024.6 release.
3 Likes

FYI - just released a new version of the SpotifyPlus integration

Apologies for the back-to-back releases, but the Spotify DJ exception bug was a pretty big deal as the DJ is a popular Spotify function.

[ 1.0.21 ] - 2024/06/07

  • Fixed a bug that caused player state to return an error every 30 seconds when playing the Spotify DJ playlist. As the Spotify Web API does not support retrieving the DJ playlist (spotify:playlist:37i9dQZF1EYkqdzj48dyYq), it simply returns a manually built representation of the Spotify DJ playlist with limited properties populated (uri, id, name, description, etc). Note that Spotify DJ support is not supported (as of 2024/06/07) by the Spotify Web API (this includes starting play, retrieving playlist details, retrieving playlist items, etc).
  • Added service zeroconf_discover_devices to discover Spotify Connect devices on the local network via the ZeroConf (aka MDNS) service, and return details about each device.
  • Added service zeroconf_device_getinfo to retrieve Spotify Connect device information from the Spotify Zeroconf API getInfo endpoint.
  • Added service zeroconf_device_resetusers to reset users for a Spotify Connect device by calling the Spotify Zeroconf API resetUsers endpoint.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.44.
3 Likes

FYI - just released a new version of the SpotifyPlus integration

Apologies for the back-to-back releases, but each new release of HA lately seems to break things. Not complaining, as it’s just the nature of software updates sometimes.

[ 1.0.25 ] - 2024/06/08

  • Fixed a bug that was causing ValueError: list.remove(x): x not in list exceptions to be raised whenever the user changed configuration options for a service. This started appearing with the HA 2024.6.1 release.
2 Likes

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.26 ] - 2024/06/10

  • Added service zeroconf_device_connect that calls the addUser Spotify Zeroconf API endpoint to issue a call to SpConnectionLoginBlob. If successful, the associated device id is added to the Spotify Connect active device list for the specified user account.
  • Added service zeroconf_device_disconnect that calls the resetUsers Spotify Zeroconf API endpoint to issue a call to SpConnectionLogout. The currently logged in user (if any) will be logged out of Spotify Connect, and the device id removed from the active Spotify Connect device list.
  • Removed service zeroconf_device_resetusers and replaced it with zeroconf_device_disconnect.
  • Updated underlying spotifywebapiPython package requirement to version 1.0.48.
2 Likes

@Fanful, @staceydodds @stennajay
I believe I have the “playback when another Spotify account is controlling the device” issue resolved. I added a new service to the 1.0.26 version of the SpotifyPlus integration that allows you to disconnect the current user on a device, then reconnect a different user to the same device.

Check out the wiki docs for the new Zeroconf Device Connect service. It will disconnect the current user from the device, and add a different user to the device; you can then issue the Play Transfer Playback service call to start play on the device.

Note that the username MUST match the account name (or one of them) that was used to configure Spotify Connect on the manufacturer device; you can’t just randomly select a Spotify account that is not known to the manufacturer device.

Use the ZeroConf Discover Devices service to retrieve the various parameters for the Connect service.

Example yaml:

service: spotifyplus.zeroconf_device_connect
data:
  entity_id: media_player.spotifyplus_john_s
  host_ipv4_address: 192.168.1.81
  host_ip_port: 8200
  cpath: /zc
  version: 1
  use_ssl: false
  username: [email protected]
  password: yourpassword
  pre_disconnect: true
  verify_device_list_entry: true

Let me know if it works for you or not. It should work, as it uses the Spotify Zeroconf API, which should be what your device uses to interface with Spotify Connect.

2 Likes

Hello @thlucas . I’m trying to follow your advice here.

A couple notes about the process, in case this might be useful for others.

  1. I think the help text on that field in the service visual editor is wrong (it’s a copy of the previous one):
    obraz
    The field doesn’t accept numbers, it’s a boolean. I haven’t found any mention of SSL in the discover device service results, so I just set this field as false.

  2. I didn’t have a Spotify password, because I used “Continue with Google” to sign up/login. However, it turns out Spotify lets you create a “device password” in the account settings on the website (inside the privacy and security section). So I created one and used it for this service.

And as for the result, I had to fiddle quite a bit, but I think I finally managed it. I will need to test this some more (and with it test the patience of my wife :smiley:), but it worked when I separately run the disconnect service, then the connect service without the pre-disconnect. In the end I managed to stop my wife’s session on the device and start playback from my account, all without touching the Spotify app.

1 Like

@Fanful
Glad to hear it is working for you.

Thanks for the notes on the SSL description; I will get that corrected with the next release today. Here is what it should have said:
Use SSL? True if the host device utilizes HTTPS Secure Sockets Layer (SSL) support; otherwise, False to utilize HTTP. Default is False (HTTP).

I also updated the ZeroConf Device Connect service wiki documentation with your “device password” notes. Thanks for that, as I don’t utilize the non-password login methods.

Can I ask what device hardware are you controlling? e.g. Sonos, Google Cast, Onkyo, etc. As well as what the CPath and Port numbers you are using to access your device(s)? I would like to add them to my ZeroConf Device Info by Manufacturer wiki documentation if you can supply me with the details.

FYI - just released a new version of the SpotifyPlus integration

[ 1.0.27 ] - 2024/06/12

  • Added extra state attribute media_playlist_content_id that contains the Content ID of current playing playlist context if one is active; otherwise, None.
  • Added property media_player.media_playlist_content_id that contains the Content ID of current playing playlist context if one is active; otherwise, None.
  • Added property media_player.media_playlist_content_type that contains the Content Type of current playing playlist if one is playing; otherwise, None.
  • Added property media_player.media_playlist_description that contains the Description of current playing playlist if one is playing; otherwise, None.
  • Added property media_player.media_playlist_image_url that contains the Image URL of current playing playlist if one is playing; otherwise, None.
  • Updated use_ssl description on all of the Zeroconf Device services.

Yamaha R-N402D, it’s a receiver with MusicCast.

Port: 80
CPath: /goform/spotifyConfig

1 Like