Play media on Alexa Media Player when a NFC-Tag is scanned

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

This idea is based on this Blueprint. When you scan a NFC tag the specified music will be played. Unlike the original Blueprint I added the ability to select from various streaming services:

  • Spotify
  • Amazon Music
  • Deezer
  • TuneIn
  • Universal: Enter the command you would say to your Echo device e.g. “Play my playlist Oldies on Spotify”. Requires Alexa Media Player version 3.4.0 or newer.

Because the tag ids cant be accessed by the selectors, you have to copy the ID from the NFC-Tags settings of your Home Assistant Instance.
I personally only use the Universal and Spotify streaming service. If you use the others and find something out about formatting the song name, please let me know so i can add them to the description.

Requirements:

  • Alexa Media Player installed (install it from HACS)
  • The according streaming service must be configured as an Alexa Skill inside your Alexa account
blueprint:
  name: Start music on Alexa Media Player when a NFC-tag is scanned
  description: |
    ## Introduction
    When a tag is scanned, start the associated music on the selected Alexa media player. 
    You can select from various streaming services or run your own commands with the "universal function".
    ## Supported Streaming Services
    ### 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).
    ### Universal
    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.
    ### Amazon Music, Deezer and TuneIn
    This should work as well, but I don't use them personally, so I cant say much abaout how to enter
    the song title. If you use them and know how to format them, please inform me so I can add it to the description.
  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
    source:
      name: Streaming Service
      description: Streaming service which should play your music
      default: Spotify
      selector:
        select:
          options:
            - Amazon Music
            - Spotify
            - Apple Music
            - Deezer
            - TuneIn
            - Universal
    volume:
      name: Volume
      description: Volume of the playback. 0 for 0% to 1 for 100%. E.g. a volume of 40% would be 0.4.
      selector:
        number:
          min: 0
          max: 1
          step: 0.01
    song_name:
      name: Song name.
      description:
        The name of the song to play. Look at the description of the Blueprint
        to see the right formatting for your specific Streaming service.
    shuffle:
      name: Shuffle mode
      default: False
      selector:
        boolean:

variables:
  source: !input source
  alexa_entity_id: !input alexa_entity_id
  song: !input song_name

trigger:
  - platform: tag
    tag_id: !input tag_id
action:
  - service: media_player.volume_set
    entity_id: !input alexa_entity_id
    data:
      volume_level: !input volume
  - service: media_player.shuffle_set
    entity_id: !input alexa_entity_id
    data:
      shuffle: !input shuffle
  - service: media_player.play_media
    data_template:
      entity_id: !input alexa_entity_id
      media_content_id: !input song_name
      media_content_type: >
        {% if source == "Universal"%}
          custom
        {% elif source == "Apple Music" %}
          APPLE_MUSIC
        {% elif source == "Amazon Music"%}
          AMAZON_MUSIC
        {% else %}
          {% filter upper %}
            {{source}}
          {% endfilter %}
        {% endif %}

Changelog:

  • 9 May 2021: Added volume as an input
  • 17 May 2021: Added input for shuffle mode
2 Likes

Would it be possible to add a settings for volume?

Volume input is added. Should work now

Great! Thank you very much

Is it possible for this to be trigger to be changed to an event type?

The reason I ask is I’m trying to use ShortCuts on Apple IOS so when I scan an NFC tag, the above happens, but I want to use ShortCuts so it can run in the background and I don’t have to click on the notification that pop ups from HA so the solution is to use ShortCuts to FireEvent to HA

I was having inconsistent results with the “shuffle mode” flag when using Spotify and calling a playlist. About half the time it would not stay on shuffle mode, so I came up with a workaround that may be useful to others.

Basically, I now use the “Universal” streaming service parameter and enter the following for the Song name parameter “Shuffle my playlist [insert playlist name here] from Spotify”. It now shuffles the playlist every time.

Thanks also for this awesome blueprint. I’m still relatively new to HASS and tracing through how this works helped me learn a good bit about blueprints.

I’m not sure what I’m doing wrong, but I can’t seem to get this blueprint to work? It doesn’t start playing any playlist on my Amazon Echo devices through Spotify?

service: media_player.play_media
data_template:
  entity_id: media_player.downstairs
  media_content_id: Playlist Tunez
  media_content_type: |-
    {% if source == "Universal"%}
      custom
    {% elif source == "Apple Music" %}
      APPLE_MUSIC
    {% elif source == "Amazon Music"%}
      AMAZON_MUSIC
    {% else %}
      {% filter upper %}
        {{source}}
      {% endfilter %}
    {% endif %}

To add to this:

params:
  domain: media_player
  service: play_media
  service_data:
    entity_id: media_player.downstairs
    media_content_id: Playlist Tunez
    media_content_type: SPOTIFY
  target: {}
running_script: false
limit: 10