Get POE State of UniFi Switch Ports

This flow retrieves the POE power state of UniFi Switches. This flow makes use of the node-red-contrib-unifi-os plugin.

Buy Me A Coffee

Flow input variables:

  • deviceId: the ID of the unifi switch
  • port: The port number of the switch you want to manage

Sample KNX Usecase

[{"id":"1cecc162d44ae3da","type":"subflow","name":"Get POE State","info":"","category":"","in":[{"x":200,"y":260,"wires":[{"id":"9669307cf647e436"}]}],"out":[{"x":1020,"y":260,"wires":[{"id":"c386069698bb659d","port":0},{"id":"a03cdb33426f24e0","port":0}]}],"env":[{"name":"device_id","type":"str","value":"","ui":{"label":{"en-US":"Device ID"},"type":"input","opts":{"types":["str"]}}},{"name":"port","type":"num","value":"","ui":{"label":{"en-US":"Port"},"type":"input","opts":{"types":["num"]}}}],"meta":{},"color":"#3FADB5","icon":"node-red-contrib-unifi-os/unifi.png"},{"id":"9669307cf647e436","type":"unifi-request","z":"1cecc162d44ae3da","name":"Get all devices","accessControllerNodeId":"311744fa7b96aaf5","endpoint":"/proxy/network/api/s/default/stat/device","method":"GET","data":"","dataType":"json","responseType":"json","x":340,"y":260,"wires":[["c57231f705929025"]]},{"id":"c57231f705929025","type":"function","z":"1cecc162d44ae3da","name":"Parse port","func":"\nvar poe_port = env.get(\"port\");\nvar device_id = env.get(\"device_id\");\n\nvar poe_mode = \"auto\";\nmsg.payload.data.forEach(device => {\n    if (device._id == device_id) {\n        //get all current overrides\n        device.port_overrides.forEach(port => {\n            if (port.port_idx == poe_port) {\n                if (port.poe_mode == \"off\"){\n                    poe_mode = \"off\";\n                }\n            }\n        });\n    }\n    \n});\n\nmsg.payload = poe_mode;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":260,"wires":[["bfd7cbc4430fbb42"]]},{"id":"bfd7cbc4430fbb42","type":"switch","z":"1cecc162d44ae3da","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"auto","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":260,"wires":[["c386069698bb659d"],["a03cdb33426f24e0"]]},{"id":"c386069698bb659d","type":"function","z":"1cecc162d44ae3da","name":"True","func":"msg.payload = true;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":890,"y":220,"wires":[[]]},{"id":"a03cdb33426f24e0","type":"function","z":"1cecc162d44ae3da","name":"False","func":"msg.payload = false;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":890,"y":280,"wires":[[]]},{"id":"311744fa7b96aaf5","type":"unifi-access-controller","name":"default","controllerIp":"10.0.1.1","controllerPort":"443","controllerType":"UniFiOSConsole","credentials":{}}]

Collection Info

next

Flow Info

Created 2 years, 10 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • function (x3)
  • switch (x1)
Other

Tags

  • unifi
  • poe
  • switch
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option