Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Longer Working as of HA 2024.12.2 #5

Open
AnshulJ999 opened this issue Dec 11, 2024 · 7 comments
Open

No Longer Working as of HA 2024.12.2 #5

AnshulJ999 opened this issue Dec 11, 2024 · 7 comments

Comments

@AnshulJ999
Copy link

Describe the bug
The Spotify Plus integration is no longer working. The media player remains unavailable.

Expected behavior
The media player should show the playback state of Spotify.
Screenshots
If applicable, add screenshots to help explain your problem.

Environment details:

  • Environment (HASSIO, Raspbian, etc): HA OS
  • Home Assistant version installed: 2024.12.2
  • Component version installed: 1.1.9
  • Last know working version: 1.1.9
  • Spotify Account Type: Premium

Output of HA logs
Paste the relavant output of the HA log here.

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:737
integration: Sensor (documentation, issues)
First occurred: 12:14:33 AM (2 occurrences)
Last logged: 12:48:43 AM

spotify_plus: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/spotipy/client.py", line 271, in _internal_call
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/recommendations/available-genre-seeds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 737, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1318, in async_device_update
    await self.async_update()
  File "/config/custom_components/spotify_plus/sensor.py", line 227, in async_update
    ) = await asyncio.gather(
        ^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.13/site-packages/spotipy/client.py", line 1717, in recommendation_genre_seeds
    return self._get("recommendations/available-genre-seeds")
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/spotipy/client.py", line 323, in _get
    return self._internal_call("GET", url, payload, kwargs)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/spotipy/client.py", line 293, in _internal_call
    raise SpotifyException(
    ...<5 lines>...
    )
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/recommendations/available-genre-seeds:
 None, reason: None

This error originated from a custom integration.

Logger: spotipy.client
Source: custom_components/spotify_plus/media_player.py:417
integration: Spotify Plus (documentation, issues)
First occurred: 12:14:34 AM (714 occurrences)
Last logged: 12:50:14 AM

HTTP Error for GET to https://api.spotify.com/v1/playlists/37i9dQZF1FoyQGyinuuvRu with Params: {'fields': None, 'market': None, 'additional_types': 'track'} returned 404 due to Resource not found

Additional context
Add any other context about the problem here.

I am not sure if this integration is still actively developed, but I really liked it, and would really appreciate if it can be fixed.

Thanks.

@hokiebrian
Copy link
Owner

Thank you for raising the issue. Unfortunately, Spotify has removed access to certain API endpoints, many of which were core to this integration. I am working on getting it "dumbed down" to remove the affected elements, it's just taking time. I hope to have it updated by the end of the weekend.

Spotify announcement: https://developer.spotify.com/blog/2024-11-27-changes-to-the-web-api

@ColtonYYZ
Copy link

Any update on this? I was really looking forward to seeing my queued songs and your integration is the only one that can supply it. The other Spotify Plus integration doesn't go deep enough with their sensors. (I was hoping to use this:
spotify_plus.spotify_extras)

@hokiebrian
Copy link
Owner

I'm still working on it. Along with Spotify removing some endpoints, I need to change away from Spotipy to aiospotify and those are taking some time. Progress is being made...

@ColtonYYZ
Copy link

ColtonYYZ commented Jan 13, 2025

Hey @hokiebrian, I know you're busy making some changes, and with that, I appreciate your hard work!

I was wondering though, are you able to help me create a sensor that will extract the next up song for Spotify? I see it's available using the following action. I have also included the results you get when you run the action in Developer tools.

I'm hoping it's something relatively easy, but I have spent hours playing with sensors I created, and even using AI to assist but I just can't seem to extract the available info. :( Again, I appreciate your hard work with the integration!!

Action:

service: spotifyplus.get_player_queue_info
data:
  entity_id: media_player.spotifyplus_colton

Results (Sample - does not include the whole results I received):

user_profile:
  country: CA
  display_name: Colton
  email: [email protected]
  id: 31aa76dyfjpaykbmgjasgpeexnce
  product: premium
  type: user
  uri: spotify:user:31aa76dyfjpaykbmgjasgpeexnce
