Home Assistant Tags

Implant a chip while they sleep :joy::rofl:

1 Like

HI! I have problem getting the jukebox up and running. I was wondering if anyone could help me out? I have everything up and running with the rfid-reader and the tagging is working fine. I have Spotify integration up and running. But what I dont get is some rows in the yaml-script. For example: What in the example am I supposed the alter? So if someone could post the script, and put “change this” or “xxxxxxx” where I need to have my own data would be very helpful.
Thanks in advance.

I’m not sure what your problem is but this is my NFC jukebox yaml which is the same as in the article.

The spotify url’s are just (working) examples. You can add NFC tags and Spotify url’s to the end (under “variables”).

alias: 'NFC jukebox'
description: Build our own NFC jukebox
trigger:
  - platform: event
    event_type: tag_scanned
condition:
  - condition: template
    value_template: '{{ trigger.event.data.tag_id in tags }}'
  - condition: template
    value_template: '{{ trigger.event.data.device_id in media_players }}'
action:
  - variables:
      media_player_entity_id: '{{ media_players[trigger.event.data.device_id] }}'
      media_content_id: '{{ tags[trigger.event.data.tag_id].media_content_id }}'
      media_content_type: '{{ tags[trigger.event.data.tag_id].media_content_type }}'
  - service: media_player.play_media
    data:
      entity_id: '{{ media_player_entity_id }}'
      media_content_id: '{{ media_content_id }}'
      media_content_type: '{{ media_content_type }}'
  - delay: '2'
mode: single
max_exceeded: silent
variables:
  media_players:
    a8951b26089711eba8615f80f42541eb: media_player.spotify_my_account
  tags:
    4C-04-1E-23:
      media_content_id: 'spotify:track:5ESGW72VURk7fyX3cXrZcd'
      media_content_type: track
    27-BC-D3-C7:
      media_content_id: 'spotify:playlist:37i9dQZF1DWV0gynK7G6pD'
      media_content_type: playlist
    077f2a8a-f6e1-4b40-9a68-9e5b3e147bd2:
      media_content_id: 'spotify:album:6YxxmZYhalM0hX6XN8dR2o'
      media_content_type: album

So you only have to write (or use the written) nfc tags of labels or cards (short or long ones) and combine them to your favorite spotify music using spotify url’s. Hope this helps.

For those interested, I am going to try to setup an automation that stores the jukebox data on the tags itself, instead of in the automation

The tag would store something like:

action: play_media
data:
  media_player: spotify
  media_content_type: playlist
  media_content_id: 'spotify:playlist:37i9dQZF1DWV0gynK7G6pD'

or

action: play_media
data:
  media_player: kodi
  media_content_type: video
  media_content_id: 'smb://server/video/tags/some_video.mkv'

Then the automation would use the tag data and reader location to determine what to do, like play something on whole home audio, or just on a specific tv

Dojf: Thank you for your help. I am not up and running just yet. The thing that I dont get is 2 things: Under “media_players:” you have a device ID of the scanner. Where do I find that ID? And second, where/how do the jukebox choose witch speakers the music should play from?
Found the ID trough Developer Tools. But still wondering how to choose speakers. Now it plays on my phone, but i need to be able to play it on my Sonos-devices. Any tips?

Ok, you found the device id of the tag reader in developer tools. It can be found also in the /config/.storage/core.device_registry file and there search for “tagreader” (or whateven you named the tagreader) and see the “id” field.

The speaker choice in the Spotify environment (selection of the “source”) is a different problem, as Spotify treats that as dynamic items and HA uses the Spotify API and so cannot do much about it. See the long discussions here.
A sort of solution can be found in the HA custom component Spotcast but I have no experience there.

