-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[unifiprotect] Unifi Protect Binding Initial Contribution #19411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
How does this related to this binding: https://github.com/seaside1/unifiprotect that also has a marketplace entry: |
@lsiepel if you read the bottom of my first i comment, i addressed this. |
Sorry, i somehow overlooked those lines. Did you try to contact @seaside1 ? |
I have not, he has not been on the forums since march, and in the end the binding would have needed a massive overhaul if submitted as a PR, regardless of the new API. Plus the binding has been untouched since Oct 2024, despite activity on the forums about issues. So i assumed it was mostly abandoned at this point. After a weekend of trying to refactor the code, i ran out of steam and decided to start over starting with the published openapi.json as the basis for forming the DTO model, then the API client, and finally informing that shape of things and channels before writing the handlers. This lead to a different structure that is much more naturally suited to the official API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces the initial contribution of a UniFi Protect binding for openHAB. The binding provides integration with Ubiquiti UniFi Protect NVR systems using the official Protect Integration API for local communication via HTTPS and WebSockets.
- Comprehensive binding implementation supporting cameras, floodlights, and sensors with real-time event processing
- WebRTC streaming support with go2rtc integration for low-latency video and 2-way audio capabilities
- STUN support for external access through NATs when using openHAB cloud services
Reviewed Changes
Copilot reviewed 125 out of 128 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
bundles/pom.xml | Adds the new unifiprotect module and removes unnecessary whitespace |
bundles/org.openhab.binding.unifiprotect/src/main/resources/OH-INF/thing/thing-types.xml | Complete thing type definitions for NVR bridge and device types (cameras, lights, sensors) with channel configurations |
bundles/org.openhab.binding.unifiprotect/src/main/resources/OH-INF/i18n/unifiprotect.properties | Internationalization properties for labels and descriptions |
bundles/org.openhab.binding.unifiprotect/src/main/resources/OH-INF/config/config.xml | Binding configuration for binary downloads and STUN usage |
bundles/org.openhab.binding.unifiprotect/src/main/resources/OH-INF/addon/addon.xml | Addon metadata definition |
bundles/org.openhab.binding.unifiprotect/src/main/java/org/openhab/binding/unifiprotect/internal/media/*.java | Media service implementation for WebRTC streaming and go2rtc integration |
bundles/org.openhab.binding.unifiprotect/src/main/java/org/openhab/binding/unifiprotect/internal/handler/*.java | Thing handlers for NVR bridge and device types (cameras, lights, sensors) |
bundles/org.openhab.binding.unifiprotect/src/main/java/org/openhab/binding/unifiprotect/internal/dto/*.java | Complete data transfer object model for UniFi Protect API entities and events |
Comments suppressed due to low confidence (1)
bundles/org.openhab.binding.unifiprotect/src/main/java/org/openhab/binding/unifiprotect/internal/media/NativeHelper.java:1
- There is a spelling error: 'stupported' should be 'supported'.
/*
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
bundles/org.openhab.binding.unifiprotect/src/main/resources/OH-INF/thing/thing-types.xml
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/unifiprotect/internal/api/dto/reference/CameraReference.java
Outdated
Show resolved
Hide resolved
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/unifi-binding-beta-3-2-0-3-6-0/131156/195 |
I've tried to contact seaside months (a year?) ago, but no response. I'd gladly also join your test audience. |
@digitaldan: I see you're updating snapshots before triggering channels when events come in. My first gut is to swap that (because I don't care about the snapshot when I'm taking actions like turning on lights) and sometimes taking a snapshot can take a non-trivial amount of time, but then I realized perhaps that's on purpose because another legitimate case is to send a notification with the snapshot when an event happens. What do you think the best course is to resolve these opposing goals? We could add a configuration to just never update snapshots automatically in response to events, then a user could choose, but that's still problematic if someone has both types of rules. Perhaps a 3-state option: no automatic snapshots, automatic snapshots before triggering channels, or automatic snapshots after triggering channels? Then if someone cares about both use cases, they can use the post-trigger update, and watch the snapshot channel itself (probably with additional state to only care shortly after an event was triggered). |
So thats exactly the reason, in rules i react to a item or trigger and send the image off. I was not aware of a significant delay grabbing images, but to be honest have not benchmarked that, so i can take a look. I'm ok adding an advanced option to swap the order if you thinks its a significant enough delay (more then a second i guess).
I could have sworn i was checking if a channel was linked before taking a image snapshot, but i think i'm doing that on another binding i'm working on now that i look at it, i'm going to add that so if you don't link an item, we don't waste resources. |
Actually i am checking if a channel is linked before taking a snapshot 😅
|
I haven't checked through the official API like this, but I've run into issues fetching snapshots completely with a rule that fetches the snapshot itself.
yes, you are doing exactly that. but that doesn't help I still want the snapshot, but want both snapshot-less and snapshotting rules |
BUT:
In other words it took nearly half a second to fetch the image. So not terrible. And perhaps my (wireless) doorbell is just behaving well today. |
AFAICT, this is the only way to identify a doorbell Signed-off-by: Cody Cutrer <cody@cutrer.us>
Are you thinking a binding config or channel config (or something else)? We could add it something like
but yes, i could see a wifi device delaying this, my doorbell also has notorious connectivity issues likely b/c of where you have to place it. |
I was thinking thing level (not binding level), but I like the idea of channel level too. That way you could configure it differently depending on event type - you might be okay with a minor delay for object or audio detection, but want to send off a notification immediately for a doorbell button press. |
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two comments i noticed when looking at this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add semantic equipment tags to all things?
Please also add semantic tags to the channels (point+property) where possible.
add ring channels based on presence of lcdMessage in camera details
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
I have been looking to add support for openHAB 5 for the UniFi Protect binding, however this looks promising and I can maybe help out to test and contribute here. |
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 126 out of 129 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
bundles/org.openhab.binding.unifiprotect/src/main/java/org/openhab/binding/unifiprotect/internal/media/NativeHelper.java:1
- Corrected spelling of 'stupported' to 'supported'.
/*
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...c/main/java/org/openhab/binding/unifiprotect/internal/handler/UnifiProtectCameraHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
This binding integrates Ubiquiti UniFi Protect into openHAB. It connects to your Protect NVR/CloudKey/UNVR and provides live events and configurable settings for Cameras, Floodlights, and Sensors.
It uses the official Protect Integration API locally over HTTPS and WebSockets
Features
I know there is another protect binding in the marketplace, and i did first try and modify that, but after a day it became very obvious i would end up rewriting most of it completely to fit the official API. Also that binding has not been updated in almost a year.
I'm opening this PR up early to get some feedback from other protect users, will mark as WIP until ready for review.
Also See openhab/openhab-webui#3368 for updates to our video widget to support 2-way audio (can be merged independent of this)