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

Perhaps a strange question, but is it possible to use this as a Spotify Connect proxy, similar to AirConnect? That way the Echo Speakers will show up in the spotify app as destinations for anyone on my local network.

Thanks!

~Spritz

Hi,
i am trying to control my denon avr via spotcast. i added the reciever via the denon integration, and got the entity “media_player.denon”. when the reciever is off, i only get my amazon echo devices listed via the spotify api, but not the denon. only when i turn it on and start a playlist on the denon via my android spotify client, it is also listed in the api. then i can also control the playback via a script in HA by device name “denon” or spotify divice id. however, when i call the reciever via the entity id, i get the following error messages:

  • Could not find device denon from hass.data
  • spotify playlist playlistname on denon: Error executing script. Error for call_service at pos 1: Could not find device with name denon
  • homeassistant.exceptions.HomeAssistantError: Could not find device with name denon

any ideas? is it even possible to control the avr via spotcast if it is not already streaming?

but also @ha_user22323

I have multiple accounts in my family membership. I added these accounts to the Spotify for developers app. I logged in with both of them (individually off course) and captured the sp_dc & sp_key id’s. I added them under my default account in the spotcast configuration file.
While selecting the other accounts, I always receive status loading, while at my own card, I get my playlists visible.

Did you manage to solve ?

Kr,

Bart

Anything in your logs? Can you share how you’ve set out the spotcast section of the configuration.yaml file?

HI Chris,

Please find below the config for spotcast:

spotcast:
sp_dc: secret
sp_key: secret
accounts:
joos:
sp_dc: secret
sp_key: secret
jessie:
sp_dc: secret
sp_key: secret

With regards to the logs, I can’t find something specific. This is the config in my for my page using the lovelace card:

    - type: entities
      entities:
          - entity: input_select.spotify_user_selection
            icon: none
            name: ' '
            # style: |-
            #   ha-paper-dropdown-menu {
            #     padding-left: 20%;
            #     padding-right: 2%;
            #     padding-bottom: 3%;
            #     z-index: 1;
            #     margin-top: -4%;
            #   }
          - type: 'custom:state-switch'
            # style: |-
            #   spotify-card {
            #     margin-top: -15%;
            #   }
            entity: input_select.spotify_user_selection
            states:
              Bart:
                type: 'custom:spotify-card'
                display_style: grid
                limit: 8
                device: mediaplayer_keuken
                # known_connect_devices: 
                #  - name: Badkamer
                #   entity_id: media_player.badkamer
                #  - name: Keuken
                #   entity_id: media_player.keuken
                playlist_type: default
                grid_covers_per_row: 4
                account: default
              Joos:
                type: 'custom:spotify-card'
                display_style: grid
                limit: 8
                playlist_type: default
                grid_covers_per_row: 5
                device: mediaplayer_badkamer
                account: joos
                
              Jessie:
                 
                type: 'custom:spotify-card'
                display_style: grid
                limit: 8
                playlist_type: default
                grid_covers_per_row: 5
                device: mediaplayer_badkamer
                account: jessie
  

And please find below extract from the log:

