RFID tag name from id in template

Did you try this?

Going to try right now.

Unfortunatelly, not working.

If you want to give node red a try then I suggest you pass the values to an entity where entity name is the id, and state is the name.
That way you can easily template it as you like.

Having an inject that injects once an hour to create new tags will probably be enough.

Well,
this can be question / feature request for integration developer. Why we can define name of tag if we can’t get it.

Use the dev tools events page to see what data is returned by a tag_scanned event.

EDIT: I just tried with one of my tags. The data does not include the name (some data redacted):

{
    "event_type": "tag_scanned",
    "data": {
        "tag_id": "00Exxxxx",
        "device_id": "xxxx96a73962fxxxxxxx862e2a8dexxxxxxx"
    },
    "origin": "LOCAL",
    "time_fired": "2021-08-22T08:27:04.187126+00:00",
    "context": {
        "id": "2b52a44303xxxxxxxxxxxxxxd6b",
        "parent_id": null,
        "user_id": null
    }
}

Seems the easiest way to do this is going to be a template that maps id’s to names in your automation.

Thanks a lot,
I just did the same testing in dev tools and as documentation says too, tag_id amd device_id are returned only.
Maintaing some kind of ‘local’ name table is a bit impractilal, so way to get tag name by id or field name in event data could be a feature request.
If this is not possible, than maintaining tag names from gui is meaningless.

Definitely worth asking for:

Edit: someone already has, vote here:

https://community.home-assistant.io/t/include-name-field-in-tag-scanned-event-data/253720

1 Like

Well,
two years without the vote… It is not likely that something will happen :frowning:

WTH month might be coming next month. Keep it in mind.

1 Like

If you use this sequence and connect that to the event node when you scan a tag then you should be able to get the name of the tag and all that.
But that means your automation will be running in node red.

[{"id":"907645a9.63a318","type":"file in","z":"48ef5c6b.b38b24","name":"","filename":"/config/.storage/tag","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":410,"y":1240,"wires":[["8d13f7ee.92c858"]]},{"id":"ea6a6141.d6cb6","type":"inject","z":"48ef5c6b.b38b24","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":360,"y":1080,"wires":[["907645a9.63a318"]]},{"id":"8d13f7ee.92c858","type":"json","z":"48ef5c6b.b38b24","name":"","property":"payload","action":"","pretty":false,"x":590,"y":1200,"wires":[["3c8f4821.07a408"]]},{"id":"3c8f4821.07a408","type":"function","z":"48ef5c6b.b38b24","name":"","func":"\nfor (let value of msg.payload.data.items) {\n    msg.tag = value.tag_id;\n    msg.name = value.name;\n    node.send(msg)\n\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":1260,"wires":[["c165a8fa.6281c8"]]},{"id":"c165a8fa.6281c8","type":"debug","z":"48ef5c6b.b38b24","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":1080,"wires":[]}]

+1 on this…also voted for the feature.

This is the reason why I stopped bothering with the tags feature in Home Assistant. My idea was to have rfid stickers on my grocery boxes and after a scan the grocery names would be added to a shopping list. But it was too laborious to maintain two huge separate lists of mappings.
Added a vote too.

1 Like

This is a much needed feature - it would remove the need to hand-code every automation in terms of “play media”, “add item to grocery list”, etc.

As it stand you need to make a translation_function for each tag_id to a name, but you already maintain the tag_name in the Tags_section.

I also voted on the feature, it would seem like a small thing to transfer.

1 Like

Using a variation of the node red sequence I posted earlier you should be able to get a complete translation table.
Here is my broadlink commands.

You should be able to create an entity with attributes like “RFID tag”: “friendly name of tag”.
And in automations that could be used like {{ state_attr('sensor.tag_names', [scanned value]) }} to get the friendly name.

Hi, thanks for getting back to me.

I’m unable to quite decode if what you’re suggesting is using a node-red intermediary to get the card name?

With node red sequence:

[{"id":"907645a9.63a318","type":"file in","z":"ebaa69a9.649708","name":"","filename":"/config/.storage/tag","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":370,"y":2240,"wires":[["8d13f7ee.92c858"]]},{"id":"ea6a6141.d6cb6","type":"inject","z":"ebaa69a9.649708","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":2240,"wires":[["907645a9.63a318"]]},{"id":"8d13f7ee.92c858","type":"json","z":"ebaa69a9.649708","name":"","property":"payload","action":"","pretty":false,"x":550,"y":2240,"wires":[["3c8f4821.07a408"]]},{"id":"3c8f4821.07a408","type":"function","z":"ebaa69a9.649708","name":"","func":"var arr = {};\n\nfor (let value of msg.payload.data.items) {\n    arr[value.tag_id] = value.name;\n}\nmsg.arr = arr;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":2240,"wires":[["c165a8fa.6281c8","87225d05cb08334e"]]},{"id":"c165a8fa.6281c8","type":"debug","z":"ebaa69a9.649708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":2300,"wires":[]},{"id":"87225d05cb08334e","type":"ha-entity","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"RFID tags"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"","stateType":"date","attributes":[{"property":"tags","value":"arr","valueType":"msg"}],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":890,"y":2220,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

I can get an entity in HA with all the tags:

Now in an automation I can use a template to get the name of the scanned tag.

alias: New Automation
description: ''
mode: single
trigger:
  - platform: event
    event_type: tag_scanned
condition: []
action:
  - service: notify.mobile_app_YOUR_PHONE
    data:
      message: '{{ state_attr(''sensor.rfid_tags'', ''tags'')[trigger.event.data.tag_id] }}'

The node red sequence does not run by itself, it would need to be either initiated by a file watcher that looks for changes on the file or something else, or just manual as it is now.

Ah, okay - that makes sense … I would think that the ‘tag_scanned’ event could initiate the nodeRed to search the file for the relevant tag, correct?

Either way, it seems to be a work-around that would work - so I will probably look into it, but as it stands I would seriously consider it a lack of foresight not to include the tag_name in the tag_scanned event :confused:

1 Like

Yes, can be done. But caching it in a entity as I did here probably makes more sense.

Perhaps a better solution is if the automation returns unknown or unavailable or whatever the failed automation returns, use that as the trigger to run the Node red sequence.
That way when you add new tags, you swipe a new tag again and everything will be updated.

Oh, okay - I seem to have misunderstood what you’re doing.

I thought I had it down to:
For everytime a tag is scanned, search the file for corresponding name, and then initiate an automation.

The way I see you’re doing it is:
Everytime the file is changed, update the entity containing all tags from file - which is the smarter way, meaning that most of the ‘instant logic’ is preserved in HA and not passed from HA to NodeRed and back to HA at the moment a tag is scanned.

Thanks for clarifying, now I think this option is a much better alternative than my original understanding. It’s still a missing feature, that it’s not in HA itself - but your solution seems more elegant than I understood at first!

Without any doubt, this is workaround and it can be written in Appdaemon, pyscript, maybe in native python script too, not only in node red, but still, this should be built in.