# Using node-red-contrib-unifi with a UniFi WiFi Network

**URL:** <https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246>\
**Category:** General\
**Tags:** unifi\
**Created:** [27 January 2023 06:42 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246 "2023-01-27T06:42:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianh33](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ianh33](https://discourse.nodered.org/u/ianh33)\
**Post date:** [27 January 2023 06:42 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/1 "2023-01-27T06:42:19Z")

</div>

I am trying to address the age old problem of which phones are attached to my network (i.e. are we in?).

I have 5 meshed UniFi APs which I have set up and control via the UniFi Network application. I do not have a UniFi hardware controller.

Am I right to assume I can't use node-red-contrib-unifi? Are there any UniFi alternatives to fetch 'attached clients' data from my APs ?

Thank you

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [27 January 2023 12:40 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/2 "2023-01-27T12:40:58Z")

</div>

I don't use unifi but looking at the node I would say not, as its designed to talk to the controller API.

Without that each AP would need to be queried separately. I don't know if there is an API available on the AP itself ? You may be able to get information from the AP web interface.

To solve this issue myself I run my DHCP server on the Rpi that has node-red, then I get an MQTT message each time a device renews its lease.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 January 2023 13:19 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/3 "2023-01-27T13:19:36Z")

</div>

> [@ianh33](#):
>
> Am I right to assume I can't use node-red-contrib-unifi? Are there any UniFi alternatives to fetch 'attached clients' data from my AP

Can't remember if you can do that from the unifi node. If not, you might be able to use the SNMP node. But I have to say that it is an unreliable measure anyway since battery powered Wi-Fi devices will generally spend as much time as possible disconnected.

> [@Sean-McG](#):
>
> To solve this issue myself I run my DHCP server on the Rpi that has node-red, then I get an MQTT message each time a device renews its lease.

Which tells you something every NN hours - or even weeks, depending on how you've set up DHCP 🙂

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [27 January 2023 13:33 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/4 "2023-01-27T13:33:56Z")

</div>

Actually every 5 mins 🙃

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 January 2023 13:35 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/5 "2023-01-27T13:35:58Z")

</div>

Wow, that's quite a load on both the devices and the DHCP server. It can cause issues with devices disconnecting as well as they poll for a new address.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [27 January 2023 13:46 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/6 "2023-01-27T13:46:31Z")

</div>

There aren't that many devices using DHCP as most of the things on the network have static IPs.

I also combine this with a door contact on the front door. That way if a phone is at home but "sleeping" I don't consider the person not at home unless the door has also been opened within last 10mins.

I have found this to work very well. There has to be a slight delay to consider someone not at home, but anyone arriving is usually logged as in by the time they get to the front door.

Obviously it has it limitations - eg if someone leaves their phone at home.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 January 2023 13:56 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/7 "2023-01-27T13:56:22Z")

</div>