2022-02-06 16:21:19 DEBUG (SyncWorker_43) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:19 DEBUG (SyncWorker_51) [custom_components.spotcast.spotcast_controller] setting up with account joos
2022-02-06 16:21:19 DEBUG (SyncWorker_27) [custom_components.spotcast.spotcast_controller] setting up with account jessie
2022-02-06 16:21:19 DEBUG (SyncWorker_27) [custom_components.spotcast.spotcast_controller] expires: 1644162508 time: 1644160879.9679215
2022-02-06 16:21:19 DEBUG (SyncWorker_43) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160879.9737787
2022-02-06 16:21:19 DEBUG (SyncWorker_51) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160879.9763584
2022-02-06 16:21:20 DEBUG (SyncWorker_43) [custom_components.spotcast.helpers] get_spotify_devices: media_player.spotify_bart_weemaels: Spotify Bart Weemaels: []
2022-02-06 16:21:20 DEBUG (SyncWorker_43) [custom_components.spotcast.helpers] get_spotify_devices: {'devices': []}
2022-02-06 16:21:20 DEBUG (SyncWorker_60) [custom_components.spotcast] websocket_handle_player msg: {'type': 'spotcast/player', 'account': 'default', 'id': 41}
2022-02-06 16:21:20 DEBUG (SyncWorker_60) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:20 DEBUG (SyncWorker_60) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160880.1703537
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast] websocket_handle_castdevices msg: {'type': 'spotcast/castdevices', 'id': 42}
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast.helpers] get_cast_devices: media_player.nest_hub_woonkamer: Nest Hub Woonkamer cast info: ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='host', data=('192.168.2.250', 8009)), ServiceInfo(type='mdns', data='google-nest-hub-8c6876b91f9c77a29d0c9db1a8270784._googlecast._tcp.local.')}, uuid=UUID('8c6876b9-1f9c-77a2-9d0c-9db1a8270784'), model_name='Google Nest Hub', friendly_name='Nest Hub Woonkamer', host='192.168.2.250', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast.helpers] get_cast_devices: media_player.nest_hub_bart: Nest HUB Bart cast info: ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='mdns', data='google-nest-hub-4cfbe9a164e742eae73abe3df776f048._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.2.166', 8009))}, uuid=UUID('4cfbe9a1-64e7-42ea-e73a-be3df776f048'), model_name='Google Nest Hub', friendly_name='Nest HUB Bart', host='192.168.2.166', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast.helpers] get_cast_devices: media_player.chromecast3215: TV Living cast info: ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='mdns', data='Chromecast-dea65b160ea8a6c85da49fd30c1c0346._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.1.106', 8009))}, uuid=UUID('dea65b16-0ea8-a6c8-5da4-9fd30c1c0346'), model_name='Chromecast', friendly_name='TV Living', host='192.168.1.106', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast.helpers] get_cast_devices: media_player.tv_kamer: TV Kamer cast info: ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='host', data=('192.168.1.140', 8009)), ServiceInfo(type='mdns', data='Chromecast-d93ad6be46ad72af93c6ed9d144e495f._googlecast._tcp.local.')}, uuid=UUID('d93ad6be-46ad-72af-93c6-ed9d144e495f'), model_name='Chromecast', friendly_name='TV Kamer', host='192.168.1.140', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast.helpers] get_cast_devices: media_player.nest_hub_jessie: Nest HUB Jessie cast info: ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='mdns', data='google-nest-hub-72278a24163d87bab8e1e4538917b2fb._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.2.81', 8009))}, uuid=UUID('72278a24-163d-87ba-b8e1-e4538917b2fb'), model_name='Google Nest Hub', friendly_name='Nest HUB Jessie', host='192.168.2.81', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)
2022-02-06 16:21:20 DEBUG (MainThread) [custom_components.spotcast] [ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='host', data=('192.168.2.250', 8009)), ServiceInfo(type='mdns', data='google-nest-hub-8c6876b91f9c77a29d0c9db1a8270784._googlecast._tcp.local.')}, uuid=UUID('8c6876b9-1f9c-77a2-9d0c-9db1a8270784'), model_name='Google Nest Hub', friendly_name='Nest Hub Woonkamer', host='192.168.2.250', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None), ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='mdns', data='google-nest-hub-4cfbe9a164e742eae73abe3df776f048._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.2.166', 8009))}, uuid=UUID('4cfbe9a1-64e7-42ea-e73a-be3df776f048'), model_name='Google Nest Hub', friendly_name='Nest HUB Bart', host='192.168.2.166', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None), ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='mdns', data='Chromecast-dea65b160ea8a6c85da49fd30c1c0346._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.1.106', 8009))}, uuid=UUID('dea65b16-0ea8-a6c8-5da4-9fd30c1c0346'), model_name='Chromecast', friendly_name='TV Living', host='192.168.1.106', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None), ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='host', data=('192.168.1.140', 8009)), ServiceInfo(type='mdns', data='Chromecast-d93ad6be46ad72af93c6ed9d144e495f._googlecast._tcp.local.')}, uuid=UUID('d93ad6be-46ad-72af-93c6-ed9d144e495f'), model_name='Chromecast', friendly_name='TV Kamer', host='192.168.1.140', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None), ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='mdns', data='google-nest-hub-72278a24163d87bab8e1e4538917b2fb._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.2.81', 8009))}, uuid=UUID('72278a24-163d-87ba-b8e1-e4538917b2fb'), model_name='Google Nest Hub', friendly_name='Nest HUB Jessie', host='192.168.2.81', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)]
2022-02-06 16:21:20 DEBUG (SyncWorker_7) [custom_components.spotcast] websocket_handle_playlists msg: {'type': 'spotcast/playlists', 'playlist_type': 'default', 'account': 'default', 'limit': 8, 'id': 43}
2022-02-06 16:21:20 DEBUG (SyncWorker_7) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:20 DEBUG (SyncWorker_7) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160880.2950737
2022-02-06 16:21:21 DEBUG (SyncWorker_0) [custom_components.spotcast] websocket_handle_playlists msg: {'type': 'spotcast/playlists', 'playlist_type': 'default', 'account': 'default', 'limit': 8, 'id': 44}
2022-02-06 16:21:21 DEBUG (SyncWorker_0) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:21 DEBUG (SyncWorker_0) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160881.0522892
2022-02-06 16:21:21 DEBUG (SyncWorker_8) [custom_components.spotcast.spotcast_controller] setting up with account joos
2022-02-06 16:21:21 DEBUG (SyncWorker_8) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160881.0534008
2022-02-06 16:21:21 DEBUG (SyncWorker_35) [custom_components.spotcast.spotcast_controller] setting up with account jessie
2022-02-06 16:21:21 DEBUG (SyncWorker_35) [custom_components.spotcast.spotcast_controller] expires: 1644162508 time: 1644160881.055
2022-02-06 16:21:22 DEBUG (SyncWorker_62) [custom_components.spotcast] websocket_handle_playlists msg: {'type': 'spotcast/playlists', 'playlist_type': 'default', 'account': 'default', 'limit': 8, 'id': 47}
2022-02-06 16:21:22 DEBUG (SyncWorker_62) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:22 DEBUG (SyncWorker_62) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160882.4890654
2022-02-06 16:21:22 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] setting up with account joos
2022-02-06 16:21:22 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160882.4903944
2022-02-06 16:21:22 DEBUG (SyncWorker_55) [custom_components.spotcast.spotcast_controller] setting up with account jessie
2022-02-06 16:21:22 DEBUG (SyncWorker_55) [custom_components.spotcast.spotcast_controller] expires: 1644162508 time: 1644160882.491667
2022-02-06 16:21:23 DEBUG (SyncWorker_41) [custom_components.spotcast] websocket_handle_playlists msg: {'type': 'spotcast/playlists', 'playlist_type': 'default', 'account': 'default', 'limit': 8, 'id': 50}
2022-02-06 16:21:23 DEBUG (SyncWorker_41) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:23 DEBUG (SyncWorker_41) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160883.5444667
2022-02-06 16:21:23 DEBUG (SyncWorker_34) [custom_components.spotcast.spotcast_controller] setting up with account joos
2022-02-06 16:21:23 DEBUG (SyncWorker_34) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160883.5454216
2022-02-06 16:21:23 DEBUG (SyncWorker_1) [custom_components.spotcast.spotcast_controller] setting up with account jessie
2022-02-06 16:21:23 DEBUG (SyncWorker_1) [custom_components.spotcast.spotcast_controller] expires: 1644162508 time: 1644160883.5464206
2022-02-06 16:21:24 DEBUG (SyncWorker_12) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:24 DEBUG (SyncWorker_12) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160884.9515214
2022-02-06 16:21:24 DEBUG (SyncWorker_3) [custom_components.spotcast.spotcast_controller] setting up with account joos
2022-02-06 16:21:24 DEBUG (SyncWorker_3) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160884.952355
2022-02-06 16:21:24 DEBUG (SyncWorker_5) [custom_components.spotcast.spotcast_controller] setting up with account jessie
2022-02-06 16:21:24 DEBUG (SyncWorker_5) [custom_components.spotcast.spotcast_controller] expires: 1644162508 time: 1644160884.9531834
2022-02-06 16:21:25 DEBUG (SyncWorker_12) [custom_components.spotcast.helpers] get_spotify_devices: media_player.spotify_bart_weemaels: Spotify Bart Weemaels: []
2022-02-06 16:21:25 DEBUG (SyncWorker_12) [custom_components.spotcast.helpers] get_spotify_devices: {'devices': []}
2022-02-06 16:21:25 DEBUG (SyncWorker_26) [custom_components.spotcast] websocket_handle_player msg: {'type': 'spotcast/player', 'account': 'default', 'id': 57}
2022-02-06 16:21:25 DEBUG (SyncWorker_26) [custom_components.spotcast.spotcast_controller] setting up with account default
2022-02-06 16:21:25 DEBUG (SyncWorker_26) [custom_components.spotcast.spotcast_controller] expires: 1644161738 time: 1644160885.1372406
2022-02-06 16:21:25 DEBUG (MainThread) [custom_components.spotcast] websocket_handle_castdevices msg: {'type': 'spotcast/castdevices', 'id': 58}
2022-02-06 16:21:25 DEBUG (MainThread) [custom_components.spotcast.helpers] get_cast_devices: media_player.nest_hub_woonkamer: Nest Hub Woonkamer cast info: ChromecastInfo(cast_info=CastInfo(services={ServiceInfo(type='host', data=('192.168.2.250', 8009)), ServiceInfo(type='mdns', data='google-nest-hub-8c6876b91f9c77a29d0c9db1a8270784._googlecast._tcp.local.')}, uuid=UUID('8c6876b9-1f9c-77a2-9d0c-9db1a8270784'), model_name='Google Nest Hub', friendly_name='Nest Hub Woonkamer', host='192.168.2.250', port=8009, cast_type='cast', manufacturer='Google Inc.'), is_dynamic_group=None)

