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

Add to media_player attributes if a Track its on Favorites or not #71

Open
3 tasks done
divinerain96d opened this issue Jan 4, 2025 · 2 comments
Open
3 tasks done

Comments

@divinerain96d
Copy link

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

I want to make a simple mushroom template button with a heart that shows when the current track its on my favourites list and when I tap the button toggles the status, I made before with the old Spotify_Plus integration from https://github.com/hokiebrian/spotify_plus and I know this can be made with an automation when content_id changes and calling "check favorite" action but I think can be easy added to the media_player attributes and get this true or false from there.

Describe the solution you'd like

Simply add an attribute to the media_player entity with favorite status of the current playing track calling the "check favorite" action when content_id changes.

Describe alternatives you've considered

Im actualy working on an automation to make it.

Additional context

None, just say thanks to the developers for this awesome integration =)

@thlucas1
Copy link
Owner

thlucas1 commented Jan 4, 2025

I am hesitant to add the favorite status indicator, as it adds more overhead to the player update process.

You can easily check favorite status of the currently playing track by calling the following service:

service: spotifyplus.check_track_favorites
data:
  entity_id: media_player.spotifyplus_john_s

You can easily add the currently playing track to your favorites by calling the following service:

service: spotifyplus.save_track_favorites
data:
  entity_id: media_player.spotifyplus_john_s

You can easily remove the currently playing track to your favorites by calling the following service:

service: spotifyplus.remove_track_favorites
data:
  entity_id: media_player.spotifyplus_john_s

@divinerain96d
Copy link
Author

divinerain96d commented Jan 4, 2025

Thanks, I undestand you, if helps someone I maded with scripts and automations, its a simple, big button to have in my car's dashboard to easily add current track to my favorites and remove when the button its hold.

Here is the code:
Note: Needs an input_boolean helper to store the value.

Scripts:

alias: Spotify Get Favorite
sequence:
  - data:
      entity_id: media_player.spotifyplus_
    action: spotifyplus.check_track_favorites
    response_variable: Liked
  - delay: "00:00:01"
  - choose:
      - conditions:
          - condition: template
            value_template: |
              {{ Liked.result.values() | list | first == true }}
        sequence:
          - target:
              entity_id: input_boolean.spotify_liked
            action: input_boolean.turn_on
            data: {}
      - conditions:
          - condition: template
            value_template: |
              {{ Liked.result.values() | list | first != true }}
        sequence:
          - target:
              entity_id: input_boolean.spotify_liked
            action: input_boolean.turn_off
            data: {}
description: ""
alias: Spotify Follow Unfollow
description: Script to follow or unfollow a Spotify track and refresh song data
fields:
  follow:
    description: Set to true to follow the track, false to unfollow.
    example: true
    required: true
    selector:
      boolean: null
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ follow == true }}"
        sequence:
          - action: spotifyplus.save_track_favorites
            metadata: {}
            data:
              entity_id: media_player.spotifyplus_
      - conditions:
          - condition: template
            value_template: "{{ follow == false }}"
        sequence:
          - action: spotifyplus.remove_track_favorites
            metadata: {}
            data:
              entity_id: media_player.spotifyplus_
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - action: script.spotify_get_favorite
    metadata: {}
    data: {}
mode: single

Automation:

description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - media_player.spotifyplus_
    attribute: media_content_id
    id: NuevaCancion
conditions: []
actions:
  - alias: Si nueva cancion Actualiza
    if:
      - condition: trigger
        id:
          - NuevaCancion
    then:
      - action: script.spotify_get_favorite
        metadata: {}
        data: {}
    enabled: true

Button:

type: custom:mushroom-template-card
    entity: input_boolean.spotify_liked
    icon: |
      {% if is_state('input_boolean.spotify_liked', 'on') %}
        mdi:heart
      {% else %}
        mdi:heart-outline
      {% endif %}
    icon_color: |
      {% if is_state('input_boolean.spotify_liked', 'on') %}
        red
      {% else %}
        gray
      {% endif %}
    tap_action:
      action: call-service
      service: script.spotify_follow_unfollow
      target: {}
      data:
        follow: true
    hold_action:
      action: call-service
      service: script.spotify_follow_unfollow
      target: {}
      data:
        follow: false
    fill_container: true

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

2 participants