#Different music simultaneously

1 messages · Page 1 of 1 (latest)

wet socket
#

Is it possible to set up an automation where I can have one song/playlist playing on one bedroom speaker and another song/playlist on a different bedroom speaker at the same time?

Currently using google speakers, I have music assistant set up and connected to my spotify account.

Even outside of automations is it possible to have different music playing simultaneously on different speakers?

high moat
#

Yes, you just assign music to a media player. From HA, you can just call media_player.play_media twice, once for every device with the corresponding media

frosty totem
#

Yes and No ... For the SpotifyPlus (and HA Spotify) integration, you have to have separate accounts to play different content on different devices at the same time. To put it another way, you cannot play different tracks using the same Spotify account on different devices at the same time. Note that this is a Spotify Web API limitation, in that it simply controls the player and does not stream the content.

Consider the following SpotifyPlus examples ...

Example for your Spotify account:

service: spotifyplus.player_media_play_context
data:
  entity_id: media_player.spotifyplus_johns_account
  context_uri: spotify:playlist:6M8n0Sp9895BXEE0MbGPde
  device_id: "Nest Bedroom 01"

Example for the other Spotify account:

service: spotifyplus.player_media_play_context
data:
  entity_id: media_player.spotifyplus_jills_account
  context_uri: spotify:show:3IM0lmZxpFAY7CwMuv9H4g
  device_id: "Nest Bedroom 2"
frosty totem
#

The SpotifyPlus Integration is a drop-in replacement for the HA Spotify integration; it can do everything that the HA Spotify integration can do, supports Spotify Connect enabled devices (Bose, Sonos, Chromecast, Amazon Alexa, Denon, JBL, and more), and provides 95+ custom services that can be used in HA automations and scripts.

There is also a SpotifyPlus Card user-interface that allows you to control the player, manage your Spotify favorites, as well as search the Spotify catalog. You have to install the SpotifyPlus integration first though, and get it configured before you can use the SpotifyPlus Card.

Both are easily installed via HACS. I am the author of both.

Hope it helps!

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

GitHub

Home Assistant UI card that supports features unique to the SpotifyPlus custom integration. - thlucas1/spotifyplus_card

wet socket
#

this will allow being able to play from different spotify accounts?
I have spotify family for everyone to have their own account, but also have the general house account that is what plays when you use the voice command via google to play music.
Would love to be able to have the bedtime automation set up so each kid can have their own bedtime playlist set up and playing.

frosty totem
#

Yes, it will handle multiple accounts. You just have to setup a Spotify Developer App for each account using the Pre-Installation Requirements. Since you are using Google ChromeCast devices, you will also need to perform the Extra Steps for Google Chromecast Users. This allows you to awaken Google Cast devices from standby mode (SpotCast is not required).

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

wet socket
#

is there a way to make things not go into standby mode?
I don't know jack about python script. I am struggling with figuring out the yamal for HA...

frosty totem
#

Sorry, but no. that's the way the Google Cast devices work.

#

It's pretty easy if you follow the wiki instructions, even if you don't have python installed. The python script you have to run is a one-time setup, unless you change your Spotify password.

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

wet socket
#

is there a video i can watch to follow this step by step?

wet socket
#

@frosty totem
I get to the Token Creation Instructions and I don't know where I am doing something wrong. I think I may be inputting my ID in the wrong spot... But when I get to step 7 and try to execute the command, there is something that quickly flash on my screen,the cmd box closes out but nothing else happens.

frosty totem
#

Are you using Windows OS? or Mac OS?
Execute the python script from the open command window that has the Python Virtual Environment activated (see Steps 1 and 5 of the Python Environment Setup Instructions).

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

wet socket
#

Windows. I finally got it figured out I hope.
Now trying to figure out step 9.

#

If I need to add another Spotify account later on will I have to do step 9 again?

wet socket
#

ok. I think I have worked through it...now how do I know if it worked and will play from the different spotify accounts?

frosty totem
#

Step 8 of the Token Creation Instructions - If you have other Spotify accounts to add, then repeat steps 2-7 for each Spotify Login ID that will be used with SpotifyPlus. The Token Cache file will contain the access tokens for ALL Spotify accounts that are to be used with SpotifyPlus once you have completed the steps for all accounts.

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

#