> [@Sean-McG](#):
>
> Obviously it has it limitations

I gave up on trying to automate presence years ago. I just set in/out manually 😁

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [27 January 2023 14:00 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/8 "2023-01-27T14:00:35Z")

</div>

I work up in the attic so its handy to see who is in the house.

Also my daughter has a habit of leaving everything in her room switched on when she goes out.  
In her case I also check last motion detected in her room (so as not to plunge her into darkness 😉 )  
I reckon the chances of her leaving without her phone are about the same as being hit by a meteor and lighting at the same time 😂

Then I store the state of the lights etc and turn them off when she leaves, and then restore them when she gets home, and she is none the wiser 🤣

---

<div class="post-metadata">

**Author:** ![ianh33](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ianh33](https://discourse.nodered.org/u/ianh33)\
**Post date:** [27 January 2023 14:07 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/9 "2023-01-27T14:07:16Z")

</div>

Smcgann Hmmm I suspect you are right. It's a shame because the "UniFi network application" obviously collects the information as it displays / interacts via a web page.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 January 2023 14:19 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/10 "2023-01-27T14:19:58Z")

</div>

I can tell if I'm home by pinging my phone's (reserved) IP address with node-red-node-ping

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96887ad5c718be8e810b52ac0bb7169838c4b161.jpeg)

```auto
[{"id":"65e0a49e109e70a6","type":"ping","z":"5de4802425738256","protocol":"IPv4","mode":"triggered","name":"Ping ","host":"192.168.1.51, 192.168.1.52","timer":"20","inputs":1,"x":410,"y":120,"wires":[["3c35d8f7b54dc61d"]]},{"id":"3c35d8f7b54dc61d","type":"switch","z":"5de4802425738256","name":"online?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":560,"y":120,"wires":[["86b6ba68e32bf4d1"],["1af3826e1a9f7e88"]]},{"id":"86b6ba68e32bf4d1","type":"change","z":"5de4802425738256","name":"ONLINE","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic & \" is online\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":100,"wires":[["3d6790d4d4e2d3b3"]]},{"id":"3d6790d4d4e2d3b3","type":"debug","z":"5de4802425738256","name":"Who's home?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":120,"wires":[]},{"id":"79c181405c6a63c2","type":"inject","z":"5de4802425738256","name":"GO","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":120,"wires":[["65e0a49e109e70a6"]]},{"id":"1af3826e1a9f7e88","type":"change","z":"5de4802425738256","name":"OFFLINE","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic & \" is offline\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":140,"wires":[["3d6790d4d4e2d3b3"]]}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 14:31 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/11 "2023-01-27T14:31:24Z")

</div>

> [@ianh33](#):
>
> Am I right to assume I can't use node-red-contrib-unifi? Are there any UniFi alternatives to fetch 'attached clients' data from my APs ?

Did you try it ?

I don't have a hardware controller, but have a container running somewhere that i can access with this node.

---

<div class="post-metadata">

**Author:** ![ianh33](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ianh33](https://discourse.nodered.org/u/ianh33)\
**Post date:** [27 January 2023 14:31 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/12 "2023-01-27T14:31:27Z")

</div>

Looks like this (node-red-contrib-unifi-os) might do the job although I'm not 100% clear on the cofiguartion options.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [27 January 2023 14:49 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/13 "2023-01-27T14:49:24Z")

</div>

> [@ianh33](#):
>
> node-red-contrib-unifi-os

I am a contributor, but only work on the Protect Side of the module

let me call in the main author: @crxporter

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [27 January 2023 14:55 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/14 "2023-01-27T14:55:28Z")

</div>

Since I've been called...

If you are running either software or hardware UniFi controller - yes this is possible. The controller runs on UniFi hardware as "UniFi OS" or as a software controller on just about any hardware (raspberry pi or docker are popular of course)

I'll be happy to help you set it up, it'll be similar to how @bakman2 runs the node. I'm busy for the next ~4 hours but could help assist afterwords.

---

<div class="post-metadata">

**Author:** ![ianh33](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ianh33](https://discourse.nodered.org/u/ianh33)\
**Post date:** [27 January 2023 15:43 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/15 "2023-01-27T15:43:00Z")

</div>

Great..... Thanks everyone. So I run node-red on a mac mini (Monterey). I have the "Unifi Network Application running on the same mac.

I can see how (I think) I cab set up the Controller.....IP: localhost, port:8443 Type: UNiFi network application with username and password the same as I would use to access the application webpage.

Which node would I use to find out if a client was atatched to an AP e.g. 192.168.1.5 ? and in this context what is an 'endpoint'

Thank you  
Ian

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [27 January 2023 15:49 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/16 "2023-01-27T15:49:54Z")

</div>

That's correct, you will set it to `Network Application` (not `Unifi OS`)

'endpoint' - The various API addresses

Using the request node - the following endpoint will `GET` you, all active clients (i think) - again im on the Protect Side of the module

```auto
/proxy/network/api/s/default/stat/sta/

```

See here:  
[products:software:unifi-controller:api [Ubiquiti Community Wiki] (ubntwiki.com)](https://ubntwiki.com/products/software/UniFi-controller/api)

---

<div class="post-metadata">

**Author:** ![ianh33](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ianh33](https://discourse.nodered.org/u/ianh33)\
**Post date:** [27 January 2023 16:49 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/17 "2023-01-27T16:49:47Z")

</div>

Thank you

I'm using [https://localhost](https://localhost) and 8443 with usual user and password but the just node says "initialiizing'. I can use the same information to log on locally with a browser.

Regards  
Ian

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [27 January 2023 17:06 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/18 "2023-01-27T17:06:41Z")

</div>

Just the ip (127.0.0.1) or localhost - yo don’t need https:// (I think)

---

<div class="post-metadata">

**Author:** ![ianh33](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ianh33](https://discourse.nodered.org/u/ianh33)\
**Post date:** [27 January 2023 17:15 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/19 "2023-01-27T17:15:56Z")

</div>

both give "TypeError: Invalid URL"

---

<div class="post-metadata">

**Author:** ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)\
**Post date:** [27 January 2023 17:46 UTC](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246/20 "2023-01-27T17:46:35Z")

</div>

Let's see. I'll review how the connection should look then ask a couple of questions about your setup...

I would expect the controller setup to look like this (but with your user/password):

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/065015876f419fc59258603a5c1ce9a12a95571d.png)  
Note that you should use _local credentials_ on the controller, not your typical UniFi email/password login. The 2 factor authentication does not work here.

Then put a request node in that looks like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7cfb96e2eb45a0d0bf87c77efc82b9fc52c2184.png)  
That endpoint is `/proxy/network/api/s/default/stat/health` so you don't have to manually type if you don't want.

Do that and then set up an inject and debug node like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc7867162a6935663871999d9f0de4b3a44701ea.png)

Hit the inject and _hopefully_ you get some output. Note I think there is a timer after deploy before it will login, maybe 15 or 30 seconds.

**Things to try**  
Test the controller on port `8443` and `443`  
Restart nodered (not just redeploy) after you make config changes just to verify that any old settings are cleared  
Like I said above, make sure you are using local credentials on the controller

I'll be around for a while now - hopefully this gets you somewhere! Once you're logged in, I'll be happy to share my flow for watching "which MAC addresses are connected to wifi" (if you want it)

[Next page](https://discourse.nodered.org/t/using-node-red-contrib-unifi-with-a-unifi-wifi-network/74246.md?page=2)
