[PROJECT] Driver for Unifi Connect

Overview:
This is a parent/child set of drivers in order to read data from your Unifi controller's Connect API and provide some information that may be useful to your Hubitat. It also allows for some commands to be sent from the Hubitat back to the API for limited control of Connect features, geared around the device-specific child drivers. Like most of my drivers this will be a perpetual project and I am always open to feedback.

Features:

  • Create supported child device(s)
  • Ability for specific device features such as turning on/off, setting volume, setting brightness, etc...
  • Daily check for new devices added to the Connect API
  • Daily check for new driver versions. It will NOT load updated drivers, just post an event that a newer version is available.

Driver Links:

Setup:

  1. Add UnifiConnectAPI.groovy driver to your Drivers Code section on your Hubitat (you can Import using the URLs above) then Save the driver.
  2. Add a Virtual device and set the Type to be UnifiConnectAPI (user-added drivers are going to be at the bottom of the list), then Save Device.
  3. Enter your Unifi Controller's IP/Hostname, Username, and Password into their respective fields in Preferences, select your Unifi controller type, then Save Preferences.
    REQUIRED: If you use a Controller Type of "Other Unifi Controllers" go back to the Preferences after you save. There should now be a field showing Controller Port # that is required. This defaults to the typical 8443 but newer Controller versions may be using 443.
  4. OPTIONAL: Add any specific child drivers using the same method as step 1.

Caveat(s) / Known Issue(s):

  • Very little data is posted to devices at this time. There is more data that has been identified and will be added but I wanted to get some basic functionality out there for everyone to try first.
  • The Connect API provides VERY limited responses to actions sent compared to other Unifi APIs. The driver attempts to work around this by populating data based on the success or failure response.
3 Likes

Thanks so much, I got the drivers installed, but it did not identify my display 13 correctly just assigned the ConnectChild driver, so I changed the driver to the display 13 and then tried to control the device with just the options and nothing happens with any of them.

What do you need from me?

Looking into the logs you sent me to try to figure out where I went wrong for the Display 13... Sorry about that.

Thanks for everything, its working great now!

Updated Version(s):

  • UnifiConnectAPI.groovy = 0.1.3
  • UnifiConnectChild-UC-Display-13.groovy = 0.1.1
  • UnifiConnectChild-UC-Display-SE-13.groovy = 0.1.1
  • UnifiConnectChild-UC-Cast.groovy = 0.1.1
  • UnifiConnectChild-UC-Display-7.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-UC-Display-21.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-UC-Display-27.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-UC-Display-SE-7.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-UC-Display-SE-21.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-UC-Display-SE-27.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-UC-EV-Station.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-ULD3AC.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-ULP3AC.groovy = NEW, link added to thread's initial post
  • UnifiConnectChild-ULP3PE.groovy = NEW, link added to thread's initial post

Change(s):

  • Added support for all devices currently listed in the API's responses (see specific child drivers).
  • Overhauled how actions were performed from the existing child devices.

Note(s):

  • After putting a bunch of work into getting all the different displays added specifically... I have been thinking of a way to make a single display driver that would make all the current 8 obsolete. Something for the future.
  • There is not much difference (from the API or driver perspective) between a Display and a Display-SE. If you are not sure which you have, add both child drivers. You can always delete the unused one. In the future, if I can get a consolidated Display child driver made it will not matter anyways.

Updated Version(s):

  • UnifiConnectAPI.groovy = 0.1.6

Change(s):

  • Change to how the CSRF value is received when a login attempt is made. In version 3.2.8 of the Unifi OS they changed the header's case... Yes, something as simple as changing it from X-CSRF-Token to X-Csrf-Token broke it. So the device was not actually capturing the latest CSRF so actions could no longer work. I was recoding it when @tomw provided a better method of changing it's case and comparing it to that. So now, even if they change it to x-CsRf-ToKeN (or any combination thereof) it will still work.
  • Changed the WebSocket portion to match what I have in my Protect driver
  • Cleanup of copy-paste error in login section
  • Change to error logging for login

Updated Version(s):

  • ALL DRIVERS UPDATED

Change(s):

  • Support for new authorization Token used by newer Unifi OS versions.
  • Replacement of driver-specific variables "Driver Name", "Driver Version", and "Driver Status" with ones that do not have a space. This will take effect the next time you Save Preferences on a particular device.
  • Correction to ProcessEvent function.