Core: New Spotify Integration can't handle multiple account config

Created on 9 Feb 2020  Â·  11Comments  Â·  Source: home-assistant/core

The problem


I have five Spotify accounts, all worked fine to integrate at the same time in the old integration.
After upgrading to 105.2, I changed the config and the Spotify Apps to the new syntax, and it works fine - but only for one account at a time.

The config won't allow several accounts specified at the same time. Or, I am doing it wrong and then I'd like to suggest an update of the documentation to make it easier to follow for multiple account config.

Environment

  • Home Assistant release with the issue: 105.2
  • Last working Home Assistant release (if known): 104.3
  • Operating environment (Hass.io/Docker/Windows/etc.): hass.io /Home Assistant
  • Integration causing this issue: Spotify
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/spotify/

Problem-relevant configuration.yaml


Old config that worked fine:

  - platform: spotify
    name: account_1
    client_id: !secret spotify_client_id_account_1
    client_secret: !secret spotify_client_secret_account_1
    cache_path: .spotify-token-cache-account_1

  - platform: spotify
    name: account_2
    client_id: !secret spotify_client_id_account_2
    client_secret: !secret spotify_client_secret_account_2
    cache_path: .spotify-token-cache-account_2

  - platform: spotify
    name: account_3
    client_id: !secret spotify_client_id_account_3
    client_secret: !secret spotify_client_secret_account_3
    cache_path: .spotify-token-cache-account_3

  - platform: spotify
    name: account_4
    client_id: !secret spotify_client_id_account_4
    client_secret: !secret spotify_client_secret_account_4
    cache_path: .spotify-token-cache-account_4

  - platform: spotify
    name: account_5
    client_id: !secret spotify_client_id_account_5
    client_secret: !secret spotify_client_secret_account_5
    cache_path: .spotify-token-cache-account_5

New config that works (only one account):

spotify:
  client_id: !secret spotify_client_id_account_1
  client_secret: !secret spotify_client_secret_account_1

But it won't accept more accounts.

Expected config would be something like this:

spotify:
- client_id: !secret spotify_client_id_account_1
  client_secret: !secret spotify_client_secret_account_1

- client_id: !secret spotify_client_id_account_2
  client_secret: !secret spotify_client_secret_account_2

...

Traceback/Error logs


Additional information

spotify

All 11 comments

Use the integration screen instead of yaml it should work by just creating new entries there.

Well, yes. But only for the "active" account, specified in configuration.yaml. I don't get any option to input next account's credentials or to choose which account to activate the integration for.

If I "edit client & client_secret to ..account_1" in configuration.yaml + restart + add the integration it works fine.

Then I can "edit client & client_secret to ..account_2" in configuration.yaml + restart + add the integration, then I get the second account's integration. And so on. But in a few minutes, the accounts not specified in the loaded configuration.yaml will time out and leave behind dead integrations.

Probably I'm just doing it wrong:
Can you show an example of a configuration.yaml that supports several Spotify accounts to be integrated?

You just create another integration, remove the yaml completely and keep adding new ones from configuration > integration. One for each account.

Hey there @frenck, mind taking a look at this issue as its been labeled with a integration (spotify) you are listed as a codeowner for? Thanks!

Ok, that sounds fine, but it doesn't work for me. The integration just add the already existing integration again. And if I press + again, It'll try to add the same account again.

When I had one integration active and working, I removed the yaml, restarted and tried to add a new integration - and then it says:
image

I'll remove the one that works and start over completely.

New try, new server, no success:

Clean install, hass.io on Pi 3+

1. Following the documentation:
o create the required Spotify application:
• Login to Spotify Developer.
• Visit the My Applications page.
• Select Create An App. Enter any name and description.
• Once your application is created, view it and copy your Client ID and Client Secret, which are used in the Home Assistant configuration file.
• Add a Redirect URI in one of the following forms:
o If you are not using SSL: http:///auth/external/callback
• Click Save after adding the URI.

2. Add config
To add Spotify to your installation, add the following to your configuration.yaml file:

Example configuration.yaml entry

spotify:
client_id: YOUR_CLIENT_ID
client_secret: YOUR_CLIENT_SECRET

3. Restart HA
4. Got a new integration discovered after restart
image
5. Choose configure.
image

image

6. Back to HA
image

7. Add next account
image
image

image

8. Integration added - for the same account as above. No possibility to choose another account.
image

(User name blanked out).

I am still sure I do something wrong, but please describe where I do wrong so I can update the documentation.

Found out why - something with the information being cached.
If I do this - it works.

  1. Basic setup from the documentation - setup the first account with integration
  2. Close the browser
  3. Prepare all other accounts with apps in Spotify (from the docs)
  4. Important - Open a new browser in Incognito mode
  5. Add a new Integration (+), choose Spotify
  6. Log in the user want to add
  7. Integration created.
  8. Close the browser.
    Repeat 4-8 for each account.

@BoneheadFraggle Sorry to post this again after it has been closed.

I have managed to get 3 accounts to be available for integration following your instructions above.

However, after sometime, the first two accounts will present themselves as "unavailable" after some time. Only the last account whose client id that remains on configuration.yaml will remain available.

Have you come across the same problem or have found a resolution to the above problem?

However, after sometime, the first two accounts will present themselves as "unavailable" after some time. Only the last account whose client id that remains on configuration.yaml will remain available.

You should not add multiple entries to your configuration.yaml file. Only 1 entry (Spotify Application) goes into your configuration.yaml. You only need 1 application, which can be used for adding multiple accounts / instances via the Home Assistant frontend.

Adding in multiple to your configuration.yaml, will cause your accounts to expire.

Just follow my steps and it should work.

  • Only add one account in configuration.yaml - step 1 / the docs.
  • For the other accounts, only add integrations (never change configuration.yaml).
  • I had to use Incognito mode in my browser AND close the browser between every new integration.

Thanks @BoneheadFraggle and @frenck.

As you both pointed out, the correct way is to only add one client id and client secret once, and there no need to amend the configuration.yaml any more.

Instead of using incognito mode, I went to https://accounts.spotify.com and logged out after adding each intergration.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flsabourin picture flsabourin  Â·  3Comments

ofuangka picture ofuangka  Â·  3Comments

piitaya picture piitaya  Â·  3Comments

missedtheapex picture missedtheapex  Â·  3Comments

arangates picture arangates  Â·  3Comments