Skip to content

Instantly share code, notes, and snippets.

@DarrolMusambani
Last active February 2, 2022 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarrolMusambani/36a5892bd915b319df70d63d47689b1f to your computer and use it in GitHub Desktop.
Save DarrolMusambani/36a5892bd915b319df70d63d47689b1f to your computer and use it in GitHub Desktop.
Get Unifi-device information

A convenient Subflow to retrieve device informations from your unifi controller using node-red-contrib-unifi-os nodes with some humble error handling.

[{"id":"149e764ec63edd6f","type":"subflow","name":"Unifi Device Info","info":"Retrieves device informations from Unifi Controler.\nRetries in 1s intervalls if the query fails.\nOutputs an errormessage if the retry count hits an predefined limit.","category":"","in":[{"x":80,"y":60,"wires":[{"id":"c6561bac9cd9ef82"}]}],"out":[{"x":1020,"y":120,"wires":[{"id":"aa50fea590d4500d","port":0}]},{"x":780,"y":20,"wires":[{"id":"46bf4a30b2e63d16","port":0}]}],"env":[{"name":"retryLimit","type":"num","value":"5"}],"meta":{"module":"Unifi Devices","version":"0.1.0","author":"Danny Mrugalla","desc":"Retrieves device informations from Unifi Controler using node-red-contrib-unifi-os nodes","keywords":"Unifi,device, Ubiquity","license":"Apache-2.0"},"color":"#12b5c7","inputLabels":["Trigger"],"outputLabels":["Data",""],"icon":"node-red-contrib-unifi-os/unifi.png","status":{"x":1140,"y":80,"wires":[{"id":"46bf4a30b2e63d16","port":0},{"id":"9c54d909a99f5ca0","port":0},{"id":"a662128d4c10aa21","port":0}]}},{"id":"e032e78404a934fc","type":"template","z":"149e764ec63edd6f","name":"API-request template","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n \"endpoint\":\"/proxy/network/api/s/default/stat/device\",\n \"method\":\"GET\",\n \"data\":{}\n}","output":"json","x":160,"y":120,"wires":[["14aa66a43ffce3b8"]]},{"id":"32471b228740ba6d","type":"unifi-request","z":"149e764ec63edd6f","name":"","accessControllerNodeId":"6ae61b61eee138ac","endpoint":"","method":"GET","data":"","responseType":"json","x":410,"y":200,"wires":[["7b89cfe8c7e143dc"]]},{"id":"aa50fea590d4500d","type":"change","z":"149e764ec63edd6f","name":"Format Output","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":140,"wires":[[]]},{"id":"7b89cfe8c7e143dc","type":"switch","z":"149e764ec63edd6f","name":"Check Response","property":"payload.meta.rc","propertyType":"msg","rules":[{"t":"eq","v":"ok","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":200,"wires":[["aa50fea590d4500d","9c54d909a99f5ca0"],["78f19122a95d5633","a662128d4c10aa21"]],"outputLabels":["OK","Error"]},{"id":"2f38d891a781b739","type":"delay","z":"149e764ec63edd6f","name":"Retry 1s","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":120,"y":280,"wires":[["979c427781583430"]]},{"id":"c6561bac9cd9ef82","type":"change","z":"149e764ec63edd6f","name":"Set actual retry count","rules":[{"t":"set","p":"retryCount","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":60,"wires":[["e032e78404a934fc"]]},{"id":"979c427781583430","type":"function","z":"149e764ec63edd6f","name":"Increase Retry Count","func":"flow.retryCount = flow.retryCount + 1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":200,"wires":[["e032e78404a934fc"]]},{"id":"14aa66a43ffce3b8","type":"switch","z":"149e764ec63edd6f","name":"Check Retry Limit","property":"retryCount","propertyType":"flow","rules":[{"t":"gt","v":"retryLimit","vt":"env"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":390,"y":120,"wires":[["46bf4a30b2e63d16"],["32471b228740ba6d"]]},{"id":"78f19122a95d5633","type":"change","z":"149e764ec63edd6f","name":"","rules":[{"t":"set","p":"lastError","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":280,"wires":[["2f38d891a781b739"]]},{"id":"46bf4a30b2e63d16","type":"change","z":"149e764ec63edd6f","name":"Error Message","rules":[{"t":"set","p":"payload","pt":"msg","to":"lastError","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":80,"wires":[[]]},{"id":"9c54d909a99f5ca0","type":"change","z":"149e764ec63edd6f","name":"Status OK","rules":[{"t":"set","p":"payload","pt":"msg","to":"OK","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":100,"wires":[[]]},{"id":"a662128d4c10aa21","type":"change","z":"149e764ec63edd6f","name":"Status Error","rules":[{"t":"set","p":"payload","pt":"msg","to":"Error --> Retry","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":240,"wires":[[]]},{"id":"6ae61b61eee138ac","type":"unifi-access-controller","z":"149e764ec63edd6f","name":"Dummy","controllerIp":"127.0.0.1"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment