Support for playing "Liked songs"-playlist for Spotify-integration

Hi,

I’m using Spotify for quite asome time now, I’ve pressed the :heart: -icon on all the songs I like. Spotify then puts all these songs in a playlist called “Liked songs”. This playlist isn’t public and doen’t have an URI to call via the spotify.play_playlist-service. Apperently there’s an API call for playing the songs in this playlist. It would be great to have a service call (or some other possibility) to trigger playing this playlist from HA. Yes, there are workarounds, but I thinhk it would be great to have the possibility to trigger playing this playlist. Feedback is more than welcome.

Fabian

Did you ever find a solution for this?

2 Likes

Hi, could you share the workarounds to play songs from the “liked” playlist?

1 Like

+1, this would be great, I plan to link it to a hue button so I can start whole house music from my liked playlist

It will be nice for all players, very often in other players this function does not work the way the user wants. Also, it would be great for HA to collect its own playlist, and take into account that it plays more often.

Was this ever added?

2 Likes

You can play your Liked Songs with the URL spotify:user:<your-spotify-username>:collection. Your username can be retrieved from Login - Spotify.

The Android application also supports spotify:collection:tracks, but it doesn’t seem to work with the Web API.

9 Likes

Thank you @robin.thoni
I’ve tried a half dozen different ways to play Spotify Liked Songs over the last year. From using Pushcut + iOS Shortcuts to playing a voice command so that Google mini or Alexa start it. This is so much better, thanks!

1 Like

I see “Liked Songs” playlist is currently available as “Tracks” in media selection of the default card, but it is missing the option to play them all, like the one available in “Playlists”. Playback stops after the selected song is over of course.

@f1ac @OzStone @robin.thoni @BigIron @nick2525 @thisisamateurhour @pedrodelrio @FlangeMonkey @Fabenissimo

FYI - My SpotifyPlus integration can do this - check out the links below for more information.

It will play items from your list of “Liked Songs” (up to 200 tracks max). It also supports setting the shuffle mode on the service call.

Here’s an example from the wiki documentation:

service: spotifyplus.player_media_play_track_favorites
data:
  entity_id: media_player.spotifyplus_john_s
  shuffle: true

Hope it helps!

More Information Links

3 Likes

Thanks a lot @thlucas for the awesome work!

I’m still struggling though to get the “play liked songs” working.

The SpotifyPlus integration is correctly installed. I have a Devialet at home. I added the Turn On script (I’m not entirely sure what it does and if it’s needed ^^):

alias: Turn-on SpotifyPlus
sequence:
  - service: spotifyplus.player_transfer_playback
    data:
      entity_id: media_player.spotifyplus_max
      device_id: "*"
      play: true
    enabled: true
    alias: Transfer Spotify Playback to Devialet device.
mode: single
icon: mdi:power

And then I created this automation:

alias: Play liked songs
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 826792121570c6bc1eb517ae3c6556f2
    type: action
    subtype: 3_single
condition: []
action:
  - service: media_player.select_source
    metadata: {}
    data:
      source: devialet
    target:
      entity_id: media_player.spotifyplus_max
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.25
    target:
      device_id: a31c9371a4f6300243426450b7d56b89
  - service: spotifyplus.player_media_play_track_favorites
    metadata: {}
    data:
      entity_id: media_player.spotifyplus_max
mode: single

But it doesn’t seem to work…any idea what I’m doing wrong?

Thanks a lot :pray:

@maxve
I am not familiar with Devialet … but after Googling, it seems like it’s just a smart speaker device. At this point, I assume that you are able to play Spotify content from your phone to the Devialet speaker? If not, follow the How to use Spotify Connect? article on their web-site to do so. You have to have that working first (I assume that you do; just adding it for any future users that run across this thread).

With that said, let’s make sure you have the integration properly configured …

Step 1 - Verify Spotify Web API connectivity

  • First thing is to see if you can see your Spotify content via the HA Media Browser for the SpotifyPlus media player (named media_player.spotifyplus_max per your yaml example).

    Browse to the following url: http://homeassistant.local:8123/media-browser/media_player.spotifyplus_max (change your url prefix if needed).

    That should display the standard HA media browser with your SpotifyPlus media player selected. It should look something like the following (note my player name is SpotifyPlus Todd L, and I have custom icons associated with some of my Spotify content types):

    Can you select your Spotify Playlist and Tracks content for the SpotifyPlus player?

    If so, then that tells me the integration is configured correctly and you are able to access the Spotify Web API to retrieve Spotify data for your user account.

    If not, then you will need to follow the integration install wiki page steps to configure the SpotifyPlus integration.

Step 2 - Verify you can Play Spotify Content via HA Media Player

  • If you don’t already have a SpotifyPlus media player dashboard configured …
    Create a new dashboard with a standard HA media player instance using the following yaml:

    type: media-control
    entity: media_player.spotifyplus_max
    

    It should look something line this (this is my player, powered on):
    image

    Power on the player, and select something from the media browser (e.g. playlist, track, etc) to play.

    If nothing plays, then check your turn on script (see below).

    If something does play, then that tells me you have everything in HA configured properly, and that the HA media player is talking to the Spotify Connect Player for the Devialet device.

