Home Assistant Tags

I came here to ask the same question.

Is it possible to just scan an NFC card and use its pre-existing serial number (device id) that’s already on the card rather that having to first write the new Home assistant URL to the tag
The Home Assistant app will always write this URL to a tag first.

i.e. home-assistant.io/tag/_new_UUID_here

I have a potential use case in mind for this NFC tag integration but it would require reading the existing tags without having to first append the extra home assistant specific URL to them.
It’s for an asset tracking. Each item already has an NFC sticker attached

We’ve tested with the URL writing method using the Home Assistant app and while it works, it’s unnecessary overhead.
Even when you write the URL to the tag, the serial number remains, the URL is just appended to the card.

Thanks

Yes. I have a few NFC tags I bought on Ebay and have not coded anything onto them. When I scan them with my phone the Tag ID gets used and that is what I used to trigger the automations.

- id: d647683e-xxxx-xxxx-xxxx-xxxxxxxxxxx
    alias: Reticulation Station 1 NFC Tag       # Scanning the NFC tag will either run / stop the front garden retic
    trigger:
      platform: event
      event_type: tag_scanned
      event_data:
        tag_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx #redacted
    action:
      service: input_boolean.toggle
      entity_id: input_boolean.retic_station_1_run
2 Likes

Excellent! Thank you Sir.

1 Like

How do you get the Home Assistant application on the phone to capture the NFC tag scanned event and forward it to Home Assistant?

I know the technique you show works with an ESPHome-based reader project, where it forwards all the tag scanning events to Home Assistant. In my case, I have a mix of mobile phone devices and dedicated ESP8266-based readers and I wanted the same sort of action to occur in both cases.

I just put my phone over the tag, don’t even have to open the HA app.

When I scan an NFC tag that’s not been written with anything, I get a “Choose An Action” dialog that allows me to select between “Tasker” and “Tags” (which appears to be some Android NFC service). the Home Assistant mobile application never gets that unprogrammed tag passed to it.

Of course, if I write the tag with the Home Assistant app, it installed an NDEF URL record with the URL prefix that gets routed to the app…

It’s been a while since I both setup a Tag or even scanned one as I got them back when this was first released to play with but haven’t really utilised them yet so I can’t fully remember the process. I do know for certain though that they would scan and be actioned by HA without needing to open the app.

Yes, I get this behavior of it automatically scanning a tag, once the mobile app has written the NDEF URL record to it. Possibly you did that in the past?

You can tell if (on Android, anyway) you scan the tag while inside of some NFC diagnostic application. It’ll show you all the knarly bits.

Also, an unprogrammed NFC tag has an identifier that’s (it looks like) 7 bytes long. When I scan an unprogrammed tag using the ESP8266 with NFC reader and the sample code, I get an event that looks like:

event_type: tag_scanned
data:
    tag_id: 04-11-A9-01-33-35-03
    device_id: cd34c56ffc7a11ea9946afeb7b4b2451
origin: LOCAL
time_fired: '2022-01-12T04:48:40.805976+00:00'
context:
    id: bb33d3480a451ce9fb2cb09f4a43df1b
    parent_id:
    user_id:

When I scan a tag programmed by the Home Assistant mobile application, there’s a longer UUID-like identifier instead:

event_type: tag_scanned
data:
    tag_id: a4778414-e79e-4ac0-b343-0b4fe9b4d0d5
    device_id: cd34c56ffc7a11ea9946afeb7b4b2451
origin: LOCAL
time_fired: '2022-01-12T04:57:06.063095+00:00'
context:
    id: 6f99cdec22d7ee47db66afb1e7a546e2
    parent_id:
    user_id:

(These events come from the hass-cli program, invoked like hass-cli event watch tag_scanned – it might appear differently using the event monitor thing inside of Home Assistant itself.)

Your example looks like one of the programmed tag, not a “blank” one.

Hmm. not sure. I thought I had simply scanned the blank tag and told HA (via the GUI) that it was to associate that tag with a description. Maybe I just don’t remember.

Unfortunately I won’t be home for weeks so can’t test with either the one I had automated, or a blank one.

Hey all,

check out that (starting 2:00Min)
ESP32 playing music on Amazon Echo

This guy is simply writing the URI of spotify to the tag and plays the music on Amazon Echo.
Of course this is bypassing HA to validate the NFC, but actually, we don’t need HA neccessarily to just play some music from spotify.

Combined with the project of @schmurtz RFID Magic Box this would be the greatest portable “ESP-toni” you could build.

What’s your opinion on that?

makeratplay / esp32SpotifyEchoDot

Instead Amazon Echo you could also use an ESP32 with the squeezelite-esp32 firmware : it transforms an ESP32 into a squeezebox player able to read mp3, webradio ,spotify connect, airplay and many more. Not easier but it’s fun and the sound of the ESP32 with this firmware is awesome. cspot is an alternative : it is a spotify connect firmware for ESP32 that you could drive with HA.

And by the way if you need just web radio and tts notification you can use ESP8266 (very cheap!) or ESP32 thanks to the project I’m working on (initially created by MrDIY) : MrDiy-Audio-Notifier

Yeah you are completely right.

It depends on what is required, while I don’t have my requirements finally set yet.

Regardless what will be the hardware to output audio:

1.) Reading the card as you do, so detecting black and white constellations, will leverage 4 possibilities by one card. Which is totally cool.

Pro:
integrated in Esphome and HA which is cool to see what is playing and pressed and read by the nfc reader

Can be used for any scenario, not only as player.

Con:

  • ha down–》 no music will be played
  • it is only me able to write the automation to play the music

2.) Makeratplay has also some pro and cons

Pro:

  • Independently working:
    It does read the uri written to the tag and directly passes it to spotify api to play it on Amazon echo

  • my wife could write the tags as well, so I am not the only one able to create tags

  • Optional: not yet validated, but maybe this is possible to be integrated into esphome --》 this would leverage the integration into ha.
    Anyhow, if played on Amazon echo, it is integrated in HA by adding spotify component… so we would see what is playing currently.

Cons:

  • not yet possible to integrate into ha
  • dedicated to read only uri’s for spotify, so it cannot do anything else.
  • each uri must have an own card / sticker
  • buttons for switching track are missing currently

Output audio:
Squeezelite is absolutely the all-rounder…
CSPOT would be the alternative to Amazon echo, especially because audio controll is not needed

The audio notifier you are working on is awsome, but something I would not use here.

So, yeah… probably I will build two devices…
One, really close to your magic rfid box, for my personal fun

One for my kids being independent from ha, playing on any device connected to spotify.

So for info, I’ve received the tags I mentioned previously, and they work perfectly with Home Assistant :wink:

What is the max range of these tags/readers? I would like to put one on my dog’s collar to open his door, but he’s not going to hold it up to a reader.

Hi everybody,

I’m trying to build a jukebox system with RFID cards and card reader (thanks to @adonno amazing job).

I’ve follow this post : Home Assistant Tags - Home Assistant

It’s working as expected : after card is scanned, an album from my Plex server is played on my Sonos Speakers. You can see bellow my automation :frowning:

alias: Handle Tag Scan
mode: single
max_exceeded: silent
variables:
  media_players:
    3c4e54495a710c03a5bcbb9b74c3e98c: media_player.chambre
  tags:
    cca80f72-2604-960d-2014-099818b363dd:
      media_content_id: >-
        plex://{ "library_name": "Reggae JA / Albums", "artist_name":
        "Capleton", "album_name": "Reign of fire" }
      media_content_type: music
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
    target:
      entity_id: '{{ media_player_entity_id }}'
    data:
      media_content_id: '{{ media_content_id }}'
      media_content_type: '{{ media_content_type }}'
  - delay: 2

This method works, but maintain a matching table between tag’s id & plex album details seems really annoying and I have the feeling this can be optimized :wink:

Here is an exemple of a Plex album mapping :
plex://{ "library_name": "Reggae JA / Albums", "artist_name": "Capleton", "album_name": "Reign of fire" }

I’ve found out that it was possible to flash this data directly inside the tags as tag_id, and these tags are still recognized when they are scanned, so my idea is to find how to skip the matching table steps between tag’s id & plex album.

My idea:

  • When any tag is scanned an automation is fired
  • A condition in this automation check if the tag id start with plex:// to continue
  • The automation play the media referenced in my tag on my sonos speakers.

The downside :
I can’t find how to use the tag_id inside the automation action.
I totaly don’t know how to do a logical test on the first caracters of a string.

Any idea how to achieve this ? :sweat_smile:
Any help would be welcomed!!

1 Like

Just wanted to say a massive thank you for this - your blog post and instructions were pretty easy to follow so I could modify the bits for a sonos playlist, etc.

I had probably wasted about 2 days of my life trying to sort this out before coming across this… now my kids can easily play their favourite music without pinging me all of the time. If only Audible could be ties to a card!

Could do what I’ve done with YouTube set the tag id to the audible book specifically wanted and when you scan a tag the event contains the I’d and you construct the url using that. Saves you needing to create records in code.

There seems to be a minor oversight in the implementation of this feature. In Settings>Tags you can name your tags quite easily, for instance “Artist - Album” for media tags, “Apples” for “grocery list tags”, etc.

But those names mean nothing in the context of automations or working with the tags. So, for instance for every tag I want to trigger a play_media-automation, I would have to manually hand-code the automation to that specific album/artist - or adding that specific item to the grocery list, etc.

Instead, if the event tag_scanned contained the name of the tag you could maintain the “message of the card” in the Settings>Tags location, and write more general automations in terms of “if card scanned, translate name to ‘play media’ function”.

As it is now it’s basically if "04-21-D9-08-19-6C-80 scanned play “Artist - Album”, if “d1aea5a3-e725-4039-acd6-a2c419dd839e add Apples to grocery list”, etc.

I see others have the same need:

2 Likes

Hello, i’m new here. I read this blog beacuse i have a tag reader from @adonno which works very good. I also managed to make automation with a card that plays album from plex server on a sonos device.
Because of two kids i thought about making a simple jukebox with tagreaders and wifi speakers playing the favourite audio book for every kid.
Is it possible to scan nfc card 1 on tagreader 1 and play album on device 1 and then scan nfc card 1 on tagreader 2 and play album on device 2?
I dont know how to make the automation! Templates?
I appreciate every help you can give.

Hi @kannbert,

…exactly that i have also realized for my children. i use node-red for this as in many other cases. if you are interested i can explain it to you. unfortunately i have not had the time to deal with direct HA automations. for me it was easier to click it together in node-red years ago. but in the meantime the automations directly under homeassistant have also become simpler and more powerful.

the key to automation here is that each reader sends its own id through which the tag was scanned. this allows you to create a simple filter if scanner id X then play on player 1 if scanner id Y then…

so if you are interested in a node-red solution i am happy to help… otherwise the hint above already helps and maybe there is already a blueprint for it?


image