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

Thank you so much for this component, it’s fixed one of my pet peeves.

I use a Chromecast attached to my AVR to play Spotify and control it with my Harmony Elite. I’m already using Emulated Roku to control playback but have always had to start something playing on the device and then manually select the device in the Spotify app after. Other members of the family also use the AVR so same issue for them.

Now I’ve set up your component with each account and, using automations through Emulated Roku again, after hitting the Play Music activity on the remote they get a screen to select which account they want to use eg Dad’s Account, Sam’s Account etc. Couldn’t be simpler and app is ready to go straight away, especially using it on my Mac where you can’t select the Chromecast as a device and have to start the web app in Chrome to be able to cast.

1 Like

Hey, i’m having the exact same problem. I’m using Hassio. Can you tell me how you fixed it?

Did you find the solution for this? I get the same error message when I try to use the component.

This is the standard log message when having any custom component installed. It is not spotcast specific

I can’t get this one working :confused:

400 Client Error: Bad Request for url: https://accounts.spotify.com/api/login

That is the mesasge I’m getting. When I try to call the service only providing a entity_id and a spotify uri.
I have configured my user and password as described in the docs:

spotcast:
  username: !secret spotify_geir_username
  password: !secret spotify_geir_password
  accounts:
    geir:
      username: !secret spotify_geir_username
      password: !secret spotify_geir_password
    grethe:
      username: !secret spotify_grethe_username
      password: !secret spotify_grethe_password

When I try to use the service in the tester it works:

entity_id: media_player.bathroom_speaker
uri: "spotify:playlist:37i9dQZF1DX3yvAYDslnv8"

When I try to use the service in a script it fails:

  chromecast_spotify:
    alias: Play Spotify
    sequence:
      - service: spotcast.start
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio", "Home Group") %} media_player.home_group
            {% elif is_state("input_select.chromecast_radio", "Badkamer") %} media_player.bathroom_speaker
            {% endif %}
          uri: >
            {% if is_state("input_select.music_source", "Test") %} "spotify:playlist:37i9dQZF1DX3yvAYDslnv8"
            {% endif %}

error:

Error executing service <ServiceCall script.chromecast_spotify (c:82f0847dc0ca4c1983f7fc5151ad9c2e)>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 121, in _internal_call
    r.raise_for_status()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/me/player/play?device_id=a15e1206e07dd02a1d0b7bc3e8bae3f1

The templates works, if I copy them into the template tester, the output is correct.

Any idea?

Sorry but I can’t help but are you sure the URI is correct when sending to spotcast from the script?

Yes, I use the same url in the tester as in the script.
In the error there seems to be something wrong with the url to playing to a device id…

What is very strange it works in the tester, but not in the script…

The usage of data_template is supported?

After upgrading Home Assistant to 0.104.0, I am encountering something weird:

When I try to start a playlist from a script, it doesn’t work.

Starting music from the Spotify-card on an idle speaker group is working flawlessly, however.

My script is:

play_music:
  alias: Play Spotify on home group
  sequence:
  - service: spotcast.start
    data:
      device_name: "Home group"
      uri: "spotify:playlist:3rIRPguVt95QoLoxroLx9x"

The error I’m getting:

[record[a,in-unique,aa776170-1968-6d4f-d738-48efdcc25617.local.]=120/119,172.20.1.131:42613] Failed to connect, retrying in 5.0s

I have checked and the IP mentioned above corresponds to one of the Google Mini speakers. This particular speaker is connected, part of the speaker group, and also plays music when I start it from the Spotify-card. I power cycled the speakers, but it doesn’t help. I also removed and re-added the Google Cast integration and all cast entities.

Any ideas?

I see the exact same thing when trying to call the service directly through the dev panel and through a script or automation.

It is not limited to a speaker group. I also see it when trying to cast directly to a device

Shit, they merged the change to upgrade zeroconf in hass. This makes chromecast (all chromecasts not only spotify) failing to start.
This needs to be reported back to HASS main project on the chromecast sub project.
Workaround is to downgrade zeroconf to the previous version

1 Like

Also spotify-card doesn’t work for me:

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 419, in _async_add_entity
await entity.async_update_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 284, in async_update_ha_state
self._async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 314, in _async_write_ha_state
attr = self.capability_attributes
File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 791, in capability_attributes
if supported_features & SUPPORT_SELECT_SOURCE:
TypeError: unsupported operand type(s) for &: ‘NoneType’ and ‘int’

1 Like

hello all,

same for me…

same error like @blackscreener

@frenck is working on it !!! https://github.com/home-assistant/home-assistant/pull/30717

Meh, it doesn’t work because spotify free account, with premium and spotify-card it plays. But that error still persist in HA logs and media_player.spotify entity doesn’t exist.

I’m seeing a lot of bugs with entities with the latest update on different topics. I think I’ll hold out on updating from 102.3 (103 had a bug with Zwave Radiators and I had to roll back then).

Downgrading zeroconf (with custom component as I’m using Docker) didn’t solve the problem for me. It’s pychromecast that throws an error in the log.

Spotify-card and spotcast does not use mediaplayer SELECT_SOURCE so you must be following some old setup for the built in spotify mediaplayer

Anyone with the problem of Failed to connect, retrying in 5.0s should try this: balloob/pychromecast#332

Actually that is only a rewrite. The purpose of spotcast is to start playback on a chromecast which requires the more powerful browser login token. It has always been my goal to make spotcast redundant but that would require that the spotify integration in home assistant would make it possible to use the browser token which I doubt would happen as it is scraped and unofficial

Just released v.2.6.0 which pins the zero conf version to 0.24.3 which should make it work again. 0.24.4 didn’t contain that much so I think it is safe to use 0.24.3.
It is kind of a rewrite so please help test it.