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

Thanks, I thought you could just search, but indeed + gives even more :wink:

Hey, maybe you can help me with something here @ASNNetworks :slight_smile:
I have a selection now and working but the dropdown alignment is terrible:

Is there a way to align it better and keep it in the card when it comes to width? I have CSS styling options but just don’t know what to style :slight_smile:

drpdwn1

drpdwn2

I don’t think you can change that. At least, I haven’t tried it myself. I have wider cards than your example, so I don’t have that issue myself.

Hi all, this looks like a great addon, I just seem to be having an issue with my Google home device.
Everything seems to be setup correctly, I have the spotcast.start service available and don’t get any account errors. It’s just my device that isn’t detected at all, whether I use entity or device name.

Upon reading through a lot of the replies, I noticed I don’t have the sensor.chromecast_devices. Does this need to be added before it will detect Google home devices?

You do not need the sensor
You need premium account but if you have that
You can try using the spotify-card which lists the cast devices and is a good way to get you started

Hi everyone! For some reason I can’t seem to get Spotcast to work.

My setup:
Home Assistant 0.113.0
Spotcast v3.3.5
Spotify-Card v2.0.0-beta26
Google Nest Mini (v2)

The card works fine when I play something on another device. I can also transfer the song I play to a Spotify Connect device in the card, but when I want to start a playlist and stream it to a Chromecast device (my Google Nest Mini) I get an error:

spotipy.client.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play&device_id=e9e54a419bb1f37a28c8v740510b18f0:error

(changed the device_id a bit cause I don’t know if I can expose that)

When I open the URL I see this:

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

Does anyone know how to solve this?
Your help is very much appreciated! :slight_smile:

Can you provide home assistant logs with debug on for spotcast

1 Like

Is this what you’re looking for?

Logger: homeassistant.components.websocket_api.http.connection.1912327616
Source: custom_components/spotcast/init.py:269
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 13:25:00 (1 occurrences)
Last logged: 13:25:00

http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play&device_id=***************************: error
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/spotipy/client.py”, line 121, in _internal_call
r.raise_for_status()
File “/usr/local/lib/python3.8/site-packages/requests/models.py”, line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/me/player/play&device_id=***************************

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 125, in handle_call_service
await hass.services.async_call(
File “/usr/src/homeassistant/homeassistant/core.py”, line 1250, in async_call
task.result()
File “/usr/src/homeassistant/homeassistant/core.py”, line 1289, in _execute_service
await self._hass.async_add_executor_job(handler.func, 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 326, in start_casting
play(client, spotify_device_id, uri, random_song, repeat, shuffle, position)
File “/config/custom_components/spotcast/init.py”, line 269, in play
client.start_playback(**kwargs)
File “/usr/local/lib/python3.8/site-packages/spotipy/client.py”, line 913, in start_playback
return self._put(self._append_device_id(“me/player/play”, device_id), payload=data)
File “/usr/local/lib/python3.8/site-packages/spotipy/client.py”, line 190, in _put
return self._internal_call(‘PUT’, url, payload, kwargs)
File “/usr/local/lib/python3.8/site-packages/spotipy/client.py”, line 128, in _internal_call
raise SpotifyException(r.status_code,
spotipy.client.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play&device_id=***************************:
error

I did some digging myself. First I tried to get the device ID with:

curl -X "GET" "https://api.spotify.com/v1/me/player/devices"

It showed me my Google Nest Mini, but only when it’s active.

{
      "id": "**************************",
      "is_active": true,
      "is_private_session": false,
      "is_restricted": false,
      "name": "Nest Mini",
      "type": "CastAudio",
      "volume_percent": 21
    },

Then I tried to play something to my Nest Mini:

curl -X "PUT" "https://api.spotify.com/v1/me/player/play?device_id=********************"

I got this:

{
  "error": {
    "status": 404,
    "message": "Device not found"
  }
}

Seems like Spotify doesn’t recognize my device, am I correct?

I heard others having issues with the mini. I don’t have one myself so I can’t debug I’m afraid.

Does it work on other cast devices?

No, I’ve also tried to cast to my Chromecast. Same result unfortunately :frowning: Also tried to reinstall spotcast, Spotify integration and Google Cast integration.

If you have any suggestions, or if I can test something, please let me know. I would just love the spotcast functionality!

This is brilliant, thankyou :slight_smile: at least I know its not me and I can stop messing with it.

1 Like

Hi,
This seems like a really interesting component, thanks a lot for your effort.

However I am struggling to get it to work with the Spotify Connect Devices I want to use it with.

Just to confirm, and for troubleshooting purposes; If I cannot see the speaker in the web player, will I not be able to use it with this component? (It’s not a Sonos speaker, and I can see it in the mobile client and PC client).

Also, what is the correct way to obtain the “spotify_device_id”? I tried using https://developer.spotify.com/console/get-users-available-devices/ but I could not find it. (Possibly because of the same reason as mentioned above).

Thanks.

EDIT: If I manually start the playback from the mobile client or PC client, I was able to find the “spotify_device_id” and start the playback from the “spotcast.start” service. However if i play to the device from another account, or switch it off/on, it will disappear and I can no longer start the playback. This is the same limitations as the built-in “Source” selector in the Spotify component, and exactly what I was hoping to overcome. Any advice, or is it simply not possible? Thanks again.

Have a look at how the spotify card uses it wrt to spotify_device_id

If you are using the sensor please upgrade to v3.4.0.
I have now released a version of spotcast which doesn’t use pychromecast discovery anymore as it caused issues with core.
See release notes on:

Installed 3.4.0 on HA 0.112.4 and got this error:

2020-07-31 12:12:46 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.chromecast_devices fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 272, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    self.update  # type: ignore
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/spotcast/sensor.py", line 61, in update
    for k in known_devices
  File "/config/custom_components/spotcast/sensor.py", line 61, in <listcomp>
    for k in known_devices
TypeError: 'set' object is not subscriptable

In console i get:
Schermata 2020-07-31 alle 12.18.53
Maybe this release works only on HA -> 0.113?
EDIT: With HA 0.113.1 it works again !!!

as stated in the manifest.json it needs ha >=0.113

1 Like

Actually i am getting this when i try to choose the device where to play:

Schermata 2020-08-04 alle 13.07.56

How to get the list of the chromecast devices?
I really don’t know if this happens after latest release of spotcast.

Don’t know if it’s related to spotcast component or to spotify card but after a reset i get this error and no more i am able to choose and play spotify playlists…

2020-08-04 17:45:07 ERROR (SyncWorker_1) [spotipy.client] HTTP Error for PUT to https://api.spotify.com/v1/me/player/play returned 404 due to Player command failed: No active device found

And if i go to that link i get:

{
  "error": {
    "status": 401,
    "message": "No token provided"
  }
}

You running 0.113.3?

No, 0.113.1