Home Assistant Tags

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

Is this hardware compatible with pet RF chips? If so, what is the range, a few inches I’m guessing. I’d like to make my house respond to my pets going somewhere they should not (e.g. each other’s food, the guest room, etc.).

dear friends,
before working on the configuration of this work I would like to know something very important for me:
is it possible to get notification of the tag approched in realtime, keeping a NFC card attached to the reader continuosly or Home Assistant read just a single approach and the the next approach without understanding if the card is attached to the tag reader in realtime?
I don’t need to approach the card to the reader once in order to create an action but I do need to know if the NFC card is attached to the tag reader and it must be a realtime information as we have on HA for the lights/switchs when are on or off (card is attached or not).
Thank you for those who will reply me.

Not sure what happened with the last update. Now none of my readers will work. Kinda bites too. Grandson loved scanning his cards to start his movies. The card scans, logs show the tag reader see’s it, home assistant is clueless it happened.

@schmurtz
How do you detect the Black Corners of the card?
Can you share details?

hm, is it detect by home assistant ? Does the LED work ? Maybe removing the reader and readding it could solve the issue ?

Well. Its all working now. I had to reset home assistant to the last backup I had which was 6 months old (I need to do better at remembering to back up HA lol), reflashed the readers (built 4 so far) and things seem to be working. After that I backed up everything again and updated everything but esphome. (all the while getting full backups as I went). I updated esphome to 10.0 and same issue with the readers. Reset back to prior backup and reflashed the readers and they work. Didn’t update esphome until 10.2 and everything is still working. Not sure what the deal was with esphome 10.0 but it didn’t like my readers.

Thank you for sharing the readers with everyone. Its been fun watching the grandson use the reader to play movies with. Using jellyfin and roku media player since thats all I can get working. Hope to get plex to work but its hit and miss.

I set this up like presented here and its all working great. I wanted to be able to make the entity_id a little more flexible but still tied to the device that scanned the card, so I added a select component with a few entity_ids to the esphome config. I am trying to use HA templates to get the slected option from the select component, but I am getting stuck. This is what I have:

  action:
    - variables:
        media_player_entity_id: >-
            {% for entity in expand(device_entities(trigger.event.data.device_id))|map(attribute='entity_id')|list %}
              {% if is_state_attr(entity, 'friendly_name', 'Media Players') %}
                "{{ states(entity) }}"
              {% endif %}
            {% endfor %}

It seems not to evaluate. I tested in developer tools | templates (substituting trigger.event.data.device_id with the actual device_id and it seemed to work ok.
What am I doing wrong?

Hello @adonno,
Is it possible to replace the D1 mini with a C3 mini so that I get all the existing features plus a Bluetooth repeater? If so, do you know what would be the pinout?

It would be nice if tags could be added to groups and even assigned to users… Been playing with a nfc card reader for a possible door access control system and having home assistant as the way to control users access using the tag scanned feature of esphome would be nice to be able to get new tags into the system without having the create a new binary sensor on the esphome config firmware everytime.

How about doing it the other way around, have the tag at the door instead of the reader. User scans the tag with a phone and then the rest is done with automations in HA.

Is this one ever solved? I’m facing the same issue.

As a person that’s not good at programming I can’t find the issue heren. My script is the same, only changed the media_player entity for now. Even ChatGPT doesn’t give me a solution to this question.

You mention script, yet this is an automation…so, where are putting this code? If it’s inside automations.yaml then you need to remove the automation: line at the start of the example.

1 Like