To test each account, simply execute a player_media_play_context service call (via HA HA Developer Tools \ Actions using YAML mode) to each of your SpotifyPlus media_player.spotifyplus_xxxxx account entries. Example - change the entity_id to your SpotifyPlus integration media player; change the device_id to one of your Google Cast devices, using the name that you defined in your Google Home App.

service: spotifyplus.player_media_play_context
data:
  entity_id: media_player.spotifyplus_account_1
  context_uri: spotify:playlist:6M8n0Sp9895BXEE0MbGPde
  device_id: "Nest Audio 01"

Repeat the above for each of your SpotifyPlus integration media player entities.

#

Forgot to mention - It should successfully start playing the context on the given device name. for each account If play does not start, then something is not setup correctly.

wet socket
#

i will check when I get back home.

#

I stumbled across something during all this and I didn't save the page, I feel like you have another project within this you are working on that would allow voice control and that it would play from the spotify account that is linked to the individual speaker when asked?
Example: kid1 has speaker in bedroom and requests google to play a song. kid 2 who has a speaker in bedroom also asks google to play a different song. both kids have their own spotify accounts.

frosty totem
wet socket
#

ok...so "Spotify Desktop Player authorization token was not found in the token cache file."
so none of the accounts were found

wet socket
#

I don't know where to save the json file. I don't see the /config/.storage/
when I try to create a storage folder it says that it already exisits but I don't see it anywhere

frosty totem
#

The period prefix of .storage location marks the directory as hidden, which is why you don't see it. If you are using the HA File Editor AddOn, you have to remove .storage in the configuration options of the addon >>> ignore pattern. It hides the .storage location by default. Check out this howto article on how to configure the HA File Editor addon to display .storage location.

If you are not using the HA File Editor addon, then what are you using to browse the config directory? If using a SMB share, then ensure you have Show Hidden Files and Folders option turned on.

I use both methods; HA File Editor addon if I want to do a quick edit of something; SMB (Samba Share) if I want to drag and drop files into the HA config area.

By default the .storage folder is hidden in the File Editor, but it can be revealed thats it! your .storage will now show up in your file editor! (but be carefull!)…

#

The spotifyplus_tokens.json file created by the Token Creation Instructions process should be copied to the HA /config/.storage/spotifyplus_tokens.json location. You can create the file in that folder using HA File Editor (filename is CaSe-SeNsItIVe) and then copy / paste the contents of the tokengen/spotifyplus_tokens.json into it if you like.

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

wet socket
#

I have file editor and i am trying to figure out SAMBA and how to drag and drop.

frosty totem
wet socket
#

I GOT IT!

#

THANK YOU!

frosty totem
#

No problem; You're welcome.
To verify, is your SpotifyPlus playing content on your Cast device now?

wet socket
#

Yes!

#

Sorry! I am super excited!

  1. I am very slowly learning all this stuff with HA and automations so it is always exciting when I get something working!
  2. This finally lets me be able to set up a separate bedtime/wake up routine for all 3 of my kids with their own music and not interrupt the other kids and that is super exciting!
frosty totem
#

Very cool - glad to hear it's working!
Just wanted to let you know that there is also a SpotifyPlus Card user-interface that allows you to control the player, manage your Spotify favorites, as well as search the Spotify catalog. In case you want a media player UI to go along with it.
Hope it helps!

GitHub

Home Assistant UI card that supports features unique to the SpotifyPlus custom integration. - thlucas1/spotifyplus_card

#

Sorry - I just realized that I already mentioned the SpotifyPlus Card in the original reply.

wet socket
#

@frosty totem
Hey just wanting to make sure I am understanding something correctly.

Do I need to create the turn on/off script?

My google speakers have static IP addresses, but when Spotify is played on say a cell phone, if I try to play using an automation I keep getting an error that the device doesn't exist or the music starts play on a cell phone, or whatever was last playing Spotify.

wet socket
#

or is it the "Player Transfer Playback?

either way how do I fix it? I don't know how to do any of the YAML stuff.

If I go in file editor I can find the "Player Transfer Playback" but I don't know if I am supposed to be putting the devices in that or somewhere else...

frosty totem
#

You should not need to use the Turn On / Turn Off script; those are useful for powering up receivers and switching inputs prior to playback.

The SpotifyPlus can only transfer playback to the official Spotify players (Mobile, Web, Desktop) if they are currently up and running. The integration cannot start the Spotify App on those types of devices (phone, browser, computer). Your Google Cast devices are different, in that they have the Google Cast protocol running all of the time; the SpotifyPlus Integration can launch the Spotify app on those devices, then transfer playback to them.

You can use the player_transfer_playback service to transfer playback to the device, or you can use the player_media_play_context \ player_media_play_tracks services to start play directly to the device of choice. Remember, if it's a phone then the Spotify App must be started prior to the service call.

You can test the following examples via the HA Developer Tools \ Actions tool (using Go To YAML Mode) ...

The following assumes that Spotify is up and running on the iPhone:

service: spotifyplus.player_transfer_playback
data:
  entity_id: media_player.spotifyplus_todd_l
  device_id: "Todds iPhone"

The following will activate the Google Nest Audio device:

service: spotifyplus.player_transfer_playback
data:
  entity_id: media_player.spotifyplus_todd_l
  device_id: "Nest Audio 01"
GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

#

Or you can use the SpotifyPlus Card \ Devices section to simply click on the device of choice to transfer playback. You may need to refresh the contents after you start the Spotify App on your phone, as it requires a manual refresh of the device list in order to detect that a new player was active.

wet socket
#

So how do I create an automation that at 9pm will start playing the chosen bedtime play list in each child's room on their google mini speaker from their individual spotify account if they have been listening to spotify on their phone or computer during the day?

#

I don't know how to do the YAML stuff. I am trying to learn it but every video I watch is not relatable so I don't understand. I create the automations by making scripts and using the drop boxes and options that are already available.

#

The tokens also keep disappearing from the file as well.

frosty totem
#

The automation YAML stuff is just another way of looking at the drop boxes / ui options (also called UI mode).
For example, take the automation in the screenshot ...
To toggle between UI Mode (default, screen capture 1) to YAML mode (screen capture 2), just click on the 3 horizontal dots icon in the upper right window and click on "Edit in YAML".
That will switch the editor directly to YAML mode (screen capture 2).
YAML mode is the way to edit automations (and scripts) if you have a complete example of a script that you want to get entered quickly. Rather than configuring each individual details using the UI options and drop boxes, you simply paste the YAML into the YAML mode editor and its ready to go. You can then switch back to UI Mode, and the UI options and drop boxes are automatically populated from the YAML.
To toggle between YAML Mode (screen capture 2) to UI Mode (screen capture 1), just click on the 3 horizontal dots icon in the upper right window and click on "Edit in Visual Editor".

frosty totem
#

As an exercise, try this ...

  1. create a new automation via Settings \ Automations, click on Create Automation button (start with new empty automation).
  2. switch to YAML mode editor by clicking the 3 dots icon in the upper right and click on Edit in YAML option.
  3. copy and paste the following script into the YAML editor (overlay any existing YAML text in the editor):
alias: SpotifyPlus Example - Play Spotify Playlist at 9pm for Jack
triggers:
  - trigger: time
    at: "21:00:00"
conditions: []
actions:
  - alias: Play Spotify Playlist on Jacks Speaker
    action: spotifyplus.player_media_play_context
    data:
      entity_id: media_player.spotifyplus_jack
      context_uri: spotify:playlist:0oWPZ1QRa9CLdfY2QYfdoR
      device_id: Jacks Speaker
      shuffle: true
  - action: spotifyplus.player_set_volume_level
    data:
      entity_id: media_player.spotifyplus_jack
      volume_level: 25
  - action: spotifyplus.player_set_shuffle_mode
    data:
      state: true
      entity_id: media_player.spotifyplus_jack
mode: single
  1. switch from YAML Mode to Visual Editor Mode (aka UI Mode) by clicking on the 3 dots icon in the upper right and click on Edit in Visual Editor option.
    See the difference? It populated all of the drop downs and UI options from the YAML text.
  2. Edit each of the actions to change the media_player.spotifyplus_jack entity to the correct SpotifyPlus entity media player for your first child.
  3. Edit the Jacks Speaker device id to the device name in the first child's bedroom.
  4. Click the Save button to save the automation.
    That automation will trigger at 9 pm every night. You can add other conditions to fine-tune the trigger, but it give you the idea how it works.
wet socket
#

Ok. I did that, and changed the entity and device IDs.

I get this error: "Error: Spotify Cast Application could not be activated on Chromecast device "5affdf4e87dda1a0243ce598e21c183f": Spotify Desktop Player authorization token was not found in the token cache file."

#

I can get it to work for a little bit but if at any point someone listens to spotify on their phone or computer instead of from their google speaker then I can not get it to play again.
The token disappears from the file and I have to re-upload the file to file editor everytime.
A few times I have had to go and do the whole "Spotify Desktop Player Authentication Configuration" again for each account.

wet socket
#

Or I get "refresh token revoked"

frosty totem
#

The refresh token revoked error indicates there is a problem with the token that you are trying to use for an account. When you see that error message, the token is automatically deleted from the spotifyplus_tokens.json file - any attempt to use it again will cause the Spotify Desktop Player authorization token was not found in the token cache file error.

Let's try to simplify the problem by just using 1 account (for now). Pick a single account, and do the following for only that account:

  1. verify Spotify Developer App has been created for the account. Each Spotify account will require its own Spotify Developer App client id and secret.
  2. verify Home Assistant Application Credentials are created for the Spotify Developer App that is associated with the selected Spotify account. Each Spotify account will require its own HA Application Credentials.
  3. verify SpotifyPlus Service instance for the selected Spotify account matches the Application Credentials created for it. Each Spotify account will require its own SpotifyPlus Service instance.
  4. execute the SpotifyPlus Token Creation Instructions creating the spotifyplus_tokens.json file.
GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

#

Try playing something to a SINGLE cast device (do not use a group device at this point). If it works with the single device, try transferring playback to their phone or computer; then transfer playback to the Google device via HA.
IF all of that works, then we can proceed to adding the next account.

Ultimately, I think the issue is that you are creating multiple accounts, but are not associating the correct HA Application Credentials to the correct SpotifyPlus service instance(s). Or you are using a cached Spotify login when creating the HA Application Credentials, which authenticates the cached login user to another user account. You have to ensure that you switch to the specific account that you are authorizing. I added the following verbiage to Step 4B instructions:

Prior to selecting the Application Credential, open a new default browser window to Spotify Web and log out of Spotify. The log out option can be found by clicking on your profile icon in the upper-right, and selecting Log Out. This will log the current user out of Spotify, and will force a re-login to occur when you select the Application Credential in the next step. This will ensure that you are prompted for the correct Spotify Credentials, and that the access token is generated for the correct Spotify user account (very important when adding multiple Spotify accounts).

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

wet socket
#

what do you mean "transferring playback to their phone or computer?"

So I play music on their google speaker, and then try playing it on their phone and then try playing it again on their google speaker from the instance and not casting it from the phone?

wet socket
#

So I started over. Removed and then reinstalled everything.
So far it seems to be working. I am off work today so planning on playing around more.

I did notice on my computer that with the spotifyplus card on my dash while I can toggle between the options I can not actually select anything. So I can toggle to the playlist I want but if I click on it it will not start playing. But if I am accessing my HA from my phone I can select the options without a problem.

wet socket
#

So yeah, everything was working. Was successfully switching from being able to play on one device(phone, watch, computer) and then switching back to the google cast device and then suddenly I get the token revoked issue

frosty totem
#

What I meant was whatever you meant by this statement:
"I can get it to work for a little bit but if at any point someone listens to spotify on their phone or computer instead of from their google speaker then I can not get it to play again."

When you say this:
"So yeah, everything was working. Was successfully switching from being able to play on one device(phone, watch, computer) and then switching back to the google cast device and then suddenly I get the token revoked issue"
Was this just for 1 account? Or did you re-configure ALL of you accounts again?

What I was trying to do with the latest suggestion was to remove other accounts from the problem, and ensure that it is working with ONE account. The refresh token revoked error indicates there is a problem with the token that you are trying to use for an account. When you see that error message, the token is automatically deleted from the spotifyplus_tokens.json file - any attempt to use it again will cause the Spotify Desktop Player authorization token was not found in the token cache file error.

My suggestion would be to remove ALL SpotifyPlus services AND their related Application Credentials. Then follow the SpotifyPlus Integration Install steps to install for just ONE account.

I still think it's an issue with mixing up the authentication tokens between users that is causing the problem.

GitHub

Home Assistant integration for Spotify Player control, services, and soundtouchplus integration support. - thlucas1/homeassistantcomponent_spotifyplus

wet socket
#