My Spotify default “Source” is (perhaps by accident :wink: ok, but this is the part where I’m also still wrestling as I want to use two more (media) tagreaders in the house.

Dojf: Thanks. Yeah, it would be great if we could choose Source for Spotify to be anything we like(Sonos for me). I found this thread were it seems to be possible to play Spotify URI on Sonos. So maybe some smart person could mix this technic with RFID Jukebox somehow.

Thx, @adonno - NFC reader has been delivered!

1 Like

@adonno I’m a happy user of your tag reader solution and thanks a lot for your work and effort.
I have a problem that I could not resolve or, maybe, I didn’t understand how it works.

Prerequisites
a. Wemos D1 mini
b. PN RFID 532
c. Card & tag, 13.56 MHz
d. master branch pn532_i2c

Use case
I want to use my Huawei Mate 20 Pro as an NFC Tag

What I did

  1. Open Home Assistant Companion which is logged in at HA instance
  2. NFC Tag option from Settings
  3. Write Tag on White Card
  4. Returning results
- platform: event
  event_type: tag_scanned
  event_data:
    device_id: 93d872ca49dfe4d7
    tag_id: ce1685b2-0bdf-4786-bea4-39caa49c4035
  1. Fire event button
  2. Check if ce1685b2-0bdf-4786-bea4-39caa49c4035 is displayed in Tags from configuration
  3. Make the following automation in automation.yaml
- alias: "Huawei NFC Access"
  initial_state: True
  mode: single
  trigger:
  - platform: event
    event_type: tag_scanned
    event_data:
      device_id: 93d872ca49dfe4d7
      tag_id: ce1685b2-0bdf-4786-bea4-39caa49c4035
  action:
    - service: switch.toggle
      entity_id: switch.shelly_1pm
  1. Reload automation
  2. Swipe Huawei Phone

Expected results

  1. The bulb must be switched on

Actual results

  1. The bulb is not light on and a new entry is created in Tags
  2. Huawei and White Card still have different identificators

More actions

  1. Go To events and listen tag_scanned
  2. Scan Huawei and White Card
    –> “device_id”: bf45cac435a56ede5256ea83fed4f9c0 is the same for both.
    –> tag id is different than the id created with HA Companion
    –> device_id is different than the id created with HA Companion


3. Go to automation and at device_id paste bf45cac435a56ede5256ea83fed4f9c0 value

New automation code excluded tag_id

- alias: "Huawei NFC Access Device ID"
  initial_state: True
  mode: single
  trigger:
  - platform: event
    event_type: tag_scanned
    event_data:
      device_id: bf45cac435a56ede5256ea83fed4f9c0
    #   tag_id: ce1685b2-0bdf-4786-bea4-39caa49c4035
  action:
    - service: switch.toggle
      entity_id: switch.shelly_1pm
  1. Reload automation
  2. Swipe White Card --> the bulb is switching ON
  3. Swipe Huawei --> the bulb is switching ON
  4. Check Tags from HA
    New Tag is created for Huawei
  5. Swipe Huawei again
    New Tag is created for Huawei

Expected results
Huawei and White card should be considered one entity
When I write a new card

      device_id: 93d872ca49dfe4d7
      tag_id: ce1685b2-0bdf-4786-bea4-39caa49c4035

must be used in automation in order to make two entities to act as one


More Testing

  1. Go To HA companion and read White Card
    –> results
- platform: event
  event_type: tag_scanned
  event_data:
    device_id: 93d872ca49dfe4d7
    tag_id: ce1685b2-0bdf-4786-bea4-39caa49c4035
  1. Make the following automation
- alias: "Huawei NFC Access"
  initial_state: True
  mode: single
  trigger:
  - platform: event
    event_type: tag_scanned
    event_data:
      device_id: 93d872ca49dfe4d7
      tag_id: ce1685b2-0bdf-4786-bea4-39caa49c4035
  action:
    - service: switch.toggle
      entity_id: switch.shelly_1pm
  1. Fire the event directly from the HA companion / Button Fire Event
    –> The bulb is switching ON and OFF
    –> Verify-in Tags if ce1685b2-0bdf-4786-bea4-39caa49c4035 was used == yes
  2. Swipe Huawei in order to obtain the same result
    –> a new tag is created
    –> the bulb remains switched off

In conclusion
if I used Fire Event button directly from HA companion the phone trigger the action and in TAGS is used the device id which was created, but if I put the same values in the automation I am not able to obtain the same behavior

2 Likes

Hi, is that working ?

Has anyone tried to read an NFC tag with the HA iOS Companion App on an iPhone 12 Pro? I can’t seem to get it to read or write any card or tag. My HA Tag Reader picks up all my cards and tags fine however.

What NFC tags are you trying to scan? Not all will work on a mobile especially the lower frequency cards and the keyring tags. NTAG are 13.56 MHz tags and pretty much all NFC enabled phones can read/write to them. If you stick to the NTAG type tags you should be ok.

1 Like

It was the card and keyring tag that came with my HA Tag Reader…so I figured there wouldnt be an issue. I ended up ordering another set of cards off Amazon and they worked…strange!

actually, on the order page, it is stated that these cards are read-only. Apparently only under iOS read-only

Don’t ask me why unfortunately I get them like that

Still working on it, it requires changes to the esphome source code in c, and my free time is… minimal

Hi
Already some time ago, but I have the same problem

iPhone Shortcuts setup reads NFC perfectly.
Shortcuts automation itself afterwards also recognizes tag an triggers events.

The tag reader for Home Assistant also recognizes the tag

But HomeAssistant App can not read the tag.
iPhone SE 2020, ios 14.2, HomeAssistant App 2020.7

Any ideas ? Is this a bug ? Or an oversight from my part ?

Greets
Arnout

Have you written to the TAG first with HA? It needs to format it from within the app first before it can read it.

Hi, sorry for the noob question. I am brand new to this.
I have setup my home assistant on my Raspberry PI.
I have added the jukebox YAML.
I have my tagreader (thanks adonno), connected to Home Assistant and it reads the tags I scan.
But now I am lost. How do I actually make the jukebox work? I guess I need to associate events to the tags I scan, but how does it actually make the jukebox start playing the spotify song or album on the device I want?

My question is has someone made a step by step guide for making this work?
Thanks for any help you can provide.

You will need to create a script which selects a playlists depending on which tag was scanned.

Something similar to this would work:

script:
  internet_radio:
    alias: Play Internet Radio
    sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge_speakers
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.everywhere
          {% elif is_state("input_select.chromecast_radio", "Back yard") %} media_player.back_yard
          {% endif %}
        volume_level: '{{  states.input_number.volume_radio.state  }}' 
    - service: media_player.play_media
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge_speakers
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "Everywhere except office") %} media_player.all_except_office
          {% elif is_state("input_select.chromecast_radio", "Back yard") %} media_player.back_yard
          {% endif %}
        media_content_id: >
          {% if is_state("input_select.radio_station", "Hit 92-9") %} http://ic6ti.scahw.com.au/6ppm_128
          {% elif is_state("input_select.radio_station", "Nova 93-7") %} http://streaming.novaentertainment.com.au/nova937
          {% elif is_state("input_select.radio_station", "Mix 94-5") %} http://sc01.scahw.com.au/6mix_32
          {% elif is_state("input_select.radio_station", "96FM") %} https://icy.ihrcast.arn.com.au/au_012_icy

          {% endif %}
        media_content_type: 'audio/mp4'

Swapping out the radio station URL’s for Spotify playlists and the input_select info for your tag read data.

I know it’s not a nice simple guide but hopefully it helps.

2 Likes

Hey guys,
I have sucessfully installed the adonno Tag reader and this is working with the lastest version of HA with tags and services like shutter und switches.
But i could not get it working with spotfiy links on my sonos s2 system.
Can anyone give me a sample configuration of the automation action:
This is my current setting which does not work.

service: media_player.media_play
data:
  entity_id: media_player.kuche
  media_content_id: 'https://open.spotify.com/track/5T490vvoFNU6psep0NPmxs?si=OD-_qchVSiGIf3wT3FUllw'
  media_content_type: music

Do i need to install the spotify HA integration? (This was also installed in the mean time, but down not work)

Thank you in advance, hope i will get fixed my christmas present for my daughter.