Ubiquiti Unifi Protect cameras

Oh! Yeah that may make better sense.

You might want to experiment with it, depending on what you're trying to do. You can resize the image with take (height and width settings on the virtual device), but there may be additional configuration with snap if you want to adjust other aspects of the image. It just depends on what you want to use it for.

1 Like

So is there presently no way to get the displayImage from your driver to appear in Hubitat's Dashboards? When setting the attribute value to displayImage or image, it say "Please Select an Attribute"

It's a limitation of the Hubitat dashboard (1024 characters) since display image is a data url injected into the tile as HTML. You can dial the image resolution WAY down (probably not practical). Or if you do a clearImages() before loading the dashboard and then do take() it will display. But really it may be more usable with an external dashboard. I'm trying to find a way to work around this limitation in Hubitat, but so far this is the best I have seen.

I found a working solution for this after seeing what was done for SharpTools and the Unofficial Ring Integration.

An app will need to be created to serve the image payload from an endpoint.
The UniFi Controller will need to be a child of that app, and the devices a child of it.

Here is a link to the quick app that I made to solve this issue.

https://gist.github.com/JoKneeMo/2e8d0e3445faa54a61e9c3284c380159#file-hubitat-unificontroller-app-groovy

I made this app so that it could also handle future UniFi Controller functions, not just Protect.

It will not migrate any existing controllers!
This was a quick and dirty job and it's the first time I've ever dove into Hubitat's app code.

Instructions:

  1. Add the app code to Hubitat along with your (tomw) 3 drivers.
  2. Be sure to enable OAuth in the app code section so that it will create an access key.
  3. Install the app from the Apps page.
  4. Open the app and click "New UniFi Controller"
  5. Fill in the details and click "Add Controller"
  6. Go back to the main page of this app and click on your new controller that was just created.
  7. Scroll down to the "Child Devices" section and click "Create Child Devices"
  8. If you go back into the controller in this app, you should see your child devices listed there.
    If you ever need to add additional devices, you can just go back to this page and click refresh.
  9. Back on the main app page, click "View Dashboard Snapshot Configuration" for details on how to add it to the built in Hubitat Dashboard.

In summary, after creating the Controller device using this app, you can add a dashboard image using a url like this:

`../../$APPID/snapshot/$CONTROLLER_DNI/$CAMERA_DNI?access_token=$OAUTH_TOKEN`

Unlike the Ring integration, this app will also work with the cloud dashboard. This is because the image link uses a relative path.

Cool! Thanks for sharing.

This is basically the same approach I had in mind, though I did it a little bit differently. This was what I struggled with:

Since you can't re-home existing devices if you discovered this issue after the fact, and because I figured that an additional app should be optional for people that didn't need it, I went with user-selection of existing devices rather than having the app parent them.

UPDATE: new info on app is here - Image Server app for dashboard images and notifications

Previous location:

https://github.com/tomwpublic/hubitat_unifiProtect/blob/tomwpublic-imageserver/imageServerApp

You just have to form the URL for any dashboard images to include the DNI of the device of interest, but the app shows the URLs for each selected device to help facilitate copy/paste during dashboard creation. Note that this should be used for the Image URL, not the Background Image Link or else the dashboard auto-refresh won't work.

EDIT: @b491ce02c78ba874857b just making sure you saw the last two posts of chatter on this topic, as it wasn't a direct follow-up to your previous question.

1 Like

That looks like it would work great for general usage to serve images from devices.

Specifically for your Protect driver, I didn't want to alter it so I added in the detection of devices not having the image attribute.
This could have been resolved by setting a default null value for image when the device is created or fails to grab a snapshot.
I discovered this problem because I have a few G3 micros that I move around. Some were offline when writting this.
When the image attribute is not available, it returns a missing snapshot image (copied from the unofficial ring app).

Also because some devices were online but a snapshot was never taken, I executed take() before retrieving the image value.
This way you won't have to set up a polling rule. Not sure how that affects system performance though.

Regarding the existing controllers; I didn't bother with it when making this app.
I'm new to apps for Hubitat but after looking at the info in the docs this might be doable?

