SOLVED: Continue playing spotify on different device via triggering a script


When on the go, I often listen to music via headphones connected to my mobile phone.

And whenever I arrive home, I navigate through the Spotify app on my phone just to select a different device located in my home to continue listening there.

Now I would like to automate this process, by creating a script in HASS which allows me to trigger it via press of a button or via a nfc tag.

at the moment, that works via the media_player.spotify entity, which allows me to switch the source of the currently playing playlist/song to the desired source. but i want to automate this process by triggering it via http post command e.g…

How can I approach this ideally? I just don’t see a way how to set up an according script as they require me to specify a playlist/song to play instead of the “currently playing” playlist.

solved it as it turns out that by just switching the source via HASS, music continues playing on the new selected source.

So I attached an almost invisible nfc sticker outside next to my front door, so that while arriving i can start the task before entering home.

the nfc sticker is written via the app “trigger”, which allowed me to browse through the available tasker actions and select the relevant one.

the action in tasker is setup as follows:

  1. Create an HTTP Post task via Net → HTTP Post.
  2. Fill in the following fields
    3.1 Server Port → http://YOUR_HASS_IP:PORT
    3.2 Path → /api/services/script/turn_on?api_password=YOURPASSWORD
    3.3 Data / File → {“entity_id”:“script.SCRIPT_NAME_IN_HASS”}
    3.4 Content Type → application/json

the tasker action defined above basically calls the HASS script added into the scripts.yaml:

  • service: media_player.select_source
    entity_id: media_player.spotify
    source: LivingRoomStereo

Hey there @k1282

I have a slightly different issue, but from your post, you may be the person with an answer?

Searched quite a bit and cannot find:
I play spoitfy on my phone (blutooth to my car system), but, when arriving home (my phone’s location triggers the garage door to open, some lights to go on etc), I would like to turn on my home sound system (already happening via an automation in HA), and then simply continue playing on that system.

I do realize that there is a simple “device” button I can press in Spotify, but, hey, there are buttons I can press to turn on the lights and open the garage door too :slight_smile: The whole purpose of HA is to do it for me, so I don’t have to, right?

So, I am a noob very much , and have limited knowledge, but, I am hoping you could advise?

So I have an automation that will detect my phone is home. It will also activate a scene where my home sound system activates, and is ready to Spotify. I just need to find out what would be the code to type in HA, to make it switch from the car bluetooth as playback device to the Yamaha amp in the house.

Ok, so I know what the amp is called in HA, but, I don’t know what the entity and process should be called in HA to make Spotify change it’s playback device, or it’s playback source (the amp can also serve as source directly, therefore, I could have HA just change the source also). But, my limitation is in finding out/knowing what those Spotify entities/functions are called, and how to address them in HA.

Any advice would be highly appreciated.

Hey! Have you got a solution for this? I’m looking to make the same automation. Thanks !

Hey there, I think I did, yes, but, unfortunately, around August last year - about two months after sorting this, something went wrong in Linux (I am running HAOS inside Vbox), and since then, I have never been able to fix the Linux or the VBox or the HOAS to work again. Am actually here today to try and get some help :slight_smile:

Since I have many Google Home speakers in the house, and I use Google Assistant, most of the general stuff are just automations inside Google Assistant, and I’m literally too lazy to find a fix for my HAOS. Therefore this delay in getting it up and running again.

Yet, there are a few things that I cannot do with Google Assistant, that HA can do, so, if I can get back into my HAOS, I will come back here and post. I cannot remember, for the life of me, what the solution was, I just know it did work.

@riaaneloff @emilef @k1282

I developed the SpotifyPlus Home Assistant custom component integration that expands the built-in Spotify integration capabilities. It’s a simple install to the “custom_components” directory via a HACS UI custom repository installer.

It has a Transfer Playback custom service that can transfer playback from one Spotify Connect device id to another. Example:

service: spotifyplus.player_transfer_playback
  entity_id: media_player.spotifyplus_john_s           # Bose ST-10 device
  device_id: 6f66ef4fbf687bbba393d8c38599aad484b30901  # Bose ST-300 device id
  play: True

Thought you would like to know, and hope it helps!