[PROJECT] Driver for Unifi Network Controllers

AWESOME! I refreshed the parent device (not the switch) and the Port Overrides state variable captured everything. Upon pushing a Port State command, everything we discussed before is retained. Thank you so much for the quick turn around! This retains everything that I need to implement my Switch & AP power down automations.

One thing I didn't catch before that is not being retained is the port Profile (e.g. All/Disabled and VLAN setting.) It looks like you're capturing the current port Profiles in your Port Overrides state variable as portconf_id, but that Profile setting is not being reapplied with the rest of the port settings.

For anyone trying to automate Port States (e.g. turn off PoE to an AP or Switch) using Rule Engine (5.1), you can do this as follows:

  1. Create your new Rule and Trigger Event
  2. When creating the Action Type, choose "Set Variable, Mode or File, Run Custom Action"
    3a. Select capability of action device = Actuator
    3b. Select Actuators to Act on = choose your switch child device that is leveraging one of snell's PoE drivers
    3c. Select custom command = SetPortState and add two parameters in this order:
    3d. Add a parameter: parameter type = number, integer value = your_port_number > click "done with parameter"
    3e. Add another parameter: parameter type = string, integer value = auto to turn PoE on or off to turn PoE off for the port (note that no parentheses are needed as Hubitat will enter them for the string) > click "done with parameter"
  3. Click "Done editing action" and continue with your rule definition.

2 Likes

Darn. I will get that in tonight. Sorry.

EDIT:
Updated Version(s):

  • UnifiNetworkAPI.groovy = 0.4.19

Change(s):

  • Port Profile (portconf_id) is now included in the data that should be retained across port overrides.
1 Like

Works great! Port Profiles survive the Port State change. Thank you!

Glad to hear it worked on yours as well. It worked on mine so I figured it would... but further confirmation never hurts. Sorry for all the trouble with the port overrides to begin with.

Absolutely no need to be sorry. It's awesome that you have shared your time and creation with the community! I'm now saving several kWh of unneeded power by shutting down 2 APs and 2 switches every night during sleeping hours. All with the help of your driver. Thanks again!

1 Like

Are you using PoE powered switches like the Flex? Or are you using the Ubiquiti Plug or Power Strip?

I find those two to be a pretty amazing deal for how reliable they have been. Especially the strip. Control over 6 outlets individually plus a 7th for the USB-C ports? For <$50?! Yes please. Very reasonable especially considering how expensive most Ubiquiti stuff is (never mind the scalper horde)...

1 Like

I have a US-8 switch on my 2nd floor that is powered by PoE from my 24 port switch and also passes PoE out to an AP. So by killing the PoE to that port on the 24 port switch, I power down both the US-8 switch and an AP. Then, for the other AP, I use a Kasa KP115 (~$24) with a PoE injector.

I use your driver to power down the Unifi PoE port and the Kasa controller by djgutheinz to power down the 2nd AP, resulting in 2 APs and 1 switch going off (and back on in the morning.)

All of it works flawlessly! (Unrelated, but I also have a few Kasa HS300 power strips (also ~$50) that djgutheinz's app also controls perfectly.)

The reason I like the Kasa's is because they're also power monitors so they work with my Sense energy monitor AND I can pump that power data from Hubitat into InfluxDB and monitor my power usage over time with Grafana.

You can see in this picture that between about midnight and 7:30am, I power down several unneeded items with Hubitat, the Kasa driver, and your driver.

2 Likes

That is awesome! Thanks for sharing the information. I know many times people wonder "what can I use these drivers for..." and you just gave some pretty interesting AND easy to setup uses.

To be honest I never really gave much thought about my stuff like that... but I could certainly power down an AP or two at night as well. Some of my devices might get a much poorer connection but it is not like any of the ones that NEED a good connection would be operating at that time anyways. Something to give some more thought and planning to.

Thanks again!

2 Likes

Updated Version(s):

  • UnifiNetworkChild-Plug.groovy = 0.1.4

Change(s):

  • Somehow the Plug child was missing on/off commands. Not sure if I somehow accidentally deleted those at some point or some other mistake. This is now corrected.

Im struggling to even get a login to work...

I'm certain the Controller IP/Username/Password is correct, but it doesn't work. I even tried creating a local Admin account just for Hubitat but no joy.

The logs show an exception when performing login, with connection timed out

What am I missing?

Do you have the Unifi site in the preferences? It is usually "default" but if you have set it at some point you need to make sure that is correct as well.

Thanks ill check that :+1:

Something that just occurred to me - do the UDM and HE need to be on the same network? I've just got the UDM and I'm playing around with it a bit before I dismantle my existing Netgear-based network. But that means at the moment that my HE is not on the UDM network

They don't have to be on the same network, but you would need to be able to communicate from one to the other - routing through the Netgear router, might be a firewall rule to be adjusted to allow communication across networks (or just between HE/Unifi

2 Likes

Updated Version(s):

  • UnifiNetworkAPI.groovy = 0.4.20
  • UnifiNetworkChild-Presence.groovy = 0.1.3

Change(s):

  • Added support for the U6 Mesh access point (I have one myself and never realized I had not actually added support for it, oops), it will show up as one of the normal AP devices
  • Added additional attributes for Presence child devices. When the presence is now checked it will also indicate the Connected To MAC and Connected To Name attributes. These will let you know what that device is connected to, whether switch or access point. Thanks to @wafox for thinking of indicating what things are connected to...
  • Minor changes to the driver version update checking

I've rearranged my network a little and now the UDM and the HE are on the same network. Login appears to be successful :+1:

Now to start playing :wink:

Since this update, I am getting UnifiConnection - Request Timeout for any attempt to get presence, current stats, RefreshUnifiDevicesBasic, etc.
Login and ping status seem to work?

I don't /think/ my husband changed anything on the unifi side. Any ideas what could be causing this or where I should start to debug?

Edit to update this, husband installed an update and rebooted the unifi system and it seems to be working? I will continue to monitor

1 Like

Good to hear. Sorry I did not get a chance to reply to the original message, but at least it worked out anyways.

1 Like

I am getting a similar error for presence, but the rest seems to work
Capture

I understood that the driver would create child devices for my Ubiquiti APs, Cameras, etc

but despite having this set, I'm not getting any child devices created
image

All the drivers and Unifi firmware are up to date