SpotifyPlus Custom Integration

Yes, i can browse all the media of my spotify account, but cannot play anything.
EDIT: Nothing in the logs…

@maurizio53
How did you play Spotify content prior to SpotifyPlus?

If you are using the Sonos card, then it probably won’t work as Sonos Card only supports Spotify integration (no SoundTouchPlus support AFAIK).

Also, what type of hardware are you using for play: Sonos? Bose Soundtouch? Chrome cast?

Thanks for your patience - I need to understand your environment before I can offer suggestions on how to fix.

Before i was using spotcast integration and only on chromecasts devices as in sonos it was not working. I have many chromecast devices and some echo…
Hope you fix this as your integration has more interesting features.

@maurizio53
Regarding ChromeCast devices and SpotifyPlus, you will still need to utilize SpotCast to play to those devices. I have not tested SpotifyPlus with Sonos, as I do not have any Sonos devices (Bose SoundTouch guy).

I am trying to learn how existing Sonos users play content using the original Spotify integration - it seems that the few Sonos users I have encountered (@prgeno ) are using the Sonos card for that. I am not quite sure how the Sonos card works, so I will be taking a look at that in the next few days. Hopefully it’s something simple, or maybe the Sonos card developer(s) could add support for SpotifyPlus. I will keep you posted on that effort.

Ok, can you send me a code for example how to use spotcast with your integration? I still cannot use spotify with Sonos card so when you know how to do it, please let me know…

@maurizio53
I don’t have any SpotCast examples on how to use Spotify (nor SpotifyPlus) with Sonos gear. You might reach out to the Sonos Card developer @PunxsutawneyPhil to see if he has an example of playing Spotify on Sonos gear using the Sonos Card.

Ok, but i was meaning about the use of Spotcast with SpotifyPlus and not with Sonos, but with Chromecast devices…

@maurizio53
Sorry, I should have been more clear. The only examples that I have for configuring SpotifyPlus is for the Bose SoundTouch line of gear, which does not require SpotCast. I don’t have any SpotCast examples on how to use Spotify (nor SpotifyPlus) with Google ChromeCast gear.

Check out the SpotCast integration GitHub project for more information on how to configure SpotCast for Google Chrome devices.

@prgeno
I had a chance to install and play with the Sonos Card today. I was able to successfully use it as a music player with the SpotifyPlus integration, keeping in mind that I do not have any Sonos devices attached. See Figure 3 below for an example.

I had to set the showNonSonosPlayers: true value in order for the Spotify, SpotifyPlus and SoundTouchPlus media players to show in the UI (obviously).

Some oddities that I noticed when using it with my Bose SoundTouchPlus integration media player:

  • Volume Changes - are not consistent among different media player types. For example, the Spotify and SpotifyPlus integrations were receiving the standard media player service command of set_volume_level to change the volume level. The SoundTouchPlus integration never received a set_volume_level service request, even though the Sonos Card volume slider adjusted to the new position.

  • Pause / Resume Play
    A media_pause service command was received to pause the playing content, but after about 10 seconds the player would display No media selected if resume had not been selected. It would also not allow you to resume play if the resume button was clicked within 10 seconds. The player remained in a paused state as normal for the Spotify and SpotifyPlus integrations.

Some oddities that I noticed when using it with ANY non-Sonos (SoundTouchPlus, Spotify, SpotifyPlus) integration media player:

  • Media Browser Favorites - the Sonos Card keeps calling the
    async_browse_media method with a media content type of favorites. I believe this is to query Sonos specific favorites maybe? It does this for both my SpotifyPlus and SoundTouchPlus integration media players. I had to put defensive code into the integrations, as it was raising exceptions and adding a lot of entries to the system log since it calls it every 3-10 seconds (even with numberOfFavoritesToShow=0). There is no favorites equivalent for the Bose SoundTouch (it stores favorites on a per music service basis).

My next step is to add my findings to the SpotifyPlus wiki documentation, as I like the Sonos Card UI layout for playing Spotify content. It’s a really cool player interface!

There are too many issues to recommend it for use with the SoundTouchPlus integration though. This is not a bad thing, as the developer probably did not have any Bose SoundTouch devices to test with (just like I don’t have any Sonos devices to test with). It’s near impossible to develop an integration for technology that you do not have on hand, and expect it to work flawlessly.

Anyway, hope it helps!

Figure 1 - SpotifyPlus Media Library
Notice the “Made For You” node item for browsing the Spotify “Made For You” content (see Figure 1a below). It also allows you to customize each media library index node with a custom image if you like.

Figure 1a - SpotifyPlus Made For You Content

Figure 2 - Spotify Media Library

Figure 3 - Sonos Card YAML
The following is my Sonos Card test YAML definition, defined to a new dashboard with a view type of Panel (1 card).

