SpotifyPlus Integration

@Kamblian

Yes, please open a new github Repository Issue Request for the ReadTimeoutError issue.

Thanks

Hey @thlucas and @cedrict, I've spent many hours reading through all the documentation I can find and using ChatGPT, but I'm still unable to solve what appears to be the same issue cedrict was having.

I was able to successfully link my Premium account to SpotifyPlus but I can't figure out how to play music from my Chromecast Google speakers (a couple minis and a Google Home). I created the spotifyplus_tokens.json and it's inside the /homeassistant/.storage/ directory, yet I get the exact same token error cedrict posted about. I also confirmed the user profile matches what you two posted screenshots of and the test script has entity_id: media_player.spotifyplus_jason.

Best I could find is ChatGPT thinks I need to additionally include another item in the token file containing the sp_dc key pair, which I tried, but that also didn't work. What was your solution??

I'm using a raspberry pi 4B with core-2026.5.1, if that matters! Thank you!

@shortybig
@cedrict found that his issue was that the spotifyplus_tokens.json was placed in the wrong directory; he accidentally created a directory with a space in it, and placed the tokens file there. This caused the integration to not find the tokens file.
For example:

/config/ .storage/    <- incorrect directory name, starts with a space
/config/.storage/     <- correct directory name, starts with a dot (hidden name in some OS's)

If you are using the Home Assistant File Editor add-on, ensure that you have the "View hidden files" option turned on, so that you can see the .storage directory.

Possible Causes

  1. the encoding of the spotifyplus_tokens.json file. What editor did you use to create the file? It should be saved as a UTF-8 encoded, plain-text format, with Unix (LF). I just use Windows notepad to create mine.
  2. there could be more than one spotifyplus_tokens.json files in the config location. I would do a search of the entire \config (and sub-directories) for the spotifyplus_tokens.json filename. If multiple entries exist, then you should only keep the one in the /config/.storage/ directory.
  3. are you sure your SMB share name is mapped to the correct location / machine? if you run multiple HA instances, then you may be editing a spotifyplus_tokens.json on a different machine or in a different directory. You might also try editing the file using the Home Assistant File Editor add-on. Check out this link for more information. Also be sure to enable access to the .storage hidden directory location in the config folder. This will allow you to edit the file directly within HA, and from the \config\ location the instance is using.
  1. I used your AuthTokenGenerator.py script via Command Prompt and simply uploaded the resulting json directly to /homeassistant/.storage/
  2. Confirmed via find / -name "spotifyplus_tokens.json" from the home directory in Terminal there is only one spotifyplus_tokens.json file and it's in /homeassistant/.storage/
  3. I've only got the one HA instance! I can see the file in File Editor and it seems fine.

I just tried replacing the spotifyplus_tokens.json file with a .txt file (deleted the original and uploaded the text version), but it gave the same error. Below is the text file I used:

{
    "SpotifyWebApiAuthCodePkce/65b708073fc0480ea92a077233ca87bd/Shared": {
        "access_token": "REDACTED",
        "expires_at": 1778385487,
        "expires_in": 3600,
        "refresh_token": "REDACTED",
        "scope": [
            "streaming"
        ],
        "title": "Spotify Desktop App Client (REDACTED)",
        "token_type": "Bearer",
        "username": "REDACTED"
    }
}

@shortybig
Can you provide a screen capture (or list) of what other files you have in the /homeassistant/.storage/ location? I take it you don't have a /config/.storage/ location, as specified in the How to find the HA configuration directory instructions for how to locate the Home Assistant configuration directory.

If you are using Home Assistant Core installation type (config directory passed to the hass command), then shouldn't that be ~/.homeassistant/.storage/?

What is your Home Assistant installation type?

Sure! And it's weird, File Editor only shows /homeassistant/ but Terminal shows /homeassistant/ and /config/. But they're linked to each other. Deleting the original json from config also deleted it automatically from homeassistant. Likewise, uploading the new .txt to homeassistant, it shows up in config.

@shortybig
It appears that homeassistant is an alias for config.

Note that the spotifyplus_tokens.txt needs to be renamed to spotifyplus_tokens.json in your example directory structure above. That is the correct .storage/ directory location.

Did you say that did not work with the .json extension?

If not, can you post a screenshot of the error that you receive?
Can you also post the script that you are executing to transfer playback?

Thanks - this is progress.

ah, okay, and yeah I originally had spotifyplus_tokens.json. Here's the action:

action: spotifyplus.player_media_play_context
metadata: {}
data:
  entity_id: media_player.spotifyplus_jason
  context_uri: spotify:playlist:7ku6P1WcrImYYJ6Tv8tmKJ
  device_id: Bedroom speaker

The resulting error (same with .txt and .json):

Spotify Cast Application could not be activated on Chromecast device "8ed23e57572077f6f5c112b63c0b6279": Spotify Desktop Player authorization token was not found in the token cache file.

I also tried with quotations around the device id and confirmed the wrong device id returns: "Spotify Player device "test" was not found in the Spotify Connect device list; verify the device is discoverable via Zeroconf on the local network."

And no worries! I appreciate all the work you've done and your willingness to help users like me!

@shortybig
Ok, I think I see the problem.

It appears that the AuthTokenGenerator process did not replace the Shared value in the token key with your Spotify LoginID value (in the spotifyplus_tokens.json file).

Change the following line in your /config/.storage/spotifyplus_tokens.json file from this:

SpotifyWebApiAuthCodePkce/65b708073fc0480ea92a077233ca87bd/Shared

to this, where YOUR_SPOTIFY_LOGINID is your Spotify LoginID value. The LoginId value can easily be found using the Spotify Developer Web portal, using the Get Current Users profile service. Click on the Try It button, then find the id response value.

SpotifyWebApiAuthCodePkce/65b708073fc0480ea92a077233ca87bd/YOUR_SPOTIFY_LOGINID

Note that you are just changing the Shared value to your Spotify LoginID value (this first 2 nodes of the token key are the same).

Hopefully that makes sense.

It didn't work at first, with it returning the error of it taking it too long, but then I restarted HA and now it's working! Thank you so much for all your help!!

1 Like