Turn On Script

  • The turn on script will be executed when a turn_on service request is made to power on the SpotifyPlus integration. The script can be used to prepare the audio output device(s) (e.g. devialet in your case) for playing Spotify Connect Player content. In your case, you can place the select_source and volume_set steps from your Play liked songs automation into the turn on script (see Figure 1 below). This is similar to what I have to do for my Bose SoundTouch speaker(s) - in my case it selects the Spotify source on the Bose, and transfers Spotify playback to the Bose device.

    Your Play Liked Songs Automation would then become just a trigger, and a call to the spotifyplus.player_media_play_track_favorites service. You may need to add a check in there to see if the SpotifyPlus integration (e.g. media_player.spotifyplus_max) is turned on, and issue a media_player.turn_on service call if necessary. For this test, just turn it on manually for now.

Figure 1 - turn on script

alias: Turn-on SpotifyPlus
sequence:
  - service: media_player.select_source
    metadata: {}
    data:
      source: devialet
    target:
      entity_id: media_player.spotifyplus_max
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.25
    target:
      device_id: a31c9371a4f6300243426450b7d56b89
  - service: spotifyplus.player_transfer_playback
    data:
      entity_id: media_player.spotifyplus_max
      device_id: a31c9371a4f6300243426450b7d56b89
      play: true
    enabled: true
    alias: Transfer Spotify Playback to Devialet device.
mode: single
icon: mdi:power

Figure 2 - Play Liked Songs Automation

alias: Play liked songs
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 826792121570c6bc1eb517ae3c6556f2
    type: action
    subtype: 3_single
condition: []
action:
  - service: spotifyplus.player_media_play_track_favorites
    metadata: {}
    data:
      entity_id: media_player.spotifyplus_max
mode: single

You can also associate your Devialet device with the SpotifyPlus player using the Configure options form (see below). In this example, I have my Bose-ST-1 speaker assigned as the default Spotify Connect Player for my media player.

Give the above a try and let me know how it goes.

Thanks a lot for the detailed answer. The issue is that the automation is not waiting for the turn_on script to finish before running the next service (play favorites).

This results in unstable behavior (music switches to devialet, and then switches back to my phone). But if I add 5 seconds delay in the automation between callin turn_on and play favorites then no glitches.

Here is my turn_on script:

alias: Turn-on SpotifyPlus
sequence:
  - condition: or
    conditions:
      - condition: state
        entity_id: media_player.devialet
        state: idle
      - condition: state
        entity_id: media_player.devialet
        state: paused
  - service: spotifyplus.player_transfer_playback
    data:
      entity_id: media_player.spotifyplus_max
      device_id: "*"
      play: true
    enabled: true
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.25
    target:
      device_id: 19a084976575e39e6e863a89238ff31d
mode: single
icon: mdi:power

and here is my play liked music automation (without the 5s delay):

alias: Play liked songs
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 826792121570c6bc1eb517ae3c6556f2
    type: action
    subtype: 3_double
action:
  - service: media_player.turn_on
    data:
      entity_id: media_player.spotifyplus_max
  - service: spotifyplus.player_media_play_track_favorites
    metadata: {}
    data:
      entity_id: media_player.spotifyplus_max
      shuffle: true
mode: single

Any pointer? Thanks a lot!

Note: below automation works, but then it’s not using the turn_on service included with SpotifyPlus…

alias: Play liked songs
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 826792121570c6bc1eb517ae3c6556f2
    type: action
    subtype: 3_double
action:
  - service: script.turn_on
    target:
      entity_id: script.turn_on_spotifyplus
  - wait_for_trigger:
      platform: event
      event_type: script_finished
      event_data:
        entity_id: script.turn_on_spotifyplus
  - service: spotifyplus.player_media_play_track_favorites
    metadata: {}
    data:
      entity_id: media_player.spotifyplus_max
      shuffle: true
mode: single

I would probably go with the script that is working and do not use the turn-on service included with SpotifyPlus. You just have to keep in mind that you will need to use a similar sequence for any other automations that start SpotifyPlus like this script does.

Just out of curiosity, I wonder what would happen if you replaced the script.turn_on with a media_player.turn_on with the SpotifyPlus turn on script option set to script.turn_on_spotifyplus? You may need to add a small wait delay (100ms?) after the media_player.turn_on to give the turn_on script time to get started so the wait_for_trigger \ script_finished can detect the event.

Hi guys, I have this simple code in HomeAssistant to play liked songs from Spotify in HomeAssistant. Don’t know if anyone wants to use it but it works.

type: custom:button-card
show_entity_picture: true
entity_picture: /local/images/logo/deezerr.png
tap_action:
  action: call-service
  service: media_player.play_media
  service_data:
    entity_id: media_player.first_echo_dot #this is your device ID NOT your group ID
    media_content_id: my liked songs in homegroup group #here is where you place your group ID name. In my case my Alexa group name is called homegroup
    media_content_type: SPOTIFY
template: radio_button

I have several Alexa’s and thus created a group.
If you also have a group just use 1 of your Alexa’s device name in the
entity_id name. If you use the groupname it won’t work.
At the line that says media_content_id that’s where you use the
Alexa group name. In my case “homegroup”
If you own just one Alexa device change that to the device’s name.

(yes I am aware that the deezerr.png logo is wrong. I’ve switched from deezer
to spotify but I am too lazy to change the image)

Thank you so much! This works like a charm. You saved my day! :smiley:

alias: Spotify test
sequence:
  - service: media_player.select_source
    data:
      # based on https://www.home-assistant.io/integrations/spotify/#selecting-output-source
      source: Living Room Speaker
    target:
      entity_id: media_player.spotify_andras

  - service: media_player.play_media
    target:
      entity_id:
        - media_player.spotify_andras
    data:
      # based on https://www.spotify.com/hu/account/profile/
      media_content_id: spotify:user:1111111111:collection
      media_content_type: playlist
description: ""
icon: mdi:music
1 Like