spotcast: Unable to retrieve token / Invalid TOTP error

The problem

I have installed v5.0.0-b30.

When I try to provide the sp_dc and sp_key values at configuration, an “Invalid TOTP” error is thrown. I tried three or four times to make sure I wasn’t doing something wrong.

System Information

version core-2025.3.2
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.13.2
os_name Linux
os_version 6.6.62-haos-raspi
arch aarch64
timezone America/Indianapolis
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
HACS Data ok
GitHub API Calls Remaining 4956
Installed Version 2.0.5
Stage running
Available Repositories 1589
Downloaded Repositories 3
Home Assistant Cloud
logged_in true
subscription_expiration February 6, 2026 at 7:00 PM
relayer_connected true
relayer_region us-east-1
remote_enabled true
remote_connected true
alexa_enabled false
google_enabled true
cloud_ice_servers_enabled true
remote_server us-east-1-14.ui.nabu.casa
certificate_status ready
instance_id 30f273ad337a4e8eb1985a895eb08817
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 14.2
update_channel stable
supervisor_version supervisor-2025.03.2
agent_version 1.6.0
docker_version 27.2.0
disk_total 57.8 GB
disk_used 6.9 GB
healthy true
supported true
host_connectivity true
supervisor_connectivity true
ntp_synchronized true
virtualization
board rpi5-64
supervisor_api ok
version_api ok
installed_addons Studio Code Server (5.18.3), AdGuard Home (5.2.5)
Dashboards
dashboards 2
resources 0
views 0
mode storage
Network Configuration
adapters lo (disabled), end0 (enabled, default, auto), hassio (disabled), docker0 (disabled), veth600d57f (disabled), veth7f095a5 (disabled), veth5cc2d7a (disabled), veth94ad141 (disabled), veth78616a5 (disabled), veth8e63670 (disabled), veth6fa8856 (disabled)
ipv4_addresses lo (127.0.0.1/8), end0 (192.168.1.141/24), hassio (172.30.32.1/23), docker0 (172.30.232.1/23), veth600d57f (), veth7f095a5 (), veth5cc2d7a (), veth94ad141 (), veth78616a5 (), veth8e63670 (), veth6fa8856 ()
ipv6_addresses lo (::1/128), end0 (2603:900a:1bf0:b350::1099/128, 2603:900a:1bf0:b350:2c2d:cbb1:d9d1:8a47/64, fe80::8aee:29c4:2077:2413/64), hassio (fe80::42:c8ff:fe9c:da28/64), docker0 (fe80::42:f5ff:fed5:941f/64), veth600d57f (fe80::5c0b:14ff:fea3:ab72/64), veth7f095a5 (fe80::d06a:95ff:fe56:743b/64), veth5cc2d7a (fe80::2cb1:48ff:fec2:bca9/64), veth94ad141 (fe80::9883:e2ff:fe20:d763/64), veth78616a5 (fe80::a83a:8aff:fecf:747d/64), veth8e63670 (fe80::4c8e:c7ff:fe6f:7efe/64), veth6fa8856 (fe80::545b:3cff:fe81:c712/64)
announce_addresses 192.168.1.141, 2603:900a:1bf0:b350::1099, 2603:900a:1bf0:b350:2c2d:cbb1:d9d1:8a47, fe80::8aee:29c4:2077:2413
Recorder
oldest_recorder_run March 2, 2025 at 10:25 PM
current_recorder_run March 14, 2025 at 9:54 AM
estimated_db_size 28.18 MiB
database_engine sqlite
database_version 3.48.0
Spotify
api_endpoint_reachable ok

What type of installation are you running?

Home Assistant OS

Diagnostics information

Spotcast was successfully installed, so HACS logs are irrelevant. The error is thrown during configuration, so debug mode can’t be configured for Spotcast.

However, I have provided the HA logs: home-assistant_2025-03-14T14-01-02.273Z.log

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 88 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I’m not contributing to this project, don’t have the skills, but I just wanted to hop on here and say thank you to all who are working on finding a fix. My family’s wakeup routine, and many others around the world, are depending on this 😂

Image

official v4.0.1 is released. Closing this ticket…

Finally

For anyone getting errors yes currently spotcast will be broken. They implemented a new multi-factor scheme and we are not compatible with it. Until a new version of spotcast is released expect your it to not work

So Spotify changed their message on the access_token endpoint:

As reported in #530 they now report:

Failed to set up: 400:

