Presence checks based on Unifi & Wifi connection

This flow will Query your unifi wifi controller for all currently connected clients and check for a definied MAC address to be:

  • Connected
  • Non-wired (Unifi leaves a client in wired state some time after it has left the network)

Based on the results it will save global values to be used in other flows.

This flow is dependant on an always on Unifi controller and the Unifi Node. optionally a Domoticz instance for pushing precense to it.

[{"id":"558eca41.b32bb4","type":"inject","z":"29a3949.adffc6c","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"60","crontab":"","once":true,"onceDelay":"","x":90,"y":640,"wires":[["11c68ce3.47f3b3"]]},{"id":"b85d423e.d6e1e","type":"http request","z":"29a3949.adffc6c","name":"","method":"GET","ret":"txt","url":"localhost:8080/json.htm?type=command&param=udevice&idx=[YOUR_IDX_HERE]&nvalue={{{nvalue}}}&svalue={{{message}}}","tls":"","x":730,"y":620,"wires":[["e6ef0710.286cf8"]]},{"id":"e6ef0710.286cf8","type":"debug","z":"29a3949.adffc6c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":640,"wires":[]},{"id":"11c68ce3.47f3b3","type":"Unifi","z":"29a3949.adffc6c","name":"Unifi","ip":"[IP-OF-YOUR_UNIFI-CONTROLLER]","port":8443,"site":"w47znjfb","command":"20","x":210,"y":640,"wires":[["c2f30e56.53e1c","f2ee4f97.9df5b"]]},{"id":"c2f30e56.53e1c","type":"function","z":"29a3949.adffc6c","name":"Phone1 Checks","func":"var devices = msg.payload[0];\n\nfor(var i = 0; i < devices.length; i++) {\n   if(devices[i].mac === '[YOUR_PHONE_MAC-ADDRESS_HERE]' && devices[i].is_wired === false) { //PHONE1 MAC\n     msg.place = i ;\n     msg.message = 'Phone1 Present';\n     // msg.deviceInfo = devices[i] ;\n     msg.payload = 1 ;\n     msg.nvalue = 1 ;\n     global.set('Phone1Status',1); // Setting 1 = Home\n     node.status({fill:\"green\",shape:\"dot\",text:\"Home\"});\n     return msg ;\n   }\n    \n}\n\n    msg.payload = 2 ;\n    msg.message = \"Phone1 Away\" ;\n    msg.nvalue = 2 ;\n    global.set('Phone1Status',0); // Setting 0 != Home\n    node.status({fill:\"yellow\",shape:\"dot\",text:\"Away\"});\n// msg.payload = i ;\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":620,"wires":[["eb99877e.799f58"]]},{"id":"47d8e773.7d3378","type":"comment","z":"29a3949.adffc6c","name":"Presence Check","info":"Works only if Mobile Phones are connected to WiFi","x":470,"y":580,"wires":[]},{"id":"eb99877e.799f58","type":"rbe","z":"29a3949.adffc6c","name":"","func":"rbe","gap":"1","start":"","inout":"in","property":"payload","x":570,"y":620,"wires":[["b85d423e.d6e1e"]]}]

Flow Info

Created 7 years, 1 month ago
Updated 6 years, 6 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • function (x1)
  • http request (x1)
  • inject (x1)
  • rbe (x1)
Other

Tags

  • presence
  • UniFi
  • Uqiquiti
  • Domoticz
  • Homeautomation
  • MAC
  • Wifi
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option