Spotify ignoring source

OK.
Well, did this is a long time ago but let me give it a try…

I believe in your configuration.yaml you have something like;

media_player:
  - platform: spotify
    client_id: !secret spoclient_id
    client_secret: !secret spoclient_secret
    aliases:
        2817660cxxxxxxxxxxxxxxxxxxxxxxx8648e207: 'Kitchen'
        f610e96fxxxxxxxxxxxxxxxxxxxxxxxxx034be7ff0: 'Gymmet'
        93fed0041a0xxxxxxxxxxx9c1b39cc60b: 'Pappas Sovrum'

if that’s true, you should remove the word aliases since that’s what I think is wrong. Then restart the machine and it should work…?

I use Hassbian, I guess you’re on something else, hass.io perhaps? Depending on what you run the logs might be in different locations.

Good Luck!

Sorry to dig this thread up. But has anyone been able to get away around this?

I would love to have this working on my HA

so I was digging around HA to understand why my HA wont retain the devices used by spotify and I stumbled on the following link

it seems spotify it’self isn’t retaining the list of devices not HA

when i play anything it appears in on the website, after a while it disappears

This is also the argument I meet back when I raised the issue (making it a non-issue) - however I don’t see this behavior on my iPhone or MacBook spotify apps. Once in a while maybe, but not as much - maybe they do something to discover the devices more aggressively or something like that.

I just think it odd that it works for some and not for others, I even tried signing up to a new account to see if that resolved my issue,

I’d love to have this hooked up to my HA