{
  "error": {
    "code": 400,
    "message": "Unauthorized request",
    "extra": {
      "_notes": "Usage of this endpoint is not permitted under the Spotify Developer Terms and Developer Policy, and applicable law"
    }
  }
}

I would actively suggest right now for anyone to deactivate their spotcast integration for the time being until we have clearer picture of what actions Spotify are willing to take at this point.

Soon™

@bkeys818 looks like Spotify started to add a 2 factor authentifaction with logins to the web browser. Just checked and its not just the setup that is broken, current install are also breaking. This might take some times before being able to fix, if possible

@misiektoja thanks for the gist. Turns out in my case, I had a small mistake in the hex string format function causing to cascade into a bad secret.

I seem to be able to get an access token now. Should be on the right track for a fix

Two new builds have been released v4.0.1-b1 and v5.0.0-b33. Both added a better parsing of authentication failure in case of error 302.

a beta version (build 31) was released with the TOTP fix. I’ll wait for reviews of the beta version and then release the production version.

I’ll take a stab at it later today 👍

I would like to thank you for your investment, which is very, very much appreciated !

Could this be the reason I started to get “Could not get spotify token” errors a couple hours ago?

Released build 32 to solve the issue where the _test_token method was not awaited. The process should now truly test that the token provided is a valid one.

@bendikrb thanks for the info, I’ll have time during the week, so I’ll check if I can find a fix.

A build candidate v4.0.1-b0 has been pushed to prerelease. Working well on my end. I’ll wait a bit for reports from other user before officially releasing it as production build

@Kagey-cmd don’t worry I’ll be releasing a V4 version I just wanted to stress test in the dev channel first. I’m working on the V4 version now.

Same here thanks the work guys, really appreciate it, as this kind of thing is way above my understanding.

On Tue, 18 Mar 2025, 12:56 PilotSteveNW, @.***> wrote:

I’m not contributing to this project, don’t have the skills, but I just wanted to hop on here and say thank you to all who are working on finding a fix. My family’s wakeup routine, and many others around the world, are depending on this 😂

image.png (view on web) https://github.com/user-attachments/assets/20504936-d98d-437a-8bed-ec991eb2f649

— Reply to this email directly, view it on GitHub https://github.com/fondberg/spotcast/issues/524#issuecomment-2733127062, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7YJPQ7CI5H6T4LSHGMBLFD2VAJZVAVCNFSM6AAAAABZAZUF52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZTGEZDOMBWGI . You are receiving this because you commented.Message ID: @.***> [image: PilotSteveNW]PilotSteveNW left a comment (fondberg/spotcast#524) https://github.com/fondberg/spotcast/issues/524#issuecomment-2733127062

I’m not contributing to this project, don’t have the skills, but I just wanted to hop on here and say thank you to all who are working on finding a fix. My family’s wakeup routine, and many others around the world, are depending on this 😂

image.png (view on web) https://github.com/user-attachments/assets/20504936-d98d-437a-8bed-ec991eb2f649

— Reply to this email directly, view it on GitHub https://github.com/fondberg/spotcast/issues/524#issuecomment-2733127062, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7YJPQ7CI5H6T4LSHGMBLFD2VAJZVAVCNFSM6AAAAABZAZUF52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZTGEZDOMBWGI . You are receiving this because you commented.Message ID: @.***>

@bendikrb thanks for the info, they might be using multiple schemes for the details. I’ll try to test everything when I’m back home after work

When can we expect a fix for this?

I just wanted to confirm to everyone, you don’t have to move to the V5 beta, I only used that version as a testing ground, I will be create an update for V4 as well after I have confirmation that the fix is working well in the beta.

@thlucas1 Yeah the retry scheme was already pointed out by Spotube developer.

Personally the delay wasn’t necessary, also I moved to the current query format which you can find in the current dev version (on phone hard to provide link).

I have a feeling that using the scheme you provided might result some times in the wrong token being provided while the new one with a server and client TOTP is the one used by spotify at the moment of writing.

Anyway I’ll be releasing soon in the dev branch my current solution is working well and using an Api call to test the token works well.

From reddit, I was pointed out to this fix from spotube. Looks like a cipher has to be solved in order to get the token now.

https://github.com/KRTirtho/spotube/commit/59f298a935c87077a6abd50656f8a4ead44bd979

Hi everybody, thanks a lot for the fix. It seems spotcast.start des not exist anymore after updating. I need to use play_media instead. Do you confirm?

Thank you 🙂

where do i find OAuth-client-id and secret so i can try the beta 😃

Guys, just read the doc if you want to test v5 but don’t ask general questions here.

The fix works for me as well. Thank you very much.

@XalaTheShepard try spotcast.play_media

Thank you so much ! My family is counting on you. You rock 🥳.

I also started getting “Could not get spotify token” errors from v4. That’s why I initially tried to install the beta.

v4.0.1-b1 is working perfectly for me too on amazon echo + google nest. Thanks!

@Pirol62 please this is not a forum thread this is bug ticket if you have question open another ticket this is polluting discussion around a bug.

There are lots of reasons for the architecture range and you should expect them when a project goes through a full refactor. If you have question aboit the V5 refactor ask them in the V5 refactor discussion ticket please

Hi, after a lot of recoding (when the spotify card stopped working I developed my own spotify dashboard), I got it working now. Creating a second oAuth was easy and worked perfectly. Thanks for your hard work so quick! One minor issue: But after the upgrade to 5.x HA doesn’t finish the reload process anymore. The popup which shows the progress of the loading procedure never diappears again so I have to close it manually. Does anyone else have this behavior?

And last but not least a question: You decided, to create own devices for the media players. As I have a lot of echos and use an input_select to choose the target player group, I had to write a mapper in order to translate the origin media players into the spotcast ones:

{% macro spotify_music_source(pinit) %}
    {% set map = {
    "Alle Etagen": "media_player.alle_etagen_cb747t7njdc02skcet2oogkyl_spotcast",
    "Hauptraum": "media_player.hauptraum_cb747t7njdc02skcet2oogkyl_spotcast",
    "Receiver": "media_player.receiver_cb747t7njdc02skcet2oogkyl_spotcast",
    "Erdgeschoss": "media_player.erdgeschoss_cb747t7njdc02skcet2oogkyl_spotcast",
    "Home Office": "media_player.home_office_cb747t7njdc02skcet2oogkyl_spotcast",
    "Wohnzimmer": "media_player.wohnzimmer_cb747t7njdc02skcet2oogkyl_spotcast",
    "Unten": "media_player.unten_cb747t7njdc02skcet2oogkyl_spotcast"}
    %}
    {{ map[pinit] if pinit in map else 'media_player.receiver_cb747t7njdc02skcet2oogkyl_spotcast' }} 
{% endmacro %}

and then i.e:

command_play_piano:
  variables:
    player: "{{states('input_select.music_sources')}}"
  sequence:
    - service: spotcast.play_media
      data:
        media_player: 
          entity_id: >
            {% from 'global_functions.jinja' import spotify_music_source %}
            {{ spotify_music_source(player) }}
        data:
          shuffle: true
        spotify_uri: "spotify:playlist:37i9dQZF1DX4sWSpwq3LiO?si=c082538406174a56"
    - service: input_text.set_value
      data:
        entity_id: input_text.current_spotify_uri
        value: "spotify:playlist:37i9dQZF1DX4sWSpwq3LiO?si=c082538406174a56"

Why did you choose that way?. My fear is, that when spotify rescans or reloads the device list, that all identifiers will be changed.

@thlucas1 thanks yeah I wanted to move to parsing the query portion and look for the key anyway, that way it’s going to be way simpler even if the format changes again

@mpw83 , many thanks for the information. It is working now. However, I cannot find the shuffle modus for it. For V4 I had the following line: random_song: true but this doesn’t work anymore. Could you please inform me if this is still available?

There’s random in the documentation: https://github.com/fondberg/spotcast/blob/dev/docs/services/play_media.md

Please don’t ask more general questions about v5 in this thread, there is a dedicated one here.

Edit: where you are cross-posting already…

@XalaTheShepard yes the services have changed quite a bit in V5. I would suggest you read the release note and the documentation. Edit: More specifically, the service definitions

V5 has been in testing since November. As per my last comment in this ticket. I only used it as a testing bed for the fix. If you still prefer to stay on V4, the fixed version should be available soon.

Hi there, I spent some time going through the gist shared by @bendikrb, attempted to replicate the behavior in Spotube’s Dart code, made some logical changes and I got it working:

PoC: spotify_monitor_totp_test.py, more info in the Debugging Tools section of the spotify_monitor project.

It might require some cleaning as I played with different options. BTW, sp_key is not needed.

EDIT: updated link

Not entirely related and mainly out of curiosity, isn’t it possible to follow an actual web based login flow and just get an access token and refresh token to renew when it expires, instead of the cookie stuff? 😃

There all a lot of functionalities that relies on the cookie. The most important of them is the registration of Chromecast device. The public Api doesn’t allow for it.

This was discussed in more details #452