type: horizontal-stack
title: Sonos Card Test
cards:
  - type: custom:sonos-card
    sections:
      - groups
      - volumes
      - grouping
    showNonSonosPlayers: true
    entities:
      - media_player.spotifyplus_todd_l
      - media_player.spotify_todd_l
      - media_player.bose_st10_1
    mediaBrowserItemsPerRow: 10
  - type: custom:sonos-card
    sections:
      - player
    showVolumeUpAndDownButtons: true
    showNonSonosPlayers: true
    showAudioInputFormat: true
    artworkAsBackground: true
  - type: custom:sonos-card
    sections:
      - media browser
    showNonSonosPlayers: true
    predefinedGroups:
      - name: Group 1 SpotifyPlus
        media: ''
        entities:
          - player: media_player.spotifyplus_todd_l
      - name: Group 2 Spotify
        media: ''
        entities:
          - player: media_player.spotify_todd_l
      - name: Group 3 Bose ST-10-1
        media: ''
        entities:
          - player: media_player.bose_st10_1
    topFavorites:
      - Top Favorites Custom Title
    mediaBrowserTitle: Media Browser Custom Title
    numberOfFavoritesToShow: 20
    entities:
      - media_player.spotifyplus_todd_l
      - media_player.spotify_todd_l
      - media_player.bose_st10_1

This integration is great and provides a lot of fun possibilities. I’m currently trying to automatically generate daily playlists with it.

Some services depend on the ‘playlist history id’ and I am not sure how to find this specific id. Can someone help me out?

I tried your card code, but really don’t know why, clicking over the card of spotifyplus i don’t get the library browser as you show in the screenshot. I get nothing…

@shpongledsummer
I believe the playlist history id you are referring to is called a snapshot id in the Spotify Web API world. There is no Spotify Web API endpoint to list playlist snapshot id history. The only way to track it would be if you manually saved the snapshot id value returned from the AddPlaylistItems, ClearPlaylistItems, ReorderPlaylistItems, and ReplacePlaylistItems calls.

Also, AFAIK I don’t think there are any forms in the the Spotify Web App to list this information either.

UPDATE: I just found the Recover Playlist page in the Spotify web interface. Per the description … If you deleted a playlist within the last 90 days, you can get it back. Find the playlist you want to recover below and click Restore.

I’m not sure if that is for deleted playlists only (seeme like it is based on wording), or if it can be used to restore a past snapshot.

@maurizio53
What does your Sonos Card dashboard look like? Can you reply with a screen capture of your dashboard that contains the Sonos Card and with the SpotifyPlus player selected.

Mine looks like this:

To display the media browser:

  • click to select your SpotifyPlus player from the left pane (SpotifyPlus Todd L in my example).
    Note that the SpotifyPlus integration has to be turned on. I don’t think there is a way to do this in the Sonos Card, though I am not for sure.
  • click the Browse Media link in the right pane.
    This displays the HA media browser for the SpotifyPlus media player. Mine looks like this:

This is what i see after creating the dashboard:

After that i click in the right panel and i get the media browser for SpotifyPlus, but then clicking over any of the item to try a play i get the same error i notified you two days ago about the media_player.play_media service.

@maurizio53
The problem is that the SpotifyPlus integration is not turned on.

Add the following to your dashboard with the Sonos Card. It simply adds 2 buttons to power On and Off the SpotifyPlus media player. I know there are probably better ways to do this, as well as look better, but this is for testing.

square: false
type: grid
title: SpotifyPlus Power Options
columns: 2
cards:
  - type: button
    entity: media_player.spotifyplus_mfabiani53
    name: 'On'
    icon: mdi:power
    icon_height: 32px
    show_name: true
    show_icon: true
    tap_action:
      action: call-service
      service: media_player.turn_on
      data:
        entity_id: media_player.spotifyplus_mfabiani53
  - type: button
    entity: media_player.spotifyplus_mfabiani53
    name: 'Off'
    icon: mdi:power
    icon_height: 32px
    show_name: true
    show_icon: true
    tap_action:
      action: call-service
      service: media_player.turn_off
      data:
        entity_id: media_player.spotifyplus_mfabiani53

What it looks like:
image

Save your dashboard changes, and click the On button. This will issue a turn_on service call to the SpotifyPlus integration to turn it on. Once that happens, you should see the Player section of the Sonos Card come to life.

@maurizio53
I just noticed this in your previous reply …

Are you trying to use the SpotifyPlus integration with a Spotify FREE membership account? Or do you have a Spotify PREMIUM membership account? The Spotify Web API only supports player functions for Spotify Premium membership accounts. If you don’t have a Spotify Premium membership account, then you won’t be able to control the Spotify player. Note that this applies to both Spotify and SpotifyPlus integrations.

Ah, ok… but why using the Spotify integration i can play spotify songs?

Thanks for the answer. I guess some of the services like the playlist analysis don’t work without putting this playlist history id in the configuration, right?

Just to be clear, I’m taking about this input field:

@maurizio53
Are you saying that you can control (e.g. play, pause, skip next, volume up / down, etc) the Home Assistant Spotify integration player using a Spotify FREE membership account? If so then I will have to research that, as the Spotify Web API states that those functions are reserved for premium account users. I also verified this in my testing - I could not control the player when logged on as my Spotify free account.

Note that you can listen for free using the Spotify Web player via their web app, which is different than the Home Assistant Spotify (or SpotifyPlus) integration.

@shpongledsummer
I’m not familiar with MusixMatch, assuming that is what the input fields are for in your screenshot image. For the entry that says “Spotify Playlist History ID (not URI)”, I would assume it’s asking for a playlist ID value (e.g. 6W6yL4bv7LrD8belwn5Fi4) instead of a URI value (e.g. spotify:playlist:6W6yL4bv7LrD8belwn5Fi4). Note that playlist snapshot ID’s are a different format (e.g. MTk3LGEzMjUwZGYwODljNmI5ZjAxZTRjZThiOGI4NzZhM2U5M2IxOWUyMDQ) than the ID and URI formats.