I am far from proficient with all of this, but I had an idea that I thought may be worth sharing. When I try to cast to google devices via Spotify on my desktop, I cannot see any of the google devices. I can only see the desktop I am on and a Firestick. The issue is referenced here (https://community.spotify.com/t5/Desktop-Windows/Spotify-Connect-amp-Google-Home/td-p/4642461) and I can confirm that I see all of my devices on my phone, but not from my desktop.

Maybe the limitation is with the Spotify API or the way that Home Assistant is using it, because it functions very similarly to the way that using Spotify on my desktop does. If I start playing music on a google home (via voice command or casting from my phone), I can see the google home on my desktop Spotify client in the devices menu but the moment I switch it to my desktop via the devices menu on my desktop the google home disappears. This is the exact same way that sources show up on my HA front-end and it behaves the same if I switch devices from the HA front-end.

Again, I have no idea how to begin remedying this, but I figured I would throw it out there in case someone who has the knowledge wants to take it and run with it at some point. Maybe there is a way to utilize the iOS or Android API to see google devices with more reliability.

Cheers

The problem is indeed with Spotify API. There’s a few issues on Spotify open. I have been researching a bit. Google Assistant can actually start the cast too. Hence, I was thinking of a workaround to make a request to Google Assistant to start the cast, then take over the control in Home-Assistant. In that sense, I wonder whether the Google Assistant SDK Add-on could make it work. Does anyone has it installed to check whether it’s possible to make REST/HTTP calls or use it in scripts?

1 Like

I think I could indeed dig up ids using Spotify Rest API as per the link shared by phairplay.
But how do you use spotify in automation? I tried to use spotify.play_playlist service as described on https://www.home-assistant.io/integrations/spotify/, but it reports no activ device found (I can play on one and Rest API reported it back!)

Sure. This is really ugly, but I haven’t looked at it for a couple of years and it works. I had some strange issues with lists starting with the same song and volume so there’s quite a lot of room for improvement. Again, it does what I want it to do…

- alias: Köksmusik på på
  trigger:
    platform: state
    entity_id: binary_sensor.koksogat_sensor
    to: 'on'
    for:
      minutes: 2
  condition:
  - condition: time
    before: '22:00:00'
    after: '18:00:00'
  - condition: template
    value_template: "{{ not is_state('media_player.spotify', 'playing') }}"
  - condition: template
    value_template: "{{ not is_state('media_player.appletvardagsrum', 'playing') }}"
  - condition: template
    value_template: "{{ not is_state('media_player.appletvardagsrum', 'paused') }}"
  action:
  - service: media_player.select_source
    data:
      entity_id: media_player.spotify
      source: "Kitchen"
  - service: media_player.volume_set
    data:
      entity_id: media_player.spotify
      volume_level: 0.0
  - service: media_player.shuffle_set
    data:
      entity_id: media_player.spotify
      shuffle: true
  - service: media_player.play_media
    data:
      entity_id: media_player.spotify
      media_content_type: playlist
      media_content_id: spotify:user:XXXXX:playlist:XXXXXX
  - service: media_player.shuffle_set
    data:
      entity_id: media_player.spotify
      shuffle: true
  - service: media_player.media_next_track
    data:
      entity_id: media_player.spotify
  - service: media_player.volume_set
    data:
      entity_id: media_player.spotify
      volume_level: 0.45

- alias: Köksmusik på lugnt
  trigger:
    platform: state
    entity_id: binary_sensor.koksogat_sensor
    to: 'on'
    for:
      minutes: 2
  condition:
  - condition: time
    before: '18:00:00'
    after: '05:30:00'
  - condition: template
    value_template: "{{ not is_state('media_player.spotify', 'playing') }}"
  - condition: template
    value_template: "{{ not is_state('media_player.appletvardagsrum', 'playing') }}"
  - condition: template
    value_template: "{{ not is_state('media_player.appletvardagsrum', 'paused') }}"
  action:
  - service: media_player.select_source
    data:
      entity_id: media_player.spotify
      source: "Kitchen"
  - service: media_player.volume_set
    data:
      entity_id: media_player.spotify
      volume_level: 0.0
  - service: media_player.shuffle_set
    data:
      entity_id: media_player.spotify
      shuffle: true
  - service: media_player.play_media
    data:
      entity_id: media_player.spotify
      media_content_type: playlist
      media_content_id: spotify:user:spotify:playlist:XXXXX
  - service: media_player.shuffle_set
    data:
      entity_id: media_player.spotify
      shuffle: true
  - service: media_player.media_next_track
    data:
      entity_id: media_player.spotify
  - service: media_player.volume_set
    data:
      entity_id: media_player.spotify
      volume_level: 0.22

- alias: Köksmusik av
  trigger:
  - platform: state
    entity_id: binary_sensor.koksogat_sensor
    to: 'off'
    for:
      minutes: 5
  - platform: state
    entity_id: media_player.appletvardagsrum
    to: 'playing'
  - platform: state
    entity_id: media_player.appletvardagsrum
    to: 'paused'
  action:
  - service: media_player.volume_down
    data:
      entity_id: media_player.spotify
  - delay: '00:00:1'
  - service: media_player.volume_down
    data:
      entity_id: media_player.spotify
  - delay: '00:00:1'
  - service: media_player.volume_down
    data:
      entity_id: media_player.spotify
  - delay: '00:00:1'
  - service: media_player.volume_down
    data:
      entity_id: media_player.spotify
  - delay: '00:00:1'
  - service: media_player.media_pause
    data:
      entity_id: media_player.spotify
  - delay: '00:00:1'
  - service: media_player.volume_set
    data:
      entity_id: media_player.spotify
      volume_level: 0.22
1 Like

@frenck, can you please take a look at this?

There is not much to look at. The current integration in 0.105 shows all sources provided by the Spotify API. There is no filtering on our end for that.

Thanks for the reply!!

Yeah, we’ve settled that this is a Spotify API problem…
But @peglegreg is right… mobile apps have a different way of fetching the available sources on the local network, since they all show as available most of the time. Isn’t there any way for the HA integration to make a scan the same way the mobile apps do instead of fetching the sources from the API?

What you see additionally on your mobile, are the Chromecast devices.

In theory, it should be possible. But that is not made/created easily.

Yes, but not only…
For instance, my Samsung TV, my PS4… they show up in my android app but not on the desktop app, which also gets the source list from the API.
There’s only one source available at all times and that’s my Yamaha receiver. I wonder why…? :thinking:

Why are the Chromecast devices listed in the Spotify Lovelace Card, while they are not available in the official Spotify API, and thus not in the sources of the media_player in HA? Anyone knows?

1 Like

I had the same problem but thanks to reading about Spotify Lovelace Card, I found the following solution. Works perfect for me!

1 Like

My wife’s Spotify account also doesn’t list any device. I can stream to Chromecast devices now through Spotcast, but I have other devices I want to start playback on (HEOS in my case). None of these are in the source_list of the media_player entity of the Spotify integration of my wife, until I start the playback myself manually through the Spotify app on her phone. Then the source_list is populated as it should be.
Also checked the api of Spotify and got this returned:

{
  "devices": []
}

The web player of Spotify also returns no other speakers at all :frowning:

Guess there is no way to resolve this issue for now?

Do not think so. Yesterday i went with This topic

Was working perfectly for 24 hours. The system was idle for over 2 hours and now i cannot even get i working again.

Hello guys, my speakers are only listed, if I used them directly from the Spotify App. How can I fix the devices in HA? Can I setup the “Sources” ??

My Config:

configuration.yaml

spotify:
  client_id: xxxxxxxxxxxxx
  client_secret: xxxxxxxxxxxxxx

HA 0.117.6

Background: If I turn on my speaker, I can’t use it. e.g. TAG reader

This has been an issue for years and it is unfortunately a limitation in the Spotify integration/API.
The good news is that depending on what speakers you have there might be ways to work around it.
If your speakers are Cast compatible (might also work with Spotify Connect) I highly recommend the spotcast custom component mentioned a few posts above.