Tags and NodeRed [Help ..]

Hi,

I need some help with use TAGS in node red. I have a esphome build NFC reader, which works as very well. In the native automations I can use the tags. But I want the tags in node red (since I do all the automations in node red).

What I want is that the tags are passed to switch (which contains all the NFC tags that I needed) to I can start the action for that tag.
But how to I get the tags since its not an entity … its part of a trigger event … I already found out that the tags are in a message object … and I need a function to get the tags , but no idea how to create the function …

1 Like

I cannot help specifically with this, since I am not using Tags.
However, maybe the generic tip will help you out:

To find out the even trigger you need:

Create a new Event Trigger node and listen to ALL EVENTS. Connect this to a debug node and set it to COMPLETE MSG OBJECT
Then scan a NFC Tag and look at the debug node output.

There you should see exactly the event you need to listen too. Then just filter for this, and use the message further as you see fit.

1 Like

Can you copy the entire msg.payload here? I don’t know the structure of the message being sent. But, usually, it is rather easy to extract the “correct” information from a payload…

1/3/2021, 11:25:30 AM[node: ec84bc64.10841](http://192.168.1.120:8123/api/hassio_ingress/ES6PpbSYNjDZjNBPm2CaaW0b9W_99l_fVJf1T8QQ58U/#)tag_scanned : msg.payload : Object

object

event_type: "tag_scanned"

entity_id: undefined

event: object

tag_id: "13-96-C2-59"

device_id: "2f07e0f38c934ea195fd6b86cbc85a0e"

origin: "LOCAL"

time_fired: "2021-01-03T10:23:13.650026+00:00"

context: object

id: "e0ba17d82d3890b9528d20432a2c94b9"

parent_id: null

user_id: null

OK. So, put this output into a json node and then the tag_id is in msg.payload.event.tag_id.
From there, through (eg) switch node you can decide what you want to do with it.

This is the way I do it:

[{"id":"66f8719e.c96e1","type":"tab","label":"NFC","disabled":false,"info":""},{"id":"592fae54.01da6","type":"server-events","z":"66f8719e.c96e1","name":"nfc test","server":"783e002.7fe69","event_type":"tag_scanned","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":67,"y":153,"wires":[["8f3081c0.a9512","98af3e9d.c845"]]},{"id":"8f3081c0.a9512","type":"debug","z":"66f8719e.c96e1","name":"nfc","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":203,"y":119,"wires":[]},{"id":"98af3e9d.c845","type":"switch","z":"66f8719e.c96e1","name":"Welk device","property":"payload.event.device_id","propertyType":"msg","rules":[{"t":"eq","v":"45b44ecd38df7d4f","vt":"str"},{"t":"eq","v":"525f71f96253fefe","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":223,"y":153,"wires":[["4a62c4bc.b07d4c"],["4a62c4bc.b07d4c"]],"info":"1 is telefoon Edward\n2 is telefoon Arienne"},{"id":"4a62c4bc.b07d4c","type":"switch","z":"66f8719e.c96e1","name":"Welk TAG nr","property":"payload.event.tag_id","propertyType":"msg","rules":[{"t":"eq","v":"b169da45-7df7-4434-9207-2ddd8298fc71","vt":"str"},{"t":"eq","v":"b8a434a4-03f2-4088-8466-d1fdf07b59cf","vt":"str"},{"t":"eq","v":"a0f7a859-a6dd-4d65-8e36-93d38462b43f","vt":"str"},{"t":"eq","v":"b831dec7-f068-4c7a-b3c3-34bfda913058","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":393,"y":153,"wires":[["7fe9155a.c922fc","a8ad46b9.fe43b8","56996bb7.381664"],["df4bb418.ffc748","7fe9155a.c922fc"],["8f6083fd.e5a8e","7fe9155a.c922fc"],["9a7a0b1b.f6ef98"]],"info":"1 is Oranje tag (ligt op Piano)"},{"id":"7fe9155a.c922fc","type":"debug","z":"66f8719e.c96e1","name":"nfc2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":543,"y":51,"wires":[]},{"id":"8b97517c.ad9d3","type":"comment","z":"66f8719e.c96e1","name":"NFC Tag test","info":"","x":70,"y":68,"wires":[]},{"id":"a8ad46b9.fe43b8","type":"api-current-state","z":"66f8719e.c96e1","name":"Buitenzitten boolean","server":"783e002.7fe69","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.licht_aan_buitenzitten","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":678,"y":119,"wires":[["45d290ce.8b5ae"],["c80cea4b.1e8838"]]},{"id":"45d290ce.8b5ae","type":"api-call-service","z":"66f8719e.c96e1","name":"buitenzitten false","server":"783e002.7fe69","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.licht_aan_buitenzitten","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":906,"y":85,"wires":[["4e88e85.5637a18"]]},{"id":"c80cea4b.1e8838","type":"api-call-service","z":"66f8719e.c96e1","name":"buitenzitten true","server":"783e002.7fe69","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.licht_aan_buitenzitten","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":896,"y":136,"wires":[["aeb412c6.96f2b"]]},{"id":"56996bb7.381664","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"var tagnr = msg.payload.event.tag_id;\nvar tagdevice = msg.payload.event.device_id;\nmsg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\n' +'TAG nr: ' + tagnr + '\\nTAG device: '+ tagdevice +'\\n Lichtbuiten aan/uit gezet';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":648,"y":170,"wires":[["af075663.762a28"]]},{"id":"af075663.762a28","type":"link out","z":"66f8719e.c96e1","name":"Send telegram test NFC","links":["a6ab7d21.e22a"],"x":763,"y":170,"wires":[]},{"id":"df4bb418.ffc748","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"var tagnr = msg.payload.event.tag_id;\nvar tagdevice = msg.payload.event.device_id;\nmsg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\n' +'TAG nr: ' + tagnr + '\\nTAG device: '+ tagdevice +'\\n Tag zonder functie nr1';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":648,"y":221,"wires":[["5dfbb8ef.58f0c8"]]},{"id":"5dfbb8ef.58f0c8","type":"link out","z":"66f8719e.c96e1","name":"Send telegram test NFC","links":["a6ab7d21.e22a"],"x":763,"y":221,"wires":[]},{"id":"8f6083fd.e5a8e","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"var tagnr = msg.payload.event.tag_id;\nvar tagdevice = msg.payload.event.device_id;\nmsg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\n' +'TAG nr: ' + tagnr + '\\nTAG device: '+ tagdevice +'\\n Tag zonder functie nr 2';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":648,"y":272,"wires":[["a1c8c106.8f9e1"]]},{"id":"a1c8c106.8f9e1","type":"link out","z":"66f8719e.c96e1","name":"Send telegram test NFC","links":["a6ab7d21.e22a"],"x":763,"y":272,"wires":[]},{"id":"9a7a0b1b.f6ef98","type":"api-current-state","z":"66f8719e.c96e1","name":"licht boolean","server":"783e002.7fe69","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.licht_aan_woonkamer_boolean","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":648,"y":357,"wires":[["c853efd5.48c2e"],["88bff5b5.a3b0b8"]]},{"id":"c853efd5.48c2e","type":"api-call-service","z":"66f8719e.c96e1","name":"licht boolean false","server":"783e002.7fe69","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.licht_aan_woonkamer_boolean","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":855,"y":340,"wires":[["4e8be817.6e40b8"]]},{"id":"88bff5b5.a3b0b8","type":"api-call-service","z":"66f8719e.c96e1","name":"licht boolean true","server":"783e002.7fe69","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.licht_aan_woonkamer_boolean","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":855,"y":391,"wires":[["409c6e83.8122c"]]},{"id":"409c6e83.8122c","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"msg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\nTag licht woonkamer aan';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1056,"y":391,"wires":[["8ebc4be0.35b2c8"]]},{"id":"8ebc4be0.35b2c8","type":"link out","z":"66f8719e.c96e1","name":"Send telegram licht kamer NFC","links":["a6ab7d21.e22a"],"x":1171,"y":374,"wires":[]},{"id":"4e8be817.6e40b8","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"\nmsg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\nTag licht woonkamer uit';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1056,"y":340,"wires":[["8ebc4be0.35b2c8"]]},{"id":"17cf4cfb.d6e033","type":"comment","z":"66f8719e.c96e1","name":"Licht buiten aan/ uit","info":"Oranje tag","x":668,"y":85,"wires":[]},{"id":"c85ecaa.6311338","type":"comment","z":"66f8719e.c96e1","name":"Lich kamer aan/ uit","info":"Blauwe tag aan sleutelbos","x":668,"y":323,"wires":[]},{"id":"aeb412c6.96f2b","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"msg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\nTag licht buiten aan';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1107,"y":136,"wires":[["e8712f05.2c8fa"]]},{"id":"e8712f05.2c8fa","type":"link out","z":"66f8719e.c96e1","name":"Send telegram licht buiten NFC","links":["a6ab7d21.e22a"],"x":1222,"y":119,"wires":[]},{"id":"4e88e85.5637a18","type":"function","z":"66f8719e.c96e1","name":"makeMSG","func":"\nmsg.payload = {};\nmsg.payload.chatId = 198675837;\nmsg.payload.type = \"message\";\nmsg.payload.content = 'NFC TAG: \\nTag licht buiten uit';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1107,"y":85,"wires":[["e8712f05.2c8fa"]]},{"id":"783e002.7fe69","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Thnx. That was the info that I needed.

Thnx for all your help.

I just noticed NodeRed now has the Home Assistant Tag:
image
So you don’t need to look for the triggered event anymore.

2 Likes