Possibly a migration page can be added that scans for any devices using your drivers.
After selecting the devices to migrate into the app, execute device.setDeviceNetworkId($formatedDNI)
Just spitballing there, not sure if that would affect the relationships.
There might be an undocumented setParentAppId() or something?

One thing I was able to find from your driver, not sure if it was intentional; If you add a second connection to the same controller, it will only import child devices not already on the system.
This was great for testing because I didn't have to remove all of my cameras from the standalone driver.
I could just remove one and then refresh the child devices from within the new app.
I'm assuming that you're using the UniFi UUID instead of generating a new one.

Also, that user was me, I forgot that I already had an account in the forum before posting that question. This app was a result of your answer. Thanks!

Awesome. That is funny.

I have looked high and low for a way to re-parent an existing device, but I don't think it exists. I have found use-cases for re-parenting to both apps and drivers but eventually gave up when I couldn't find any way of doing it.

How did you solve the cloud-based use-case? I just noticed that the method I used doesn't seem to work, presumably because the dashboard running on my mobile device is trying to access the image URL directly rather than through the backend on my local network like I would have expected.

On the weird behavior with multiple controllers that you saw: I set the DNI of the child motion (camera, doorbell) and button (doorbell) devices to a defined format that includes the MAC of the device plus its type of virtual device. So, when you have two parent drivers connected to the same controller, only one will actually be able to create a virtual device for a given child. I thought about further scoping the DNI value to the specific controller so that they could be duplicated, but I figured that was an unlikely corner case. It would be easy to change if needed, though -- for example in cases where someone wanted to use your app for some images and still have a standalone driver setup separately.

I noticed that the cloud dashboard url was just a very simple proxy serving the same paths.
It seems to work for any apps with OAuth and a mapping.

In fact, in the dashboardHelp page of my app, I render out the local url with with getLocalApiServerUrl(). If you change this to getApiServerUrl() you'll get the cloud url.
Their endpoint paths are both the same, only the domain changes for the most part.
So if you use the relative path for accessing the image (back two levels from the dashboard endpoint), it will load the image via the cloud or local, however you're accessing it.

It also works when accessing the Hubitat through a reverse proxy via an alternate port with TLS.

1 Like

You're right- I had a more fundamental issue that jpeg rendering to a cloud endpoint fails for some reason. Your svg method works fine. Thanks for that example!

Instead of having a tile on the dashboard with a live feed, is there a way to just install the Unifi Protect app ?
And have the app on the dashboard, then you can view the cameras from inside the app ?
Has anyone tried this ?

Just realized I never closed the loop back to this thread. Here's one method to do this, using vlc on an external machine to transcode the stream to mjpeg: App Link on Your Dashboard - #18 by tomw

So I just installed your app code and the 3 drivers, went through the steps, but #9 I can't find, The App page never populated with anything, but the devices populated great.

how can I get the "View Dashboard Snapshot Configuration"

I wrote the drivers and @JoKneeMo kindly shared one app to serve images for dashboards. I also shared my take on it, here: Ubiquiti Unifi Protect cameras - #127 by tomw

I never made mine part of the main package because I wasn't sure whether it was complete enough for users other than me. Want to try it out and I will make it part of the main package with the drivers if so?

Well I had the stuff installed and had the devices installed and could click on device and take snap and that worked, But could not get back to the APP he made to see the View Dashboard Snapshot Configuration" so I tried the proccess again and now getting an error that it cant connect to my unifi controller. So I tried to log into my controller and now it will not let me in. keeps saying my password is incorrect. (And I have lasspass auto populate it with out issue until now)

I think this broke my login into the controller as now I cant get in, and there is no password reset option. :frowning:

Can you log in to the controller outside of the Hubitat integration?

no not anymore. something broke it been fine for over a year.

That is very odd. Do you at least get its web interface to log in? Are you using a cloud or local login?

It can’t. It doesn’t make any changes to the controller.

1 Like

Ok looks like it was a time out, when I tried to recreate the setup again and add the controller back to Hubitat again, it for some reason created 8 copies, and that locked me out of the server. LOL. Going to create a user just for protect to avoid that issue in the future.

Back in my controller

1 Like