I removed all the services and App creds.
I reinstalled one account first and made sure that it was working and then after that I added the other accounts.

I had everything working for about an hour.

#

2 things I figured out was when using my computer I can't select anything on the SpotifyPlus card to transfer playback. I can't select the speaker, or a song or play list. I can toggle between but I can't change what I am listening too.
I can do those things however from my phone using the HA app.

The 2nd was when I attempted to create an automation that would do a TTS notification over the chosen speaker, it caused the loss of the token. I had a moment where I thought I managed to save the token and all was well but then after a few minutes it stopped and was lost.

I did copy your YAML automation and was able to successfully use that with 3 different speakers and accounts. I am just trying to figure out how to make it happen at the same time across all the speakers.

#

I have 6 rooms, 6 accounts, 6 speakers. I need to create an automation, that will make an announcement over X number of speakers, but then start playing a different playlist from each account to the individual speaker of choice.

I would need this to be able to be interrupted at different intervals for a new announcement but then continue the music.

"It is 5am. Time to take meds." insert said music playlist
"It is 530am. You need to get up and get dressed."

#

continue playing music
"It is 6am. You need to leave in 30 minutes."
start new playlist

and it continues until whatever time.

Eventually once I get the smart lights set up I would incorporate lights turning on and or flashing.

I had it set at my last house, but just using the main family account that is linked to music assistant.

#

However, just now I was getting the token revoked on 1 account. I opened the Spotify app on my phone for that account and casted directly to the speaker and now it works in HA.

frosty totem
#

Are you sharing Spotify Developer Application client id / secret values between SpotifyPlus and HA Spotify or Music Assistant? If so, then that is the problem.

You indicated that "I had everything working for about an hour." Spotify authorization tokens are only good for 1 hour. That tells me that something else is using the same authorization token and refreshing it. You can't have more than 1 process using the same authentication token; if you do, one of the processes is going to fail, because the other process renewed the token and the original process doesn't know about it.

"I reinstalled one account first and made sure that it was working and then after that I added the other accounts. "
Try just using the one account for more than 1 hour (say 3 hours) and see if it works correctly. Vis SpotifyPlus, try transferring playback, selecting the speaker, selecting a song / playlist, etc. Do not use Music Assistant, nor HA Spotify, nor TTS notifications at this point. We are just trying to verify that everything is working via SpotifyPlus for the 1 account for more than a 2 hour period.

wet socket
#

There is only 1 account that MIGHT be sharing the ID/secret with MA and /or HA Spotify but it hasn't been an account I have been trying any of this with.

Although, it is the account that is used when anyone uses the voice assistant on their speaker so if they switch from playback on the phone to voice changing the account to their speaker?

I will disable MA and the HA Spotify.

frosty totem
#

I would recommend creating a new Spotify Developer App for the user, that way it's completely segregated from anything MA or HA Spotify is doing. AFAIK, you can have as many Spotify Developer Apps as you want. I also have not had any issues with using the same Spotify Developer App client id / secret with the HA Spotify integration and SpotifyPlus integration, but I have not used Music Assistant so not sure if they play well together.

wet socket
frosty totem
#

Are you using separate ID/secret values for each account as well?

And to be clear, you are not using the same ID/secret value for ALL accounts are you? You need separate Spotify Developer Apps for EACH Spotify account.

wet socket
#

yes, each account has it's own client ID/secret value. Everything is separate.

I have a word doc, that I copy and pasted each individual person/account one at a time as i went through the entire process following the documentation steps.

frosty totem
#

Sounds good. So what does your environment look like currently? Do you just have the 1 SpotifyPlus account configured? Were you able to verify that everything is working via SpotifyPlus for the 1 account for more than a 2 hour period?

wet socket
#

Unfortunately over the weekend I did not get a chance.

I am at work and trying to see what I can do not connected to the network.

#

Are you open to a DM or would you prefer to keep this going here?

frosty totem
#

I would be open to a DM if you like. What I would like to see is your Application Credentials list, as well as the SpotifyPlus service instances configuration.
For example, in my HA Test Instance I have the following defined:

  • media_player.spotifyplus_todd_l - Spotify premium account.
  • media_player.spotifyplus_todd_l_free - Spotify free account.

I have 2 Application Credentials defined for the 2 SpotifyPlus Services.
Here are screenshots of the configurations.