|
[{"id":"a79a3412.95bbc8","type":"comment","z":"198805b3.d752aa","name":"Presence","info":"","x":100,"y":1420,"wires":[]},{"id":"356d290f.2adc76","type":"inject","z":"198805b3.d752aa","name":"Every 5 seconds","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"x":130,"y":1460,"wires":[["2fe17f39.cb2e2"]]},{"id":"2fe17f39.cb2e2","type":"Unifi","z":"198805b3.d752aa","name":"","ip":"","port":8443,"site":"default","command":"20","x":310,"y":1460,"wires":[["9c4ebd18.14827"]]},{"id":"9c4ebd18.14827","type":"function","z":"198805b3.d752aa","name":"Determine device presence","func":"const lastSeenSeconds = 20;\nlet presenceCutoff = (Math.abs(new Date()) - (lastSeenSeconds * 1000)) / 1000; \nconst people = {\n \"presence/person1\": \"Identifier1\",\n \"presence/person2\": \"Identifier2\"\n};\n\nreturn Object.keys(people).map(function(topic) {\n let devices = msg.payload.filter(device => device.name === people[topic] && device.last_seen > presenceCutoff);\n return {\n topic: topic,\n retain: true,\n payload: devices.length > 0\n };\n});","outputs":"2","noerr":0,"x":520,"y":1460,"wires":[["1d706e57.f39ea2"],["84981.f0fe567f"]],"outputLabels":["michael presence","meredith presence"]},{"id":"1d706e57.f39ea2","type":"rbe","z":"198805b3.d752aa","name":"","func":"rbe","gap":"","start":"","inout":"out","x":750,"y":1440,"wires":[["e52f02f3.7cd59"]]},{"id":"84981.f0fe567f","type":"rbe","z":"198805b3.d752aa","name":"","func":"rbe","gap":"","start":"","inout":"out","x":750,"y":1480,"wires":[["e52f02f3.7cd59"]]}] |
Whether that works or not depends on your setup if the hostname property is sticky and properly unique. The
name
property uses the name assigned in the Ubiquiti UI to the device, which will track the MAC address I believe, and would be a much safer bet. Alternatively, you could base it on the MAC address directly if you wanted, but it would just be harder to tell at a glance what device you are looking at. I prefer to just name everything in the Ubiauiti UI and get the benefit of knowing what device is which there as well.