[PROJECT] Driver for Unifi Network Controllers

I assume this is a typo or some strange character embedded but the LED on and off buttons on the access points have a space in them:

Thanks for making this integration - now that I am in I am enjoying having this access on my Hubitat.

Updated Version(s):

  • UnifiNetworkAPI.groovy = 0.4.74
  • UnifiNetworkChild-USW8PoE.groovy = 0.1.9

Change(s):

  • Added recognition for the Unifi Flex 2.5G PoE 8 Port Switch. It can use the existing USW8PoE child driver.
  • Changes to the USW8PoE child driver for newer Tile attribute handling (to better deal with Hubitat code changes). These changes will eventually get passed on to all my child drivers... but there are so many that I only plan to do it as I touch on them for other changes or checks.
  • Added some additional data point handling.

Note(s):

  • As pointed out by @simon4, you may see some oddities with the naming of things. This is actually an effect of the new UI style and how it treats capitalized commands (and Current States/State Variables also have changes). I have put it in as something needing correction on Hubitat's side (a bit more checking for whether it is an acronym or not, by whether the capital letter has lowecase following it or not). Nothing I can do about it from the driver perspective. I realized that I replied about this in a message, but forgot to post it here. So I did not ignore the feedback or anything.

@snell I just setup a new 48 port switch and I want to change the name attribute of each port to identify what is plugged into it. Does the API expose a way to update this attribute? I am hoping to bulk update them from a spreadsheet or NodeRed.

Just out of curiosity - what can you do with this if it were working?

I have a UDM Pro and have a couple of ubiquiti small switches but my two many switches are not ubiquiti.

So I am interested in what I could do if I switch to Ubiquiti switches.

@ritchierich: I had not looked at this before... but a quick check shows the API DOES allow changing the port name as part of the port overrides (the same way PoE state or such is changed) and it is a simple value. It is even returned in the data (if set), so I can add something based on this. However, a bulk update is a bit more... unusual... We would need to talk a bit in messages to determine the best way to handle such a thing, due to the limits on the number of characters you can submit in a command field.

@simon4: A lot of it depends on how you want to use it. Originally there was the variety of data that you may want to know about for general dashboard knowledge. Since that time though I have added more capabilities. A few of the general examples are:

  1. Knowing the presence of networked devices. You get home, it can recognize your phone reconnecting to they network. Or when it has left the network. Not geo-located.
  2. Control of Unifi-based outlets, like their single plug, 6 outlet (and USB) power strip, or their larger rack-mount devices via Hubitat.
  3. Ability to regularly check on the state of network devices. Have something that might lose it's connection? Set a check for it and POPO the outlet it is on (requested feature).
  4. Block/unblock particular MAC addresses. Kids spending too much time on the phone? Block after certain hours or on command (requested feature).
  5. Control PoE ports on the switch(es) for sensor or other devices that are drawing power from them.
  6. Turn on/off and change the color of an Access Point's LED ring to help notify of statuses the Hubitat knows of.

Those are some of the examples I use or were requested. Of course some people use the data from it within Rule Machine to do more. I am also open to requested features (such as the "coming soon" port naming).

I also have made separate driver sets for the Unifi Protect and Unifi Connect APIs to take advantage of things they can do.

2 Likes

I don’t need a bulk command if there could be a way to update it via command I can bulk do it via NodeRed via MakerAPI.

I was thinking I could just make it a command, select port number and enter name. Done. HOPEFULLY it will be that easy once I get to coding it later this weekend.

EDIT:
Yeah... not so easy it seems. Nevermind that it will require updating many child device drivers... But, working on it.

1 Like

Thanks - the only thing I have been doing so far is turning off the leds on the access points at night. The brightness and color don't seem to work for me.

Which model of AP(s) do you have? There are a few possibilities:

  1. The model itself is unable to set color or brightness and I mistakenly identified it with those that can.
  2. There was a period of time where Ubiquiti made ones that had more limited LED capabilities than others of the same model due to supply chain issues. An example of this is the U6-LR. I have two of those that have full color control, but if you look at the tech specs now it says they are white/blue LEDs.
  3. The model requires some different coding to change the LED and/or brightness. If you CAN change them within the Unifi app or on the Unifi controller's Network app, then likely I need to make a change to the code to handle whatever the difference is.

I have a U6-LR and a U6+. The app only allows LED on and off. So I am assuming I have the versions that don't offer color control.

Hmm... Using the U6-LR as an example... Just looking at mine for comparison, can you check a couple things in the State Variables?

  1. Confirm it has the Model "UALR6v2"
  2. What is the Board Revision it has?

Trying to figure out if there is some differentiator to be able to identify them and assign them the "Basic AP" driver that does not have the LED control...

EDIT:
They should have some way to identify them in the API... because the Unifi Network app (on the controller and on my phone) allows me to set the color and such for mine. Just need to find it I guess.

During Covid and the microchip shortage they stopped including the color LED in their APs. I have a few older U6LRs that I can change but a U6 Pro I purchased during the shortage only has blue.

I had 3 8 Port Netgear switches in my structured wiring panel that I replaced with a UniFi 48 port switch. I have a few vlans setup and I wanted to easily change which was assigned to a given port. I am also ditching Rig cameras and replacing with UniFi Protect so I needed more PoE power.

1 Like

Updated Version(s):
ALL DRIVERS UPDATED - Parent and ALL Children

Change(s):

  • All drivers were changed for updated state and event handling to match my newer coding.
  • All child drivers were updated to use a newer Tile method that seems to work better with changes to Hubitat's underlying code.
  • The ability to change port names should have been added to every child driver that handles multiple switch ports.
  • Port name change handling added to the parent driver.

Note(s):

  • Due to the fact that every driver was updated, I am not going to list their new versions for every single one like I normally would for smaller groups.
1 Like

Hi Snell,
first, i want to thank you very much for these drivers i really appreciate it.

is there some sort of documentation somewhere that i can read, specifically for presence check.
I can't figure out how to have Hubitat check my phone MAC, if i do a manual check, it works and says that the MAC is present but if I put the MAC in the [ MAC Address(s) to Presence Check] field, it gives me errors in the logs like this:
"java.lang.NullPointerException: Cannot get property 'label' on null object on line 2012 (method ReceiveData)"

I tried creating a child manually from scrach using the presence driver and no luck, can't find where to enter a MAC or something.

now, a child was automatically created at some point "Client check" and this one has a field named [ Client MAC Address(s) to Check] but it does not ssy "presence", I tried adding my phone MAC there, still no luck

Where could i find the info / help for that please ?
Thanks !

EDIT:
At first I thought this might be a case of the Presence Child not being added, but I found a bug in my code that was not adding child devices properly. Sorry about that. Publishing a corrected version ASAP. I think you were doing it properly, but the bug was causing it to not add the child device, so the label could not be checked because the child did not exist, etc...

You never need to manually add a child device for any of my projects, all children are automatically created (and can be removed whenever you want, they will be automatically recreated if needed).

Updated Version(s):

  • UnifiNetworkAPI.groovy = 0.4.76

Change(s):

  • Fixed a bug that was preventing child devices from being added properly. Thanks to @robertsimard for bringing up the question that led to me discovering the bug.
2 Likes

wow!
That was fast, you rock !
Thanks, i'll try it today and see what happens !

ok,
it does create a child named "presence[MAC], but does not work
the child does not act like a presence device( I can't choose "presence" for Hubitat status) and status does not show a "presence" attribute.
if I refresh it , it "seems" to do something but no results, also "Label" does not get updated to the Unifi client name.

States shows this:

Current States

|Driver Name|UnifiNetworkChild-Presence|
|Driver Status|Up to date|
|Driver Version|0.1.11|

State Variables

|Driver Name|UnifiNetworkChild-Presence|
|Driver Status|null|
|Driver Version|0.1.11|

if it helps, here is the trace log for a refresh:

Presence [My Phone MAC] - Updated
Presence [My Phone MAC] - State: DriverStatus = null
Presence [My Phone MAC] - Event: DriverStatus = null Unit = null Forced = false
Presence [My Phone MAC] - State: DriverVersion = 0.1.11
Presence [My Phone MAC] - Event: DriverVersion = 0.1.11 Unit = null Forced = false
Presence [My Phone MAC] - State: DriverName = UnifiNetworkChild-Presence
Presence [My Phone MAC] - Event: DriverName = UnifiNetworkChild-Presence Unit = null Forced = false

I tried again manual "presence check" with my phone MAC works instatly in the Main App

other info: I am using a CloudKey Gen2 PLus and it conects perfectly using "Unifi Dream Machine (inc. PRO)" as connection type, admin pages shows that the local hubitat user is connected, no errors in logs, I tried "Other Unifi controllers" and that does not work.

Child devices were created for all my APs but for them also it doe not work for presence if I refresh, Last seen attrubute all show "unknown"

hope it is enough info

Thanks !

1 Like

Updated Version(s):

  • UnifiNetworkAPI.groovy = 0.4.77

Change(s):

  • Fix for child devices not receiving state/event information. I apologize for this one folks, plus I am not sure how I missed it these last X days. Basically what happened is that when I was copying the code between multiple drivers (trying to make sure they were more consistent) I did not realize that I had named the Child Device Enablement preference something different from where I was copying it from. So every time it tried to send to a child device, it was determining that they were not enabled and skipped it. I deleted my Presence devices, watched them recreate, made sure they got presence data AND showed it, and then checked on other devices (switches and an AP) to make sure their data was changing properly.
1 Like

Again, you are very quick!
Thanks, I will try this version

ok, tested it:

Main app still shows 0.4.76 but that is no big deal, driver code shows 0.4.77
The child was recreated and it works when I refresh it, shows present and i can set the Hubitat Status to "presence" - good !

just so you know:

  • The label is not updated on the presence child device but "Last Seen" is updated regularly.
  • the APs childs still do not work : No MAC known for AP [MAC Address], cannot refresh.
    I will delete them and see tomorrow morning if they are recreated differently.

Thanks !