Thanks in advance for your help !

Kr,

Bart

Indeed, can’t really see anything that explains why it’s not working.

But can you re-format the configuration.yaml part of your post as code so we can check the indentation is correct? (Other bits of the post show you know how to do this I think,)

1 Like

The other thing you could try is seeing if the playlists load on a stand alone spotcast card without using your state-switch setup, but to be honest, I doubt this is the issue.

Sorry, I’m at the limits of my knowledge here. All I can say is that I have a nearly identical setup to yours, and that it does work for me.

Hi Chris,

Sure, my bad, here is the config of configuration.yaml:

spotcast:
  sp_dc: AQC-wnbfLdWIFiK5SHlsmbTveJ0P- the rest is a secret
  sp_key: 19567498-b1e1-40cb-8141- the rest is a secret
  accounts:
    joos:
     sp_dc: AQCglm4hyLKJj8Q2anW6x0sX- the rest is a secret
     sp_key: 5138dec9-f255-4e28- the rest is a secret
    jessie:
     sp_dc: AQDbMTrjqluscz0aUOiuK - the rest is a secret
     sp_key: a8bc6cb1-ea41-4abe-af29- the rest is a secret

Hope this helps,

Kr,

Bart

Do you also have a spotify premium, using the different family members ? Do you add them in your spotify dev app as single users ?
How did you capture the individual sp_dc & sp_key inputs ? Using chrome & loggin’ in with the different users individually ?

