|
[{"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"]]}] |
Hey @groenerik, I had the same problem after upgrading to NR v3. I'm not sure if the Unifi output has changed or if NR is now processing things differently/more strictly.
For example, the change from new Date() to Date.now() was noted as a known bug in the TypeScript parser: https://discourse.nodered.org/t/why-does-new-date-show-as-an-error/88776
But I can say that your fixes do work. Well done and thank you for sharing.