Spotcast - custom component to start playback on an idle chromecast device

Thank you. I had read those posts and gave device_name a try, but using that same syntax, I keep getting ‘Failed to call service spotcast.start. Unknown error’ in the Developer|Services Tools and ‘Failed to call service spotcast/start. ‘NoneType’ object is not subsriptable’ when actually trying it with a service call from Mini Media Player. The only seemingly relevant difference between our setups is Google vs Echo devices. Does Google allow for more than one Spotify account to be connected to a Google Assistant (Home?) device at a time?

EDIT: I have also tried the media_player entity_id. Same errors.

Yes, but I don’t think that should matter here?
Have you tried the spotcast call specifying the account?

- service: spotcast.start
  data:
    account: <your account name>
    device_name: Dining Room Hub
    uri: spotify:playlist:37i9dQZF1DXbYM3nMM0oPk

One of my children who is older has their own Spotify account (under our Family plan). I have configured spotcast with their sp_dc and sp_key and successfully used that account in their original preset buttons.

However, going by this, the main house account is configured without a name (a default of sorts).

I’ve tried using that default account (no account specified) and my child’s account. Same issues.

Here’s a debug log:
Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/spotcast/spotcast_controller.py:187
Integration: Spotcast (documentation, issues)
First occurred: 3:34:02 PM (1 occurrences)
Last logged: 3:34:02 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: ‘NoneType’ object is not subscriptable

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 447, in _async_step await getattr(self, handler)() File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 680, in _async_call_service_step await service_task File “/usr/src/homeassistant/homeassistant/core.py”, line 1627, in async_call task.result() File “/usr/src/homeassistant/homeassistant/core.py”, line 1670, in _execute_service await self._hass.async_add_executor_job( File “/usr/local/lib/python3.9/concurrent/futures/thread.py”, line 58, in run result = self.fn(*self.args, **self.kwargs) File “/config/custom_components/spotcast/init.py”, line 190, in start_casting spotify_device_id = spotcast_controller.get_spotify_device_id( File “/config/custom_components/spotcast/spotcast_controller.py”, line 200, in get_spotify_device_id spotify_device_id = self._getSpotifyConnectDeviceId(client, device_name) File “/config/custom_components/spotcast/spotcast_controller.py”, line 187, in _getSpotifyConnectDeviceId for device in devices_available[“devices”]: TypeError: ‘NoneType’ object is not subscriptable

Hmm. So in my spotcast setup I redefine the default account to give it a name. I would try that and try calling it with that account.

Another question. Do you see the media player you are trying to target in sensor.chromecast_devices attributes? I’m wondering if your Echo is being picked up as a Spotify Connect device for spotcast.

Have you ever succesfully started Spotify with spotcast on that echo?

Edit. Nvm. I see above it was working.

spotcast: # https://github.com/fondberg/spotcast
  sp_dc: !secret HASSIO_SP_DC
  sp_key: !secret HASSIO_SP_KEY
  accounts:
    hassio:
      sp_dc: !secret HASSIO_SP_DC
      sp_key: !secret HASSIO_SP_KEY
    jazzyisj:
      sp_dc: !secret JAZZYISJ_SP_DC
      sp_key: !secret JAZZYISJ_SP_KEY
    sherigagnon:
      sp_dc: !secret SHERI_SP_DC
      sp_key: !secret SHERI_SP_KEY

Hmmm…I gave it a try. Here’s my updated !include’d yaml

sp_dc: !secret spotcast_family_sp_dc
sp_key: !secret spotcast_family_sp_key
country: US
accounts:
  family: #new line
    sp_dc: !secret spotcast_family_sp_dc #new line
    sp_key: !secret spotcast_family_sp_key #new line
  dad:
    sp_dc: !secret spotcast_dad_sp_dc
    sp_key: !secret spotcast_dad_sp_key
  child:
    sp_dc: !secret spotcast_child_sp_dc
    sp_key: !secret spotcast_child_sp_key

I restarted HA and tried the service call again. Same error.

Is the media player listed in sensor.chromecast device attributes?
Are you trying to start spotify directly from dev_tools to test it?
Can you post the service call yaml you are using?

No. These are Amazon Echo (Spotify Connect) devices presented as media_player entities in HA.

Here is the service call I’m using to test.

service: spotcast.start
data:
  uri: spotify:playlist:37i9dQZF1EIYtCYWOqKQq0
  force_playback: true
  account: family
  device_name: Echo Dot Living Room

Ah. I have all cast devices. I thought the chromecast_devices would have picked up the Spotify Connect devices also. And yeah your service call looks ok…

Do you have any other media players that spotcast does work on? Do you have any spotcast errors on startup? You’re sure the credentials haven’t expired?

You might have to open an issue on the github. I think I’m all out of ideas.

I’m fairly certain the sp_dc and sp_key are still good since the service call works with a renewed Spotify Device ID, but never the other two “device types.” But, I’m not certain the token isn’t expiring after 1-2 days. Wouldn’t an expired token only affect the use of a Spotify Device ID though?

I’ll head over to GitHub. Thanks for your help!

If your Spotify token has expired the account won’t work at all.

They don’t usually expire unless you log out of the account somewhere. I can’t remember the last time I’ve had to update mine.

Good luck, hope you get it worked out!

Just curious to see if anyone has managed to cast to a mobile phone running the Spotify App?
I have captured the Spotify connect ID of my Samsung S20, but Spotcast does not recognise it as as device when I run the service.

I have found that Spotify Connect devices are “locked” to the Spotify account that last used that device. They would not be available under Spotcast until I use the Android App with the account that I want to use and select that device again. I have a number of Spotify Connect devices - say Living Room and Bedroom, and two accounts A and B. If account A has connected to Living Room then Living Room is no longer available to account B. The Living Room device can be seen if account B uses an Android Spotify App to scan for Spotify Connect devices, and can be called by the spotcast.start service with account B after it has been selected using the Android Spotify App.

I can’t seem to find a way around this without using the Android Spotify App.

Thanks, that’s been my experience as well.

Here’s the issue I started on GitHub:

Do you find that Spotcast stays connected via Spotify ID as long as you don’t change the associated Spotify account? If you do change accounts and then reconnect later with that same account, do you find the Spotify ID has changed? Have you had success using Spotcast on those Spotify Connect devices using Entity ID?

Hi guys,

I cant get repeat to work? What am I doing wrong this is what my JSON looks like in a call service node

{"spotify_device_id":"xxxxxxxxxxx","repeat":"true","uri":"spotify:track:1KYHsn2EiJgVLZ1nw4h5JU"}

What am I missing here?

Thanks

I have to write: I’m so grateful that I felt on this chat… I’m starting right away to configure the spotcast.start which should fix my problemsssss

Tak

Hello,

Just seen this new integration supporting Google cast among other devices/protocols : https://github.com/music-assistant/hass-music-assistant#music-assistant

Has anyone tested to compare with our lovely spotcast? I like spotcast but have to reboot HA and update the keys from time to time. Not a big deal and still very glad of the work that has been done on this component, but I wonder if this new option could benefit from more resources to support it and more stability ?

1 Like

Hey all,

So it looks like repeat is broken (ive submitted a bug report on github). Is anyone else repeating things in Spotify? I’m using it to play some white noise during the night.

Does anyone have a workaround for repeat being broken?

Thanks :slight_smile:

EDIT####

So, im not sure if this has now been fixed or the doco was just wrong. But repeat is now working with;

"repeat":"track"

Hello all,

I’m trying to resolve problems with my Spotcast use case.
When I’m going shower, motion detection is starting my playlist.
Unfortunately, sometimes I got errors like:
Could not get spotify token
Cound not get device ID
or
Error: http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=blablabla: Device not found, reason: None

So I started to use continue_on_error flag from recent changes to repeat until my google home mini start spotify playlist. Unfortunately I’m still stuck with:
Error: http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play device_id=4a6386d57172e18e0103de65e9a5a574: Device not found, reason: None

I believe it can’t find device because it’s not available source (checked with spotify API).
How to get past that?

1 Like

I have a generic question: After how long do the tokens/cookies expire ?
My Spotify-Card stopped working a few days ago and I realized it relied on Spotcast. I then followed the Spotcast installation process again, and then realized I just had to update the sp_dc and sp_key cookies.
It might be obvious for people who often read the debug logs, but for random users like me, it would be great to get a notification on the Home Assistant left panel when the tokens have to be renewed. That would really help understand what’s wrong and save a lot of time :slight_smile: !

I have the same issue. Did you solved it yet?

When I enter the url in a browser, the following pops up:

{
“error”: {
“status”: 401,
“message”: “No token provided”
}
}