Since the UniFi API change, drivers that log in with a username and password stopped working for many of us. I wrote a new Edge driver that uses the official UniFi Protect Integration API with a local API key instead.
What it does
Doorbell ring as a button “pushed”, ready for routines
Motion per camera
Person, vehicle and animal detection as separate motion sensors
Real time events over the local Protect events WebSocket, no cloud
Experimental video stream (RTSP), viewable via a camera group
Requirements
UniFi OS console with Protect (tested on a UDR7 with a G4 Doorbell)
A local API key: UniFi OS > Control Plane > Integrations
In the app: Add device > Scan nearby, a device “UniFi Protect” appears
Open its settings and enter your console IP address and API key
Your cameras appear automatically
Cannot open the device settings in the app (seen with Android app 1.8.52)? The driver also runs a small settings page on your SmartThings hub (not on the UniFi console) where you enter the console IP address and API key. Its address is your hub IP plus a random port that the hub picks each time the driver starts. To find and open it, install the SmartThings CLI and run this in PowerShell; it asks for the IP address of your SmartThings hub (app: hub device > Information, or your router):
The channel currently serves the version 2 build from 14:24 UTC. That build is verified to install on a fresh hub and has everything from the version 2 post above.
As soon as uploads work again, the channel gets the new build and your hub picks it up automatically.
Two tips in the meantime:
- Can’t open the device settings in the app? That is a known SmartThings app issue, not the driver. Try again later or on another phone. Until the settings page ships there is no other way to enter the IP address and API key.
- If the install fails on your hub with “Failed to install Driver”, check how many drivers your hub has. Hubs stop installing at around 50 drivers. Remove unused ones with smartthings edge:drivers:prune.
Thanks for taking up the effort! Much appreciated!
I have it up and running, and everything seems to be working great. I am on v2 62.14 and Android 1.8.47.24. Will report back here if I have any issues.
Quick question: could you open the settings of the “UniFi Protect” controller device in the app without problems, to enter the IP address and API key? On my own phone the settings page of that device does not open at all (the app just closes it), so I am trying to find out whether that is my app or something more general. Which phone and app version are you on?
With all the issues with the last few app versions, it is highly likely Samsung broke something or introduced a bug(s) that is impacting your driver. I am using the last working version of the Android app for me, which is 1.8.47.24, on a Samsung S22 Ultra and S22+. Your driver is working here without any issues. So far, everything after version 1.8.47.24 is a dumpster fire lacking any real beta testing.
v2.6 is in the channel: fixes a crash every minute.
The vendored lustre WebSocket client fell over once per keep-alive interval (60 s) with lustre/ws.lua:296: attempt to index a nil value (local 'recv'). The hub restarted the driver each time, so it looked like it worked, but any doorbell or motion event during the restart was lost and the log filled with FATAL lines. The select() timeout that sends the keep-alive ping now skips the receive step instead of calling it with nothing to read.
Your hub picks it up by itself. If it keeps logging that line after a day, run smartthings edge:drivers:install <driverId> --hub <hubId> --channel <channelId> once; on my v2 hub that pushed the update through immediately.
Update 29 October: the real cause of my NotFoundError last week was timing, not a full hub. With SmartThings support I tested both ways on a cleaned up hub. Package, assign and install as three separate commands with about two minutes in between: installed straight away. The one step smartthings edge:drivers:package . --channel <id> --hub <id>: NotFoundError, and that uploaded version kept failing on every later install, even minutes later. So if you build your own version, use separate steps and package a new version if one failed. I did prune about 30 unused drivers from the hub on 26 October as well; whether that played a part is unknown.
v2.7 is in the channel: the settings page on the hub now locks itself.
The settings page (for people who cannot open the device settings in the app) has no password. Until now it stayed open as long as the driver ran, so anyone on your network who found the port could change the console IP address and API key. From v2.7:
The page is only open while the driver has no API key yet, or for 10 minutes after you press Refresh on the UniFi Protect device.
About a minute after you save, it closes again.
The port really closes, so nothing is listening on the hub when you do not need it.
A flood of connections can at most make the page busy; it no longer affects the driver.
Need the page? Run the one line script, it presses Refresh for you and opens the page:
The settings page is never open longer than 15 minutes, also when no API key is set yet. Press Refresh on the UniFi Protect device to open it again for 15 minutes.
The page only answers when opened by the hub IP address and refuses forms sent from other websites.
Your hub picks up v2.8 by itself. Tested on my v2 hub: connected and event stream open after the update.
SmartThings has no routine trigger for “device offline”. The UniFi Protect device now has a Connection status (Connected or Offline), so you can make a routine:
If UniFi Protect > Connection is Offline, then send a notification to members.
Short drops (a reconnect or one missed poll) are ignored: Connection only turns Offline after 2 minutes without a connection. Every drop is remembered: when the connection is back the device shows Last drop with the time (UTC), how long it lasted and the reason.
For a device that drops off now and then (like a robot on a weak wifi spot) set “How long does this status last” to a few minutes. The driver updates itself from the channel; the status shows after the next poll. README updated.
The UniFi console uses a self signed certificate, so the driver could not tell it apart from another device on the same address, and it would have sent the API key to it. The driver now remembers the UniFi console’s certificate at the first connection and refuses (without sending the API key) when another certificate answers. Replaced the UniFi console? Enter the API key again and the new certificate is trusted. The driver updates itself from the channel.
If you made the Offline routine (UniFi controller device, Connection is Offline, send notification), duplicate it in the app and change the condition to Connection is Connected, with a text like “UniFi controller is back online”. Then you know the problem is over without opening the app. The device also shows Last drop (when, how long, why).
Update v2.10.1: no more “not all status information updated yet”
The SmartThings app shows that message when an attribute has no value. On a device that never had a connection drop, Last drop was still empty. It now starts with “No drops yet”.
Update v2.10.2: no Offline notification for a short network outage
New setting Offline after (minutes), default 30. Connection only turns Offline after that many minutes without contact. Before it was 2 minutes, so a router or network update at night (a few minutes without network) gave an Offline notification even though nothing was wrong. A real outage still gives one.
The default is 30 minutes here because UniFi Protect itself restarts for quite a while during an update (20 minutes here last night).
Fixed: Only changed values go to the hub. The driver used to send every value again on every poll or report. Too many events make the hub drop events of a device, and the app then keeps a stale value (a switch that stays on, a slider that keeps its old position). Now a value is only sent when it changes, and after every driver start all values are sent once so the app catches up. The stream and the LED state were sent again on every camera sync.
The list of cameras you removed (so they do not come back) is now stored in a form that survives every hub version.
Security, settings page: the page on the hub now only answers under a secret address, printed in the hub log and by tools/find-settings-page.ps1. Before, anyone on your LAN could open it while it was open and overwrite the console address and API key. After 30 wrong addresses it closes.
Security: the driver remembers the certificate of the console with the first connection that carries the API key. If that certificate can no longer be read later, the API key is now not sent (before, the check was skipped).
Update: the hub picks up the new version from the channel by itself, or install it again from the channel.
Fixed: routines no longer run again after a driver update or hub reboot. After a start the driver sent the first value of every attribute as a forced event (state_change), so routines and notifications on these devices ran again on every update. Now it first compares with what SmartThings already shows and only sends what differs.
Refresh twice quickly could leave an old event connection running (a leaked socket and a doorbell press reported twice). The old loop now stops.
Reconnect backoff: if the console accepts the event stream and drops it right away, the driver now waits longer each time (up to 5 minutes) instead of reconnecting every 5 s.
Status LED shows the new value at once and the real value again on an error.
Renaming a camera no longer resets a running motion to inactive.
Update: the hub picks up the new version from the channel by itself, or install it again from the channel.