Start music on Alexa media player (or movie on Plex) when a tag is scanned

Thanks for creating this Blueprint. Couple questions if you dont mind…
Im totally lacking the knowledge needed in yaml as of now, but Im learning. I have a playlist in spotify I would like to play through my echo device. What part of the code and with what would I change it to.

Thanks,
Jace

According to the doc (https://www.home-assistant.io/integrations/spotify/), replace AMAZON_MUSIC by playlist and in the song_name input use the spotify playlist URI (see doc above for how to get it).

I gave it a try. I added the url from the share spotify playlist link into the song id and set the media content type to playlist. Nothing played. Unfortunately…
Thank you

Sorry but I don’t have a Spotify account so I can’t try.

I changed your blueprint so its more universal and modified some descriptions. It needs some work on the descriptions and though cause I only tested Universal, amazon and spotify (i dont have the rest), but it seems to work fine. Its a good working prototype

Maybe you can check this out and look if you wanna adept this to your blueprint. Its solves the issues with spotify for the most users and as a last chance you can use the Universal source, where you can type in what you would say to your alexa device and it will work.

blueprint:
  name: Start music on Alexa when a tag is scanned
  description:
    When a tag is scanned, start the associated music on the selected Alexa media player.
    You can also run commands with the "universal function"
  domain: automation
  input:
    tag_id:
      name: Tag ID
      description:
        The tag ID of your NFC trigger. Can be found under Settings --> NFC Tags
        and then click on the NFC Tag you want to choose.
    alexa_entity_id:
      name: Alexa player
      description: The entity ID of the alexa player to use
      selector:
        entity:
          domain: media_player
    song_name:
      name: Song name.
      description: The name of the song to play. The source is specified below.
        Make sure to select only one source. If its known that a source must be formatted right
        then its specified in the source you can select.
    source_amazon:
      name: Amazon Music
      description: Music is from Amazon Music. The Song name can be the songname
      default: false
      selector:
        boolean:
    source_spotify:
      name: Spotify
      description:
        Music is from Spotify. Song name must be songname (e.g. Still Alive),
        songname and interpret (e.g. Still alive from Red ),
        "playlist" and playlist name (e.g. Playlist Oldies)
        or the name of a featured playlist from Spotify (e.g. Missed Hits).
      selector:
        boolean:
    source_apple:
      name: Apple Music
      description: Music is from Apple Music.
      default: false
      selector:
        boolean:
    source_deezer:
      name: Deezer
      description: Music is from Deezer.
      default: false
      selector:
        boolean:
    source_tunein:
      name: TuneIn
      description: Music is from TuneIn.
      default: false
      selector:
        boolean:
    source_custom:
      name: Universal
      description:
        You can put a command in the songname which you would say to your Alexa device e.g.
        "Play my playlist Oldies on Spotify" (leave out your trigger word from your device).
        Requires Alexa Media Player version 3.4.0 or newer.
      default: false
      selector:
        boolean:

variables:
  is_spotify: !input "source_spotify"
  is_amazon: !input "source_amazon"
  is_apple: !input "source_apple"
  is_deezer: !input "source_deezer"
  is_tunein: !input "source_tunein"
  is_costum: !input "source_custom"

trigger:
  - platform: tag
    tag_id: !input tag_id
action:
  - service: media_player.play_media
    data_template:
      entity_id: !input alexa_entity_id
      media_content_id: !input song_name
      media_content_type: >
        {% if is_amazon %}
          AMAZON_MUSIC
        {% elif is_spotify %}
          SPOTIFY
        {% elif is_apple %}
          APPLE_MUSIC
        {% elif is_deezer %}
          DEEZER
        {% elif is_tunein %}
          TUNEIN
        {% elif is_costum%}
          custom
        {% endif%}

1 Like

any idea how (if it’s possible) to extend this to allow the Alexa device be selected via an Input Select dropdown similar to how you’ve done it in your TTS Blueprint. Ideally using the Friendly Name of the media_player entity rather than it’s entity_id

Also, as an aside “borrowing” the Input Text structure from your TTS Blueprint (same link as above) allows you to input a song/playlist as text and have this play when the automation executes (I’m using a button in the UI to call the automation)

You can copy the selectors (exept the announce selector) from the TTS blueprint. Also copy the media_entity part of the TTS Automation and copy it to the media_entity of this (in the actions). At last copy the trigger and add it also.

I dont know if you can use the friendly name in the input-select, that you have to try it out. This automation uses another service.

1 Like

Cheers…yeah its the friendly name part that doesn’t want to work…thanks for coming back to me :+1:t2:

Yeah I have done some tinkering. This should now work:

blueprint:
  name: Start music on Alexa when a tag is scanned
  description:
    When a tag is scanned, start the associated music on the selected Alexa media player.
    You can also run commands with the "universal function"
  domain: automation
  input:
    tag_id:
      name: Tag ID
      description:
        The tag ID of your NFC trigger. Can be found under Settings --> NFC Tags
        and then click on the NFC Tag you want to choose.
    alexa_entity_id:
      name: Alexa player
      description: The entity ID of the alexa player to use
      selector:
        entity:
          domain: media_player
    song_name:
      name: Song name.
      description: The name of the song to play. The source is specified below.
        Make sure to select only one source. If its known that a source must be formatted right
        then its specified in the source you can select.
    source_amazon:
      name: Amazon Music
      description: Music is from Amazon Music. The Song name can be the songname
      default: false
      selector:
        boolean:
    source_spotify:
      name: Spotify
      description:
        Music is from Spotify. Song name must be songname (e.g. Still Alive),
        songname and interpret (e.g. Still alive from Red ),
        "playlist" and playlist name (e.g. Playlist Oldies)
        or the name of a featured playlist from Spotify (e.g. Missed Hits).
      selector:
        boolean:
    source_apple:
      name: Apple Music
      description: Music is from Apple Music.
      default: false
      selector:
        boolean:
    source_deezer:
      name: Deezer
      description: Music is from Deezer.
      default: false
      selector:
        boolean:
    source_tunein:
      name: TuneIn
      description: Music is from TuneIn.
      default: false
      selector:
        boolean:
    source_custom:
      name: Universal
      description:
        You can put a command in the songname which you would say to your Alexa device e.g.
        "Play my playlist Oldies on Spotify" (leave out your trigger word from your device).
        Requires Alexa Media Player version 3.4.0 or newer.
      default: false
      selector:
        boolean:
    message:
      default: []
      name: Input of Song input from the UI
      description: Input text where the Song comes from
      selector:
        entity:
          domain: input_text
    target:
      default: []
      name: Target of the notification (Input Select)
      description: The alexa device where the notification should be played. Must be in a input select. Options can be the Friendly Name, Serial Number, entity_id, or Home Assistant Group.
      selector:
        entity:
          domain: input_select

variables:
  is_spotify: !input "source_spotify"
  is_amazon: !input "source_amazon"
  is_apple: !input "source_apple"
  is_deezer: !input "source_deezer"
  is_tunein: !input "source_tunein"
  is_costum: !input "source_custom"
  alexa_entity_id: !input alexa_entity_id
  message: !input message
  target_for_message: !input target
  song: !input song_name

trigger:
  - platform: tag
    tag_id: !input tag_id
  - platform: event
    event_type: state_changed
    event_data:
      entity_id: !input message
action:
  - service: media_player.play_media
    data_template:
      entity_id: >
        {% if trigger.platform == "event" %}
          {{states.media_player| selectattr("attributes.friendly_name","equalto", states(target_for_message)) |map(attribute="entity_id") |first}} 
        {% else%}
          {{alexa_entity_id}}   
        {% endif%}
      media_content_id: >
        {% if trigger.platform == "event" %}
          {{states(message)}}
        {% else%}
          {{song}}
        {%endif%}
      media_content_type: >
        {% if is_amazon %}
          AMAZON_MUSIC
        {% elif is_spotify %}
          SPOTIFY
        {% elif is_apple %}
          APPLE_MUSIC
        {% elif is_deezer %}
          DEEZER
        {% elif is_tunein %}
          TUNEIN
        {% elif is_costum%}
          custom
        {% endif%}
3 Likes

@GameOnRammy Just change the trigger section to whatever you’d like.

1 Like

Thanks, a lot for thevquick reply, will give it a try, I’m still new to this but I’m learning.

Hmm I get

unknown tag !<!input> at line 82, column 38:
     ... spotify: !input "source_spotify"
                                     ^

Never mind, seems to be a bug in the text editor - works fine!

Hello, i am trying to build a blueprint simmilar to yours, but it would be nice if i can use a selector for the NFC Tags. I didn´t find any documentation if that is possible. Do you have any idea how to not copy & paste every NFC ID manually? Maybe this could be a nice feature…

Hi,
At the time I wrote this it wasn’t possible (or if it was I didn’t succeed in doing it).
Maybe now this can be done, I don’t know. I don’t think I will spend time to try to add it.
Cheers,

I would also love this. I might have a look to see if it’s reasonable to add that to the code and submit it to HA (Open Source software really is a wonderful thing).

1 Like

Hey!
I tried using the Plex variant here, but I can only get it to work for starting the movie on the browser instance of Plex Client. I can’t get it to cast a la chromecast, or play through the Plex app on my Android TV.
I’m new to HA automation (this is actually the first one I have set up) so I’m not sure if there’s any additional info I can share to help. AFAICT, there’s nothing of use in the trace.

Anyone know if its possible to play an Album with Amazon Music? Instead of making individual tags for each song sometimes I just want to play the whole album like for example Pink Floyd.

This works for me:

service: media_player.play_media
data:
  entity_id: media_player.echo_office2
  media_content_id: album "Dark Side of the Moon"
  media_content_type: AMAZON_MUSIC
1 Like

Thank you very much