spotcast: Failed to get device id from spotify

Hi all, many thanks to @fondberg for the great component. So I was able to manage the requirement that my kids are able to ask our google home minis to play a random album. They are using it since months in during the covid pandemic…

Since yesterday evening the spotcast component can’t start any playback. I already restarted my home assistant instance and inserted new values for sp_dc and sp_key to be sure that the token is valid. No updates are made since last week.

Spotcast is build up a connection to my Google Home (I can hear the “bling”) but then I got the message “Failed to get device id from spotify”.

2021-03-23 08:08:53 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [1860452328] Failed to get device id from Spotify
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 141, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1488, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1523, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 218, in service_handler
await script_entity.async_turn_on(
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 323, in async_turn_on
await coro
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1041, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 262, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 466, in _async_call_service_step
await self._async_run_long_action(service_task)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 428, in _async_run_long_action
long_task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1488, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1523, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 218, in service_handler
await script_entity.async_turn_on(
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 323, in async_turn_on
await coro
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1041, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 262, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1488, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1527, in _execute_service
await self._hass.async_add_executor_job(handler.job.target, service_call)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/spotcast/__init__.py", line 296, in start_casting
spotify_device_id = spotify_cast_device.getSpotifyDeviceId(client)
File "/config/custom_components/spotcast/__init__.py", line 478, in getSpotifyDeviceId
raise HomeAssistantError("Failed to get device id from Spotify")
homeassistant.exceptions.HomeAssistantError: Failed to get device id from Spotify

Playback using open.spotify.com or the app is working without any issue on the chromecast devices.

Any hints?

Thanks, Kai

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 29
  • Comments: 51 (16 by maintainers)

Most upvoted comments

Hello everybody.

Open source is great and free which in the case of just one person going the work (me) can lead to situations where during periods of sick leave or pressing matters elsewhere (work) thiings piles up.

I would urge you to put efforts into trying to help out by fixing things through pull requests rather than say something is broken several times and come up with arbitrary non version controlled patches.

I too noticed this is broken and if no one chips in i will try and fix it when i have time

Why does everyone on github feel the urge to spam. Just click on the notification bell if you want to be alerted or say something useful…

Please don’t respond to this, I know it’s spam, too, but I would like to save my postbox from more of this “Same”.

Just for clarity of people who might need this in the future. To implement the “dirty fix”, edit the __init__.py file (found in /config/custom_components/spotcast/__init__.py and paste the contents of this file (init.py), replacing all that is currently there. Save and reboot HA.

Also, something to note, this change will likely get overwritten if you update the component (although, hopefully, the issue is fixed by the time the next release rolls around)

Hi, Same here, i thought the dirty fix solved the problem but my devices ID don’t stay for long in spotify API. If something is already playing on my device launched from the app, i can launch anything else with spotcast. But if my device is idle for a moment. Spotcast return an error considering the ID isn’t known by spotify. If i check on spotify web api, my devices is empty Any idea why spotify doesn’t keep my devices in memory ? is there any workaround ? (Not exactly a issue with the dirty fix but if you have ideas 😃 )

tl;dr It seems that spotipy.Spotify.devices() is broken. A “normal” API request via the spotify web console does work and shows the device (after the “bing”). I worked around this problem with my commit https://github.com/provinzio/spotcast/commit/c6b29531fb0836c7665a020c18fc33a99fba9dc3 which makes it usable again.


Which means, that we have to get the device ids manually…? Sounds cumbersome, but I can’t see a better way at the moment. I would love to know, how the app is handling this…

It’s quite easy to get the device id over the spotify web console. Just start the device with the app and run the API request.

Edit: nvm, that doesn’t work properly…

Edit2: The error states known devices: [], but looking at the web api console, I see multiple devices. It seems like the spotipy.Spotify.devices() function is broken.

Edit3: This might be the relevant issue in spotipy https://github.com/plamere/spotipy/issues/659

Edit4: My current assumption is, that the credentials do not have the required permissions to get the devices… but it’s obscure why spotipy is not raising an error on this. I did a real nasty fix, ignoring the check, so that spotcast works for me again (https://github.com/provinzio/spotcast/commit/c6b29531fb0836c7665a020c18fc33a99fba9dc3).

Edit5: I moved my dirty fix to a proper branch https://github.com/provinzio/spotcast/tree/dirty-fix-device

Mhh… I can’t say any other than it works for me… If these points don’t help you, I have unfortunatly no idea. We should have a deeper look into spotipy.Spotify.devices() which is not part of this repo.

  • Does your selected token from the web api have the correct permission? It asks me which permissions it should have after I click Get Token
  • Does your chromecast device make the “bling” sound?
  • Hit the “Try it” button a few times after the bling.
  • Does the API work at all for you? My desktop (with opened spotify) is always shown in the list.

You might want to try my dirty fix https://github.com/provinzio/spotcast/commit/c6b29531fb0836c7665a020c18fc33a99fba9dc3.

Edit: I moved my dirty fix to a proper branch https://github.com/provinzio/spotcast/tree/dirty-fix-device

Mhh… I can’t say any other than it works for me… If these points don’t help you, I have unfortunatly no idea. We should have a deeper look into spotipy.Spotify.devices() which is not part of this repo.

  • Does your selected token from the web api have the correct permission? It asks me which permissions it should have after I click Get Token
  • Does your chromecast device make the “bling” sound?
  • Hit the “Try it” button a few times after the bling.
  • Does the API work at all for you? My desktop (with opened spotify) is always shown in the list.

You might want to try my dirty fix c6b2953.

The dirty fix works perfectly on all the google home we have (each bedroom has a home mini used as an alarm clock with an automation + scheduler_card + spotcast). Thank you for the dirty fix while waiting for a more logical solution

I can also confirm that the dirty fix solves the issue, for now.

Hi all,

I am having this issue for a week now. I have a script starting with a spotcast.start to wake me up nicely that has been running great for months but not since last week: it stops due to “Failed to get device id from Spotify”

Strangely enough, when I restart the script manually a couple minutes later, it works fine again. I have updated my keys to be sure, but that didn’t help.

Anyone else with the isuue?

Same issue here. It seems like the first call which fails with an error wakes up the Chromecast and opens the Spotify App. Now Spotcast is able to retrieve the device id in the next call and it will start playing. I managed to make it work with the workaround seen below:

action:
  - service: spotcast.start
    continue_on_error: true
    data:
      uri: ***
      entity_id: ***
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: spotcast.start
    data:
      entity_id: ***
      uri: ***
      force_playback: true
      random_song: true
      shuffle: true
      start_volume: 100

Hi all,

I am having this issue for a week now. I have a script starting with a spotcast.start to wake me up nicely that has been running great for months but not since last week: it stops due to “Failed to get device id from Spotify”

Strangely enough, when I restart the script manually a couple minutes later, it works fine again. I have updated my keys to be sure, but that didn’t help.

Anyone else with the isuue?

@ludwigvdb by any chance did you find a solution to your issue with ‘devices disappearing’?

Hi, I didn’t find any direct solution for this issue, BUT with the last HA update and the last spotcast update everything works fine again 😃 (NB : SPOTIFY plugin is now necessary for spotcast to work)

Hello everybody.

Open source is great and free which in the case of just one person going the work (me) can lead to situations where during periods of sick leave or pressing matters elsewhere (work) thiings piles up.

I would urge you to put efforts into trying to help out by fixing things through pull requests rather than say something is broken several times and come up with arbitrary non version controlled patches.

I too noticed this is broken and if no one chips in i will try and fix it when i have time

take care @fondberg

@justincrosby well, that’s because this PR includes this “dirty fix” 😀