NFC, NodeRed e identificação de utilizador

image

Este artigo junta dois temas diferentes: Automações com base em tags NFC e a possibilidade de ter automações diferentes consoante o utilizador

Em primeiro lugar é preciso configurar as tags na aplicação do Home Assistant:

Quando abrem o menu NFC Tags têm duas opções: Ler e Escrever

Se a tag estiver virgem, vão ter de gravar primeiro. Carregam em “Escrever a TAG NFC” e colocam o telemóvel em cima da tag.

Assim que estiver gravado podem ler a informação.


No NodeRed temos de apanhar o evento do tipo

image

e depois colocar um debug node para identificar a path e o user_id

No debug do Node Red podem ver a informação completa

image

Na imagem acima conseguem ver o tag_id e o user_id

Depois basta usar numa automação do género:

O node tag_id vai identificar a tag e no caso de ser a primeira, vai identificar o utilizador e seguir a respectiva automação
Se for o segundo tag_id, não interessa o utilizador e vai abrir o portão da garagem.

O flow é dummy mas vou deixar no final para poderem ver a configuração dos nodes.

node tag_id:
image

node utilizador:
image

[{"id":"856cce8e.29502","type":"tab","label":"NFC","disabled":false,"info":""},{"id":"81417a0f.c1eca8","type":"server-events","z":"856cce8e.29502","name":"","server":"2998c139.aa476e","event_type":"tag_scanned","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":290,"y":200,"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":470,"y":200,"wires":[["9470bdd7.ef287"],["296f7190.a033de"]]},{"id":"9470bdd7.ef287","type":"switch","z":"856cce8e.29502","name":"Utilizador","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":480,"y":120,"wires":[["b9521be1.7e6088"],["805ae37.651822"]]},{"id":"b9521be1.7e6088","type":"api-call-service","z":"856cce8e.29502","name":"Ligar Luz João","server":"2998c139.aa476e","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":660,"y":100,"wires":[["4d768992.771978"]]},{"id":"805ae37.651822","type":"api-call-service","z":"856cce8e.29502","name":"Ligar Luz Joana","server":"2998c139.aa476e","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":660,"y":140,"wires":[["afb82923.e98ef8"]]},{"id":"afb82923.e98ef8","type":"api-call-service","z":"856cce8e.29502","name":"Radio Comercial","server":"2998c139.aa476e","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":140,"wires":[[]]},{"id":"4d768992.771978","type":"api-call-service","z":"856cce8e.29502","name":"RFM","server":"2998c139.aa476e","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":100,"wires":[[]]},{"id":"296f7190.a033de","type":"api-call-service","z":"856cce8e.29502","name":"Abrir Portão da Garagem","server":"2998c139.aa476e","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":690,"y":200,"wires":[[]]},{"id":"2998c139.aa476e","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
6 Curtiram

Copyright © 2017-2021. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade