Support for Multiple Spotify Accounts

First of all, congrats and thank you to @happyleaves for bringing spotify to HA officially.

At the moment, each rooms have one echo dot and each dot is linked to separate spotify account. I am wondering is it possible for this Spotify component to support multiple accounts?

I tried this…

- platform: spotify
  name: Spotify Office
  client_id: !secret spotify_office_client_id
  client_secret: !secret spotify_office_client_secret

- platform: spotify
  name: Spotify Living Room
  client_id: !secret spotify_livingroom_client_id
  client_secret: !secret spotify_livingroom_client_secret

…but failed.

Right now it supports only one account. It writes credentials to a file, and that filename isn’t based on the entity id - it’s always the same. There could be other issues as well, but I only have 1 spotify account to test with.

oh ok. In that case, I am moving this to Feature Requests category. Hope it can support multiple Spotify accounts in the future. Thanks.

1 Like

I would love to have support for 2 spotify accounts.
We have 1 spotify connect speaker and if my fiancee uses it in the evening, it does not work for my account connected to HA.
I wnated to write automation that pipes through the account currently on the speaker

1 Like

So is there something new about this? Maybe if i use a special spotify playlist player, where i can choose the spotify account, the playlist and where to play.
Or every account gets a custom tab :thinking:

I’ll have a swing at this.

After checking the code I found the config value “cache_path”, setting that to a unique value (per account) should make this work as you described.

I have only 1 spotify account so I cannot test this, would be great if you could test it @masterkenobi.

- platform: spotify
  name: Spotify Office
  client_id: !secret spotify_office_client_id
  client_secret: !secret spotify_office_client_secret
  cache_path: '.spotify_office'

- platform: spotify
  name: Spotify Living Room
  client_id: !secret spotify_livingroom_client_id
  client_secret: !secret spotify_livingroom_client_secret
  cache_path: '.spotify_livingroom'
4 Likes

just configured by specifying cache_path, this works. i have two spotify media players now. The second one can’t see any sources, might be due to the fact that i havent use/link it on any devices yet.

1 Like

Gr8 Investigate if everything works for you, if not tell me the problems here and I’ll try to fix it. Will do a pull request for documentation to add some info about this

Tested it on a web player and I was able to control it within HA.

was this feature ever added into a pull request?

This discussion really helped me out, thanks guys! In case anyone else has run into trouble, a couple of things to bear in mind:

  • Using absolute path on for the cache_path was important for me
  • You must absolutely name your spotify platform config entries. Until I did this, it refused to work.

Thanks again!

1 Like

It has always been there, but its not that clear on how to set it up in the docs imo.

Hi there,
I was trying to add a second account to my working HA Spotify control, but could not get it working.
Allthough two separate cache files are created and two Spotify media player show up in HA, both are somehow controlling the same account, the one that already existed.

My code looks as following:

- platform: spotify
  name: 'Spotify 1'
  client_id: <client_id_1>
  client_secret: <client_secret_1>
  cache_path: '.cache1'
- platform: spotify #older and already working account
  name: 'Spotify 2'
  client_id: <client_id_2>
  client_secret: <client_secret_2>
  cache_path: '.cache2'

Honestly, I don’t get what @chimpy meant with “Using absolute path for the cache_path …”.
Maybe this is the problem.
Hope you guys can help me getting this to work!
Thanks

My working config looks similar to yours, have you deleted the old cache files? I was having the same issue before I removed the existing files

Relative path is the the path relative to you. Absolute path is the path beginning from “/”.

Go to the directory containing “.cache1”. Do a pwd command. Add “.cache1” to the result of that command. Put it in the config.

Today had the chance to test again and it looks like the hint from @dkramer74 did the job. Alltough I already deleted the cache a few times. After deleting the cache, I was not able to directly get it to work, so I waited a while and tested again later, suddenly it worked. Here is what I did:

  1. Delete all cache files
  2. Restart Home Assistant
  3. Konfigure the first spotify account from outside my home (the second account could not be konfigured)
  4. Konfigure the second spotify account from home a few hours later (suddenly the account could be configured)

No clue why and how long it will work. Maybe it was the different location/IP during the configuration.
Anyhow thanks for your suggestions.

It’s not necessary to have 2 client_id's and client_secret's

My config looks like this, and works:

- platform: spotify
  name: 'Spotify 1'
  client_id: <client_id_1>
  client_secret: <client_secret_1>
  cache_path: '.cache1'
- platform: spotify #older and already working account
  name: 'Spotify 2'
  client_id: <client_id_1>
  client_secret: <client_secret_1>
  cache_path: '.cache2'

I found this thread very helpful thanks everyone.

For what it’s worth; however, absolute paths were part of my trouble; I had to switch back to relative paths. YMMV I suppose, but something to try if it still isn’t working for you.

This looks to be exactly what I’m looking for but not sure if the code snip should be placed under the spotify: integration directly or under sensor: integration (since it uses the - platform: spotify).

Only used Home Assistant since 0.105 and I understand syntax might have changed. I now run 0.108.2 so would need full syntax for the configuration.yaml.

Many thanks for your contribution!