I’ll try to use the accounts each seperate as default, to see if it works

Thanks again for your help !

Kr,

Bart

Not sure if this makes a difference really, but I have 2 spaces indentation before the sp_dc and sp_key keys, like this:

spotcast:
  sp_dc: AQC-wnbfLdWIFiK5SHlsmbTveJ0P- the rest is a secret
  sp_key: 19567498-b1e1-40cb-8141- the rest is a secret
  accounts:
    joos:
      sp_dc: AQCglm4hyLKJj8Q2anW6x0sX- the rest is a secret
      sp_key: 5138dec9-f255-4e28- the rest is a secret
    jessie:
      sp_dc: AQDbMTrjqluscz0aUOiuK - the rest is a secret
      sp_key: a8bc6cb1-ea41-4abe-af29- the rest is a secret

I also recently added a country: key under the main account, but I’m sure that can’t be making a difference, as it was also working before that.

Yes, I do

My memory is hazy about this, but my developer app does currently have 3 users (although I can’t seem to add any more users). The thing is, I originally created separate developer apps for each user, but looking at their dashboards, it seems that these apps aren’t being used at all. There are no statistics appearing - on the other hand, we also use my developer app for our Logitech Media Server music setup, so my developer app is getting used a lot!

Yes, I did exactly as you describe to get these keys.

