[PROJECT] Driver for Unifi Network Controllers

update!

APs childs were re-created automatically and they work fine, label is also set right ! Thanks

only thin I see is the presence Label updating from the controller - no really big deal :wink:

Thanks !

Thanks for updating and checking so quick!

As for your questions:
Version shown in the driver Current State (or State Variables) will not update until it does the Daily Check (for updates) or if you Save Preferences (then it writes the version). But like you said, it shows the correct version in the driver code window, so you got it.

Child devices do not rename their label to match what the API provides unless their label field is null (blank). That way people can label them something on their Hubitat and it will not be impacted by what they set on their Unifi controller. This is by design. If you do want to "sync" them up you can:

  1. Delete the label and Save the device info. It should change when it next receives the data.
  2. Set the Device Name in the device's Preferences to match what you labeled it and Save (this should attempt to change it on the controller).

Thanks,
yep, I got that from when I had "Cannot get property 'label' on null object " errors.

Still, my child presence device has an empty label and it does not update from the controler even if I save.

The null errors should have gone away, I added a check to make sure the child exists before attempting to check if there is a label for the child.

Save will not update the label... but it should populate when it gets data from the API that includes the device name.

The other side of this is that the Unifi Controller has to have an actual name for the device. For example, I added my Pixel 8 to the Presence checking and it created it, but did not label it. So the label was blank. It should get the Name, correct? If I go into the Unifi controller and check the client devices I can see that it has a name in the list... but it really does not. If I select it I can see this:
Pixel8inUnifi
The name field is blank on the controller and it is providing it some "generated" name. If I enter something into the Name field and Save it will now have one. So I named it Pixel8.

Went back to my Hubitat and by the time I logged in and opened the devices, the child device's label has been switched to Pixel8.
Pixel8inHubitat

Now, if you have entered something into the Unifi side and saved it and it is not showing up... then I have more work to do because I JUST did this to get the screenshots...

First off, again, thanks for the very clear answer and for your great patience.

So, ok, I id not have a name in the unifi controler for my phone as it was displayed by my host name and model number so I was expecting this name to appear in Hubitat, i did not know I had to set this up.

So, I entered a name for it in my Unifi controller and saved, it did not update in Hubitat on the presence child.
it's presence has been checked a few times since and it does not update still.

now, since this child had been created by a prior version of the driver, I deleted it
--> it was re-created with the right label right away

Thank you very much for all of this and for beeing very quick and pro-active.
Have a great evening!

Yeah, some of these systems (like Unifi's) that make things easy with default values are actually making it more difficult behind the scenes. If they show it as a name, why not just POPULATE the name field?!

It should have gotten the label even after a child was created so that is odd... I will look at that more over the week (lower priority than the stuff not working at all).

Thanks again for bringing stuff up! Better to hear about it and get it fixed.

1 Like

"Thanks again for bringing stuff up! Better to hear about it and get it fixed."
no problem, glad i could help testing stuff

Would you think that it would be possible to add a presence value on the child APs (unifinetworkchild-AP) so we could use presence to know when / which AP is up and get alerted ?

Thanks

The AP child driver actually does have the Presence capability and there is field that used to be reported by the API "isConnected" that set the presence for things like the APs, switches, and such. It no longer appears to be provided though (I do not see it on recent samples).

You could check the LastSeen or Uptime events, but they would require parsing to get something more useful. I was trying to do something in Rule Machine to provide you a method... but hit either something I do not understand or a bug, so I posted about that in the Rule Machine area.

ok,
would be a nice to have but what you did already is very impressive.
Thanks a lot

I will keep the AP presence in mind, if I see a field come in that would be useful with the regular checks.

1 Like

I'm having a similar (likely the same) problem on my setup. The last presence update to any of my child devices was Feb 25, though I can see the Unifi parent doing the presence probes in the logs. I'm on 0.4.77, which it looks like should have the fix (and I did an HPM Repair to make sure everything was updated), but I can't seem to get the Presence children active again.

I've tried removing one of them and it isn't being recreated. I'd rather not be too destructive in my troubleshooting, if I can help it. Am I missing something obvious to check?

The logs for the child device are nearly silent -- on a Refresh command, I see this:

The parent meanwhile sees the Refresh and does a check, but doesn't appear to do anything with the result.

Strange... is there any chance that the MAC address reported by the phone has changed? I know on Android phones they will use a randomized MAC to connect to WiFi (and I think iPhone was going/did something similar). I know I had to stop my phone from doing that on my home WiFi so I could accurately monitor it... although then it should show the presence as "not present" even if it was there...

You can remove the second image since it has your network information... I will shoot you a separate message.

Any chance of getting a UCG Ultra driver or does the UCG Max child work?

It would not automatically recognize the UCG Ultra, because I do not have the model information. It should not need a separate driver though, it looks like I could reuse the Max driver I already have.

If you look at the Generic child device it made for it, can you check what the value is for the Model down in the State Variables list? Once I have that I can add the recognition in. I have an update coming soon anyways for other data changes, plus if there is anything I can figure out for @mbishop.

1 Like

I'll work on this this weekend! Need to set up some firewall rules to allow the communication.

1 Like

First time using this driver, and I am running into command issues with my Pro Max 24 PoE. The cycle PoE power works, but setting the PoE port state does not (no logged errors). I also tried some of the Etherlighting commands such as set brightness or behavior, but they are not working and here is an example error I see in the log:

org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: user_driver_Snell_UnifiNetworkAPI_1277.SetEtherBrightness() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String, java.math.BigDecimal) values: [USPM24P 9c:05:d6:e1:d3:e8, UniFi - Core Switch, 6779895ae9f515532fd718b4, ...] (method SetEtherBrightness)

Also, if you want to add the USW-Aggregation 8 port switch, the model shows as “USL8A”.

I will try to look into the brightness tonight, I was getting ready for an update this evening anyways... From the error I would imagine I made a typo somewhere (maybe the child driver since I did not see it with my 16 port version).

I will see about the Aggregation switch. That will likely need a new child driver but I can probably copy most of it from the Aggregation Pro I already have.

Thanks for the heads up and model info.

Updated Version(s):

  • UnifiNetworkAPI.groovy = 0.4.78
  • UnifiNetworkChild-USPM16.groovy = 0.1.2
  • UnifiNetworkChild-USPM16P.groovy = 0.1.2
  • UnifiNetworkChild-USPM24.groovy = 0.1.4
  • UnifiNetworkChild-USPM24P.groovy = 0.1.4
  • UnifiNetworkChild-USPM48.groovy = 0.1.4
  • UnifiNetworkChild-USAGG.groovy = NEW, added to list in original post

Change(s):

  • Change to how Etherlighting commands are passed for all Pro Max child drivers EXCEPT the 48 PoE (it did not need the changes).
  • Change to how the parent driver submits Etherlighting commands to the API.
  • Recognition of 8 port Aggregation Switch and addition of child driver to support it.
  • Overhaul of how model identification is performed, cleaning up and simplifying the code a lot by removing a lot that was fairly redundant.
  • Handling for change in model information returned by U6-LR Access Points.
  • Change to how Presence and ClientCheck children events and states are handled so they no longer require the "Show Unifi Devices as Children" Preference to be enabled on the parent device.
  • Additional data handling for new data returned by the API.

I'm struggling to get the API to log-in to the controller. I've tried both port 443 and 8443 as this is a UCG Ultra and I'm using other controller type. The hubitat is on a different VLAN but I've confirmed the firewalls are properly configured as I can ping the gateway IP using the ping function in the API. Any ideas?

Edit: Here is the log error.

2025-03-29 11:32:51.465 AM

error

UnifiNetworkAPI - Exception when performing Login: groovyx.net.http.HttpResponseException: status code: 401, reason phrase: Unauthorized

Are you using a local admin and not an account with the MFA?