NFC Tag Action based on user

NFC Tags are a great way to trigger automation. Let’s say you arrive home, swipe your phone on an NFC Tag and some lights turn on and music starts playing. It’s amazing until your significant other says another playlist will be a better option. Or upon arriving some other scene, with different devices ou different setting should start instead.
Home Assistant allows us to get the id of the user (phone) that scanned the NFC tag so we can use that to trigger different actions.

Let’s say we have 2 NFC tags. One in the garage and another in the shared office. When leaving the house, we enter the garage and both use the same NFC tag to open the garage door. It doesn’t really matter who’s using the tag as we both want the same result out of that particular NFC Tag.

Garage Tag flow
tag_id node

Our garage tag is the one with the id ending in 13d5 so when we receive that id in Home Assistant with a ‘tag_scanned’ event it will leave the ‘tag_id’ node in output 2 which leads to a call service node that tells Home Assistant to open the garage door.

While entering the office, however, we both use the same tag but we can id the user and trigger a different set of actions based on it.

If tag_id ending in 43e0 is scanned, the flow will run through output 1 of the tag_id node into another switch node that will check for the user that made the scan.

Node-RED flow:

[{“id”:”856cce8e.29502″,”type”:”tab”,”label”:”NFC”,”disabled”:false,”info”:””},{“id”:”81417a0f.c1eca8″,”type”:”server-events”,”z”:”856cce8e.29502″,”name”:””,”server”:””,”version”:1,”event_type”:”tag_scanned”,”exposeToHomeAssistant”:false,”haConfig”:[{“property”:”name”,”value”:””},{“property”:”icon”,”value”:””}],”waitForRunning”:true,”outputProperties”:[{“property”:”payload”,”propertyType”:”msg”,”value”:””,”valueType”:”eventData”},{“property”:”topic”,”propertyType”:”msg”,”value”:”$outputData(\”eventData\”).event_type”,”valueType”:”jsonata”},{“property”:”event_type”,”propertyType”:”msg”,”value”:”$outputData(\”eventData\”).event_type”,”valueType”:”jsonata”}],”x”:160,”y”:120,”wires”:[[“5d97e256.fc40cc”]]},{“id”:”5d97e256.fc40cc”,”type”:”switch”,”z”:”856cce8e.29502″,”name”:”tag_id”,”property”:”payload.event.tag_id”,”propertyType”:”msg”,”rules”:[{“t”:”eq”,”v”:”94ab8c0f-0b0c-43e0″,”vt”:”str”},{“t”:”eq”,”v”:”969b-36c9fa2113d5″,”vt”:”str”}],”checkall”:”true”,”repair”:false,”outputs”:2,”x”:330,”y”:120,”wires”:[[“9470bdd7.ef287”],[“296f7190.a033de”]]},{“id”:”9470bdd7.ef287″,”type”:”switch”,”z”:”856cce8e.29502″,”name”:”user”,”property”:”payload.context.user_id”,”propertyType”:”msg”,”rules”:[{“t”:”eq”,”v”:”ae0fsdsaf26aca4d”,”vt”:”str”},{“t”:”eq”,”v”:”fasdfdsfafadsadsfa”,”vt”:”str”}],”checkall”:”true”,”repair”:false,”outputs”:2,”x”:470,”y”:120,”wires”:[[“b9521be1.7e6088”],[“805ae37.651822”]]},{“id”:”b9521be1.7e6088″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Turn On John’s Light”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:680,”y”:100,”wires”:[[“4d768992.771978”]]},{“id”:”805ae37.651822″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Turn On Jane’s Light”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:680,”y”:140,”wires”:[[“afb82923.e98ef8”]]},{“id”:”afb82923.e98ef8″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Play TV”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:860,”y”:140,”wires”:[[]]},{“id”:”4d768992.771978″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Play Spotify”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:870,”y”:100,”wires”:[[]]},{“id”:”296f7190.a033de”,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Open Garage Door”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:670,”y”:200,”wires”:[[]]}]

Leave a comment

Your email address will not be published. Required fields are marked *