Really sorry I can’t be of more help than this.

Thanks Chris,

In your integrations, do you only have one entity configured ? Your main account ?

Thx in advance !

Kr,

Bart

No, I have an entity configured for each account in the family, so three in total. Each account has its own media_player controls therefore.

Voila,

AND THAT WAS THE ISSUE :slight_smile: I’m now able to switch between accounts. You’re my hero of the day !
Thanks a lot Chris !

Kr,

Bart

1 Like

Hi all,

Did anyone ever made it possible to list, after succusfully showing grid or playlists, all the tracks of the chosen playlist ?

Thx in advance,

Kr,

Bart

Hey guys,

does anyone also have the problem that the media player goes idle after a while of inactivity and that the select source option dissappeares from the media player card? I am then not able to play music from within Home Assistant. Same issue effects automations and scripts for playing music at a certain time of the day. I hoped that Spotcast might solve that issue, but it didn’t. Is this a general limitation of Spotify?

Can you paste what you have in data?

Thanks :slight_smile:

Trying to workout which part of the link from the Spotify app was the actual playlist, then workout we are listening to the same one. LOL great taste mate!

EDIT

Worked it out,

if you’re using Alexa you cannot use the entity ID and must use the Spotify device ID as per the github doco.

Then enter this into the data section of your call service node

{“spotify_device_id”:“XXXXXXXXXXXXXXXXXXXXX”,“random_song”:“true”,“shuffle”:“true”,“uri”:“spotify:playlist:37i9dQZF1DX0FJ8JYkqiJu”}

Enter nothing for the entity ID

image

I have an issue after just installing this component. I get an error message when I’m trying to use the service with a script (it’s calling a Spotify playlist) when it’s in “standby” (idle?) mode:

"Failed to call service script/01_test. http status: 403, code: -1 https://api.spotify.com/v1/me/player/play?device_id=xxxxxxxxxxxx: Restricted device, reason: None

When I go that adress in the browser I get:

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

Note, my media player is an Echo Dot and I’m using the Spotify Device ID for it. Works great when the Echo is already playing something…

First of all: thank you for building this great addon. It really added something to my home assistant possibilities.

However, I run into one big issue. I want to automate playing Spotify playlists on my Denon speaker with two different accounts. However, if my wife last streamed on this device, my automation doesn’t work and there is no sound. If my account last streamed on the device, the automation does work, so the entity id is correct.

I see the same issue in the Spotify lovelace ui, the Spotify connect devices available only show the ones that I last used. My wife sees the other ones but we are not seeing the same devices.

Is this solvable or a major Spotify issue?

You are not supposed to go to the address, that is an api link, Spotcast is supposed to handle that for you. As for the rest, error 403 (that’s the one that your api call received), means forbidden. In other words, Spotify knows what you mean but doesn’t want to let you do it. Generally, it means you do not have access to the ressource you tried to call. For more details.

To understand what is going on, we would need to know more information, like how you are set up, what version you are running, if basic service calls work. I would suggest you open an issue on the GitHub. With just one tread for your problem, I’ll be a lot simpler to help you.