result:
  date_last_refreshed: 1736662949.711658
  currently_playing_type: track
  currently_playing:
    album:
      album_type: single
      artists:
        - external_urls:
            spotify: https://open.spotify.com/artist/6CtgBm0ZXwlnL45wP1VPMo
          href: https://api.spotify.com/v1/artists/6CtgBm0ZXwlnL45wP1VPMo
          id: 6CtgBm0ZXwlnL45wP1VPMo
          name: Toy Armada
          type: artist
          uri: spotify:artist:6CtgBm0ZXwlnL45wP1VPMo
        - external_urls:
            spotify: https://open.spotify.com/artist/6gjNx8L5hJfG1oGjLzLHou
          href: https://api.spotify.com/v1/artists/6gjNx8L5hJfG1oGjLzLHou
          id: 6gjNx8L5hJfG1oGjLzLHou
          name: DJ Grind
          type: artist
          uri: spotify:artist:6gjNx8L5hJfG1oGjLzLHou
      available_markets:
        - AR
        - AU
        - AT
        - BE
        - BO
        - BR
        - BG
        - CA
        - CL
        - CO
        - CR
        - CY
        - CZ
        - DK
        - DO
        - DE
        - EC
        - EE
        - SV
        - FI
        - FR
        - GR
        - GT
        - HN
        - HK
        - HU
        - IS
        - IE
        - IT
        - LV
        - LT
        - LU
        - MY
        - MT
        - MX
        - NL
        - NZ
        - NI
        - "NO"
        - PA
        - PY
        - PE
        - PH
        - PL
        - PT
        - SG
        - SK
        - ES
        - SE
        - CH
        - TW
        - TR
        - UY
        - US
        - GB
        - AD
        - LI
        - MC
        - ID
        - JP
        - TH
        - VN
        - RO
        - IL
        - ZA
        - SA
        - AE
        - BH
        - QA
        - OM
        - KW
        - EG
        - MA
        - DZ
        - TN
        - LB
        - JO
        - PS
        - IN
        - BY
        - KZ
        - MD
        - UA
        - AL
        - BA
        - HR
        - ME
        - MK
        - RS
        - SI
        - KR
        - BD
        - PK
        - LK
        - GH
        - KE
        - NG
        - TZ
        - UG
        - AG
        - AM
        - BS
        - BB
        - BZ
        - BT
        - BW
        - BF
        - CV
        - CW
        - DM
        - FJ
        - GM
        - GE
        - GD
        - GW
        - GY
        - HT
        - JM
        - KI
        - LS
        - LR
        - MW
        - MV
        - ML
        - MH
        - FM
        - NA
        - NR
        - NE
        - PW
        - PG
        - PR
        - WS
        - SM
        - ST
        - SN
        - SC
        - SL
        - SB
        - KN
        - LC
        - VC
        - SR
        - TL
        - TO
        - TT
        - TV
        - VU
        - AZ
        - BN
        - BI
        - KH
        - CM
        - TD
        - KM
        - GQ
        - SZ
        - GA
        - GN
        - KG
        - LA
        - MO
        - MR
        - MN
        - NP
        - RW
        - TG
        - UZ
        - ZW
        - BJ
        - MG
        - MU
        - MZ
        - AO
        - CI
        - DJ
        - ZM
        - CD
        - CG
        - IQ
        - LY
        - TJ
        - VE
        - ET
        - XK
      copyrights: []
      external_ids: {}
      external_urls:
        spotify: https://open.spotify.com/album/2vhMbDFvZyVRqHsF689vYb
      genres: []
      href: https://api.spotify.com/v1/albums/2vhMbDFvZyVRqHsF689vYb
      id: 2vhMbDFvZyVRqHsF689vYb
      image_url: https://i.scdn.co/image/ab67616d0000b2735f946be219df05adddb77a7f
      images:
        - url: https://i.scdn.co/image/ab67616d0000b2735f946be219df05adddb77a7f
          height: 640
          width: 640
        - url: https://i.scdn.co/image/ab67616d00001e025f946be219df05adddb77a7f
          height: 300
          width: 300
        - url: https://i.scdn.co/image/ab67616d000048515f946be219df05adddb77a7f
          height: 64
          width: 64
      label: null
      name: St. Elmo's Fire (Man in Motion) [feat. Jason Walker]
      popularity: null
      release_date: "2015-09-02"
      release_date_precision: day
      restrictions: {}
      total_tracks: 9
      type: album
      uri: spotify:album:2vhMbDFvZyVRqHsF689vYb
    artists:
      - external_urls:
          spotify: https://open.spotify.com/artist/6CtgBm0ZXwlnL45wP1VPMo
        href: https://api.spotify.com/v1/artists/6CtgBm0ZXwlnL45wP1VPMo
        id: 6CtgBm0ZXwlnL45wP1VPMo
        name: Toy Armada
        type: artist
        uri: spotify:artist:6CtgBm0ZXwlnL45wP1VPMo
      - external_urls:
          spotify: https://open.spotify.com/artist/6gjNx8L5hJfG1oGjLzLHou
        href: https://api.spotify.com/v1/artists/6gjNx8L5hJfG1oGjLzLHou
        id: 6gjNx8L5hJfG1oGjLzLHou
        name: DJ Grind
        type: artist
        uri: spotify:artist:6gjNx8L5hJfG1oGjLzLHou
      - external_urls:
          spotify: https://open.spotify.com/artist/0iRXawKcy8BO1tI2iPdUet
        href: https://api.spotify.com/v1/artists/0iRXawKcy8BO1tI2iPdUet
        id: 0iRXawKcy8BO1tI2iPdUet
        name: Jason Walker
        type: artist
        uri: spotify:artist:0iRXawKcy8BO1tI2iPdUet
    available_markets:
      - AR
      - AU
      - AT
      - BE
      - BO
      - BR
      - BG
      - CA
      - CL
      - CO
      - CR
      - CY
      - CZ
      - DK
      - DO
      - DE
      - EC
      - EE
      - SV
      - FI
      - FR
      - GR
      - GT
      - HN
      - HK
      - HU
      - IS
      - IE
      - IT
      - LV
      - LT
      - LU
      - MY
      - MT
      - MX
      - NL
      - NZ
      - NI
      - "NO"
      - PA
      - PY
      - PE
      - PH
      - PL
      - PT
      - SG
      - SK
      - ES
      - SE
      - CH
      - TW
      - TR
      - UY
      - US
      - GB
      - AD
      - LI
      - MC
      - ID
      - JP
      - TH
      - VN
      - RO
      - IL
      - ZA
      - SA
      - AE
      - BH
      - QA
      - OM
      - KW
      - EG
      - MA
      - DZ
      - TN
      - LB
      - JO
      - PS
      - IN
      - BY
      - KZ
      - MD
      - UA
      - AL
      - BA
      - HR
      - ME
      - MK
      - RS
      - SI
      - KR
      - BD
      - PK
      - LK
      - GH
      - KE
      - NG
      - TZ
      - UG
      - AG
      - AM
      - BS
      - BB
      - BZ
      - BT
      - BW
      - BF
      - CV
      - CW
      - DM
      - FJ
      - GM
      - GE
      - GD
      - GW
      - GY
      - HT
      - JM
      - KI
      - LS
      - LR
      - MW
      - MV
      - ML
      - MH
      - FM
      - NA
      - NR
      - NE
      - PW
      - PG
      - PR
      - WS
      - SM
      - ST
      - SN
      - SC
      - SL
      - SB
      - KN
      - LC
      - VC
      - SR
      - TL
      - TO
      - TT
      - TV
      - VU
      - AZ
      - BN
      - BI
      - KH
      - CM
      - TD
      - KM
      - GQ
      - SZ
      - GA
      - GN
      - KG
      - LA
      - MO
      - MR
      - MN
      - NP
      - RW
      - TG
      - UZ
      - ZW
      - BJ
      - MG
      - MU
      - MZ
      - AO
      - CI
      - DJ
      - ZM
      - CD
      - CG
      - IQ
      - LY
      - TJ
      - VE
      - ET
      - XK
    disc_number: 1
    duration_ms: 365742
    explicit: false
    external_ids:
      ean: null
      isrc: QMY2W1100427
      upc: null
    external_urls:
      spotify: https://open.spotify.com/track/4Oa9NeRlyuw2Kmxzdmq321
    href: https://api.spotify.com/v1/tracks/4Oa9NeRlyuw2Kmxzdmq321
    id: 4Oa9NeRlyuw2Kmxzdmq321
    image_url: https://i.scdn.co/image/ab67616d0000b2735f946be219df05adddb77a7f
    is_local: false
    is_playable: null
    name: St. Elmos Fire (Man in Motion) Feat. Jason Walker - House of Labs Dub Mix
    popularity: 7
    preview_url: null
    restrictions: {}
    track_number: 4
    type: track
    uri: spotify:track:4Oa9NeRlyuw2Kmxzdmq321
  queue:
    - album:
        album_type: single
        artists:
          - external_urls:
              spotify: https://open.spotify.com/artist/1moxjboGR7GNWYIMWsRjgG
            href: https://api.spotify.com/v1/artists/1moxjboGR7GNWYIMWsRjgG
            id: 1moxjboGR7GNWYIMWsRjgG
            name: Florence + The Machine
            type: artist
            uri: spotify:artist:1moxjboGR7GNWYIMWsRjgG
        available_markets: []
        copyrights: []
        external_ids: {}
        external_urls:
          spotify: https://open.spotify.com/album/4KCYejvKVfrQ8ILYblzhFc
        genres: []
        href: https://api.spotify.com/v1/albums/4KCYejvKVfrQ8ILYblzhFc
        id: 4KCYejvKVfrQ8ILYblzhFc
        image_url: https://i.scdn.co/image/ab67616d0000b2731b0c73410091fb1cdd7c1df1
        images:
          - url: https://i.scdn.co/image/ab67616d0000b2731b0c73410091fb1cdd7c1df1
            height: 640
            width: 640
          - url: https://i.scdn.co/image/ab67616d00001e021b0c73410091fb1cdd7c1df1
            height: 300
            width: 300
          - url: https://i.scdn.co/image/ab67616d000048511b0c73410091fb1cdd7c1df1
            height: 64
            width: 64
        label: null
        name: Shake It Out
        popularity: null
        release_date: "2011-01-01"
        release_date_precision: day
        restrictions: {}
        total_tracks: 4
        type: album
        uri: spotify:album:4KCYejvKVfrQ8ILYblzhFc
      artists:
        - external_urls:
            spotify: https://open.spotify.com/artist/1moxjboGR7GNWYIMWsRjgG
          href: https://api.spotify.com/v1/artists/1moxjboGR7GNWYIMWsRjgG
          id: 1moxjboGR7GNWYIMWsRjgG
          name: Florence + The Machine
          type: artist
          uri: spotify:artist:1moxjboGR7GNWYIMWsRjgG
        - external_urls:
            spotify: https://open.spotify.com/artist/4Ws2otunReOa6BbwxxpCt6
          href: https://api.spotify.com/v1/artists/4Ws2otunReOa6BbwxxpCt6
          id: 4Ws2otunReOa6BbwxxpCt6
          name: Benny Benassi
          type: artist
          uri: spotify:artist:4Ws2otunReOa6BbwxxpCt6
      available_markets: []
      disc_number: 1
      duration_ms: 202934
      explicit: false
      external_ids:
        ean: null
        isrc: GBUM71108047
        upc: null
      external_urls:
        spotify: https://open.spotify.com/track/2WtTU2qIgpk7HowzCGQMXy
      href: https://api.spotify.com/v1/tracks/2WtTU2qIgpk7HowzCGQMXy
      id: 2WtTU2qIgpk7HowzCGQMXy
      image_url: https://i.scdn.co/image/ab67616d0000b2731b0c73410091fb1cdd7c1df1
      is_local: false
      is_playable: null
      name: Shake It Out - Benny Benassi Remix Edit
      popularity: 0
      preview_url: null
      restrictions: {}
      track_number: 3
      type: track
      uri: spotify:track:2WtTU2qIgpk7HowzCGQMXy
      ```

@hokiebrian
Copy link
Owner

hey @ColtonYYZ - I published a pre-release version, 1.2.5, that should mostly work for the basic functions - including queues. As far as your other question... here's how I use the queue and recently played elements. The queue is an attribute of sensor.spotify_extras. You could just do a template sensor specific to item [0] in that list for just the next song if appropriate. I have some time to work more on this this week and should finally make some legit progress!

      - type: custom:auto-entities
        card:
          square: false
          type: grid
          columns: 2
        card_param: cards
        filter:
          template: |-
            {%-
               for item in state_attr('sensor.spotify_extras', 'queue') -%}
                 {{
                   {
                     'type': 'custom:button-card',
                     'layout': 'icon_name_state2nd',
                     'template': ['myrecentqueue'],
                     'variables': {'itemName':item.trackname, 'itemURI':item.trackuri, 'itemID':item.trackuri, 'itemSaved':item.saved},
                     'label': '',
                     'name': item.trackartist + '<br>' + item.trackname,
                     'entity_picture': item.image,
                     'tap_action': {'service_data':{'media_content_type':'music','media_content_id': item.trackuri} },
                     'double_tap_action': {'service_data':{'libraryinfo':'track','track_id': item.trackuri,'origin':'RecentQueue'} },
                     'hold_action': {'service_data':{'libraryinfo':'untrack','track_id': item.trackuri,'origin':'RecentQueue'} },
                   }
                 }},
                 {%- endfor %}

myrecentqueue:

variables:
  itemPlayed: none
label: |
  [[[
  const timeago = (new Date() - new
  Date(variables.itemPlayed)) / 1000;
  const minutes = Math.floor((timeago / 60));
  const formattedMinutes = String(minutes).padStart(0, '0');
  return `${formattedMinutes} minutes ago`;
   ]]]
show_label: true
show_name: true
aspect_ratio: 4.5/1
show_entity_picture: true
styles:
  card:
    - font-size: .6em
    - padding: 0px
    - border: 0px
  entity_picture:
    - scale: 1
    - padding: 0px
  custom_fields:
    logo:
      - position: absolute
      - top: 35%
      - left: 31%
      - color: firebrick
      - opacity: |
          [[[ 
             if (variables.itemSaved) return "90%";
               else return "10%";
          ]]] 
custom_fields:
  logo: |
    [[[
       return `<img src=/local/spotify-icon.png width=15 height=15>`
    ]]]
tap_action:
  action: call-service
  haptic: light
  service: media_player.play_media
  confirmation:
    text: '[[[ return `Play: ${variables.itemName}` ]]]'
  service_data:
    media_content_type: playlist
    entity_id: media_player.spotify_my
double_tap_action:
  action: call-service
  haptic: light
  service: script.song_library_tools`

That code helps build this. The icons are full color or not based on the song being in your library. Tap actions add / remove from the library.

Screenshot 2025-01-13 at 5 16 08 PM

@ColtonYYZ
Copy link

Hey @hokiebrian! Thanks for getting back to me so quickly!

One thing I have noticed was a mistake I made. I confused your integration with the other SpotifyPlus integration. When am running the following action, it's calling the other integration because your integration has an underline between the words Spotify and Plus, whereas the other one doesn't.

data:
  entity_id: media_player.spotifyplus_colton
action: spotifyplus.get_player_queue_info

I did try the yaml's you provided but they didn't work for me. The auto-entities doesn't display anything (literally nothing in my dashboard. I have to click 'edit' to see where it is so I can edit it. The second yaml has a bunch of ` in the code. It didn't work for me, so I checked with an AI tool and it corrected it for me to use ' (an apostrophy) instead. But when I view the card, it just says, "no history".

That said, I have tried all of the following possibilities below, and none of them seem to work for me. :( Any idea what I am doing wrong, or what I am missing? I realize it's not your integration this data is being pulled from, but if could provide some insight as to how I can extract the data I need from it, I would be very appreciative!

    - platform: template
      sensors:
        next_song_title_queued:
          friendly_name: "Next Song Title"
          value_template: >
            {% if state_attr('media_player.spotify_plus_colton_2', 'queue') %}
              {{ state_attr('media_player.spotify_plus_colton_2', 'queue')[0]['title'] }}
            {% else %}
              Unknown Title
            {% endif %}

    - platform: template
      sensors:
        next_song_3:
          friendly_name: "Spotify Next Song"
          value_template: >
            {% if state_attr('media_player.spotify_plus_colton_2', 'queue') and state_attr('media_player.spotify_plus_colton_2', 'queue') | length > 1 %}
              Upcoming Song
            {% else %}
              No upcoming songs
            {% endif %}

    - platform: template
      sensors:
        next_song:
          friendly_name: "Next Song"
          value_template: >
            {% if state_attr('media_player.spotify_plus_colton_2', 'queue') and state_attr('media_player.spotify_plus_colton_2', 'queue') | length > 1 %}
              {{ state_attr('media_player.spotify_plus_colton_2', 'queue')[0].title }}
            {% else %}
               No upcoming song
            {% endif %}

    - platform: template
      sensors:
        spotify_next_song:
          friendly_name: "Next Spotify Song"
          value_template: >-
            {%- set queue = state_attr('sensor.spotify_plus_extras', 'queue') %}
            {%- if queue and queue|length > 1 %}
              {{ queue[0].trackname }} by {{ queue[0].trackartist }}
            {%- else %}
              Please select your media
            {%- endif %}

    - platform: template
      sensors:
        spotify_next_song:
          friendly_name: "Next Spotify Song"
          value_template: >-
            {%- set queue = state_attr('sensor.spotify_plus_extras', 'queue') %}
            {%- if queue and queue|length > 1 %}
              {{ queue[0].trackname }} by {{ queue[0].trackartist }}
            {%- else %}
              Please select your media
            {%- endif %}

    - platform: template
      sensors:
        spotify_next_song_queued:
          friendly_name: "Spotify Next Song"
          value_template: >
            {{ states_attr('sensor.spotify_plus_extras', 'queue')[0].title }}

@ColtonYYZ
Copy link

I was able to get some help by @thlucas1 in a different post, and I finally got it working. Here's the link in case you were curious or wanting to do it too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants