hjdhjd / unifi-protect Goto Github PK
View Code? Open in Web Editor NEWA nearly complete implementation of the UniFi Protect API.
License: Other
A nearly complete implementation of the UniFi Protect API.
License: Other
With the 2.9.33 release becoming official, I wanted to reach out to Unifi and ask for their assistance with reviewing the too many requests
issues.
Feel free to close, but I wanted to reach out see if there was any specific information I might help relay to their team. I suspect they will close - not our code
, but figured I give it a shot. Thanks in advance!
Describe The Problem:
To Reproduce:
Time based and stacking exasperated.
Logs:
Event Listener reconnecting in 10 seconds: refresh failed
API access error: 429 - Too Many Requests
Screenshots:
There is no longer an 'Add Device' button on the Protect UI, and the '/protect/devices/add' direct link just redirects to '/protect/devices/' now...
How can we add cameras without this?
Hello, I am using your nice project as part of a larger home-made alarm system and noticed that after some time (can be multiple weeks), the event stream simply stops. I assume that is because the websocket stream is somehow interrupted and not re-established.
My question:
Is there anything I can do in any of the events thrown by unifi-protect to (1) detect this has happened and (2) reconnect?
To Reproduce:
Logs:
The unifi-protect logs remain empty (no errors or anything are thrown)
I'm using the unifi-protect package to stream the video of a single camera to ffmpeg and product HLS video (this format is suitable for consuming via a web page). There's a lag of about 15 seconds - is this normal?
Is your feature request related to a problem? Please describe:
Cache authentication as necessary to avoid hitting new unifi rate limiting constraint where possible.
Describe the solution you'd like:
Ability to selectively use existing authentication credentials which can be overridden as needed.
Describe alternatives you've considered:
Updating unifi settings which does work but is likely not accessible to all users.
Additional context:
Thanks Ubiquiti. https://community.ui.com/questions/Unifi-API-Rate-Limited/ba82a718-9418-46b0-8f2f-235bfc647f9b
Hey there, thanks for creating this library.
I'm trying to detect doorbell rings and used this project to bootstrap the websocket. I'm currently able to retrieve messages, but they're encoded? I'm not very known with this, what is this? Is there an easy way to convert this to JSON? An example of my messages is below.
Thank you! ๐
Describe The Problem:
Unable to use the getSnapshot method to get historical timestamps. I am able to log in and get camera list and pass the camera info into the getSnapshot method but the method is only returning the live snapshot and not historical ones. Is there a bug here or did I miss a setting on the unifi side or something on the javascript side?
To Reproduce:
var image = await ufp.getSnapshot(cam, 1280, 720, 1721019600000, false)
fs.createWriteStream('b.jpeg').write(image);
Logs:
Show the UniFi Protect API logs here.
Not seeing anything relevant in the logs besides the logins from the api user
Screenshots:
It doesn't appear the movement commands are listed in your api reference. Perhaps because you don't have one to test with? I have one, perhaps if you advise how to trap the data I can extract it? Not sure if simple pcap is needed or something more. Before I go down a rabbit hole, I thought you might have some info that would be helpful in figuring out the PTZ side of things. You CAN control position in their protect app, both setting a 'home position' and going to that, and then otherwise moving up/down from current position.
The goal is to determine how motion is controlled on the PTZ. I wish to build a script that will perform a patrol function since Ubiquiti apparently, after 3 years, still won't do so.
I have been having this issue for a while,
plugin works for a good while then starts errorring out, sorts itself out in a few minutes / hours and then this happens again.. all cameras go offline in homekit only, protect is still accessible and working.
I've created a local admin for homebridge plugin access.. able to see all the cameras when its working.
i have around 32 cameras
plugin version : homebridge-unifi-protect v5.5.4
unifi os version : 2.5.11
protect version : 2.1.2
homebrige (on Mac) : [v1.5.0]
Log
[9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] UNVR [UNVR4] Staircase [UVC G3 Instant]: Unable to turn the status light on. Please ensure this username has the Administrator role in UniFi Protect. [9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] UNVR [UNVR4]: Controller API connection terminated because it was taking too long. This error can usually be safely ignored. [9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] UNVR [UNVR4]: Unable to retrieve NVR configuration information from UniFi Protect. Will retry again later. [9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] Invalid login credentials given. Please check your login and password. [9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] 192.168.1.142: API endpoint access error [9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] 192.168.1.142: Unable to retrieve the livestream websocket API endpoint from the UniFi Protect controller. [9/17/2022, 6:11:27 PM] [homebridge-unifi-protect] 192.168.1.142 Staircase [UVC G3 Instant]: Unable to start the timeshift buffer for HomeKit Secure Video. [9/17/2022, 6:11:28 PM] [homebridge-unifi-protect] 192.168.1.142 Staircase [UVC G3 Instant]: Unable to turn the status light on. Please ensure this username has the Administrator role in UniFi Protect. [9/17/2022, 6:11:28 PM] [homebridge-unifi-protect] 192.168.1.142 Home theater cam [UVC G3 Instant]: Unable to turn the status light on. Please ensure this username has the Administrator role in UniFi Protect. Error: from server 192.168.1.62:50425 Error: connect ECONNREFUSED 192.168.1.62:50425 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) { errno: -61, code: 'ECONNREFUSED', syscall: 'connect', address: '192.168.1.62', port: 50425 } [9/17/2022, 6:11:37 PM] [homebridge-unifi-protect] 192.168.1.142 Doorbell [UVC G4 Doorbell]: Unable to turn the status light on. Please ensure this username has the Administrator role in UniFi Protect. [9/17/2022, 6:11:38 PM] [homebridge-unifi-protect] UNVR [UNVR4]: Connected to the UniFi Protect controller API (address: 192.168.1.142 mac: 68D79A5D9DE7).
I know it says it needs admin access but, the user is admin
need help please !
Describe The Problem:
After migrating from the version 3.0.4 to 4.8.0, the code does not compile.
This is the error thrown:
internal/modules/cjs/loader.js:1080
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
require() of ES modules is not supported.
require() of myproject/api/node_modules/unifi-protect/dist/index.js from myproject/api/src/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename myproject/api/node_modules/unifi-protect/dist/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from myproject/api/node_modules/unifi-protect/package.json.
To Reproduce:
Hi,
first of all: Respect for that beauty of code you created!
Do you think, that there's any possibility to control the PTZ cameras via this API?
I'd be happy for everything like setting X,Y,Z or using a preset added on the Protect Web UI.
Describe The Problem:
I'm using the unifi-protect
package to stream the video of a single camera to ffmpeg
and product HLS video (this format is suitable for consuming via a web page). There's a lag of about 15 seconds in the video - is this normal?
To Reproduce:
Followed the docs for listening to the message
events of ProtectLivestream
. I'm feeding these directly into ffmpeg
stdin
(i.e., -i pipe:0
) for transcoding into HLS. I'm watching the transcoded stream with VLC
.
Describe The Problem:
Hello, I am using your nice project as part of a larger home-made alarm system and noticed that after some time (can be multiple weeks), the event stream simply stops. I assume that is because the websocket stream is somehow interrupted and not re-established.
My question:
Is there anything I can do in any of the events thrown by unifi-protect to (1) detect this has happened and (2) reconnect?
Note:
I found this code in your homebridge project:
// Bootstrap refresh loop.
const bootstrapRefresh = (): void => {
// Sleep until it's time to bootstrap again.
setTimeout(() => void this.bootstrapNvr(), PROTECT_CONTROLLER_REFRESH_INTERVAL * 1000);
};
// Let's set a listener to wait for bootstrap events to occur so we can keep ourselves in sync with the Protect controller.
this.ufpApi.on("bootstrap", () => {
// Sync our device view.
syncUfpHomeKit();
// Refresh our bootstrap.
bootstrapRefresh();
});
// Kickoff our first round of bootstrap refreshes to ensure we stay in sync.
bootstrapRefresh();
Is that the solution? Keep calling the bootstrap call every x seconds?
To Reproduce:
Register an unifi-protect.on("message") listener
Do a unifi-protect.login()
Do unifi-protect.getBootstrap()
Wait for the on("message") to stop being triggered
Logs:
The unifi-protect logs remain empty (no errors or anything are thrown)
Screenshots:
Is your feature request related to a problem? Please describe:
No
Describe the solution you'd like:
Can you please make the currently valid login credentials (X-CSRF-Token, Cookie, etc.) accessible or the complete header.
So it would be possible to use the established connection, to get some custom stuff, e.g. downloading thumbnails #24
Describe alternatives you've considered:
see above
Additional context:
none
Describe The Problem:
Since last week I cannot login to the protect integration. Until then I used a cloud account and everything was fine. This time I made a local account and get the same error everytime I try to login (see screenshot).
I have the latest versions of all apps, home assistant, UniFi protect and the integration and a local account (created like the files suggested)with all access to the protect app.
To Reproduce:
Logs:
N/a
Show the UniFi Protect API logs here.
Remove any sensitive information.
Screenshots:
<!โ If applicable, add screenshots to help explain your problem. โ>
Is your feature request related to a problem? Please describe:
am for me is a problem. I need data from my unifi protect to my prometheus so i can use grafana to show metrics ( cameras, nvr )
Describe the solution you'd like:
An exporter which can be run on debian12 and can collect all the api information from the unifi protect and store it into prometheus host so i can than make a grafana dashboard.
Describe alternatives you've considered:
Nothing else. I try to find such a tool but without success
Additional context:
First thanks a lot for this great library, great work !
Can you please implement a function to download the thumbnails?
Endpoint for this are:
/proxy/protect/api/thumbnails/#eventId#
Thumbnail/proxy/protect/api/events/#eventId#/thumbnail
Small Square Thumbnail (not all cams support this, only if bootstrap featureFlags.hasSquareEventThumbnail
is true.EventId can be taken from an event with "modelKey": "event"
My wish is to have a function where i can pass the eventId as parameter. Perhaps two function, one for Thumbnail and one for Small Thumbnail.
Could you please implement this?
Describe the solution you'd like:
It would be nice to have an endpoint we could provide a date range to and a camera ID and it would return a video file or files of all of the recordings between then.
Hi there
I am trying to find a way to trigger the g4 pro poe chime sound without using the main g4 pro doorbell
so I can use a trigger on another door ?
possible ? how ?
cheers
Is your feature request related to a problem? Please describe:
First thanks a lot for this great library, great work !
Describe the solution you'd like:
Can you please implement a function to download the thumbnails?
Endpoint for this are:
/proxy/protect/api/events/#eventId#/thumbnail?h=266.5625&w=266.5625 Thumbnail
/proxy/protect/api/events/#eventId#/animated-thumbnail?h=149.94140625&keyFrameOnly=true&speedup=10&w=266.5625 animated Thumbnail
EventId can be taken from an event with "modelKey": "event". Parameters seems to be optional
My wish is to have a function where i can pass the eventId as parameter. Perhaps two function, one for Thumbnail and one for Small Thumbnail.
Describe alternatives you've considered:
see above
Additional context:
Could you please implement this?
Do you know of or have plans to implement a way to get detections from the camera events? (Person / Vehicle)
The motion detections and doorbell triggers are very useful, but being able to extend the use case of a doorbell to include detecting if someone is at your front door if they don't ring the bell would be really nice. Likewise for seeing if a vehicle has entered your driveway or space you monitor.
Also just to comment, excellent work with this API. Very impressive reverse engineering and documentation.
Describe The Problem:
Hi there
I am trying to find a way to trigger the g4 pro poe chime sound without using the main g4 pro doorbell
so I can use a trigger on another door ?
possible ? how ?
cheers
To Reproduce:
Not applicable
Logs:
Not applicable
Screenshots:
Not applicable
Is your feature request related to a problem? Please describe:
I'm trying to interface with this unifi-protect library from TypeScript. Based on an example, I learned that I need to decode the binary websocket messages into a ProtectNvrUpdatePacket
. However, that particular type does not seems to be exported. It's not exported from protect-api-updates.ts, and I can't find a more generic type in other locations either.
Just for clarity: this is purely a type export issue; the code seems to function just fine. This is a minor issue.
Describe the solution you'd like:
export some type that can be used for decoding update packets. I don't know if it needs to be this exact type as defined in protect-api-updates.ts, or some more generic type.
Describe alternatives you've considered:
Working with untyped code works, but isn't ideal.
Additional context:
none
Is your feature request related to a problem? Please describe:
I bought a UVC-G5-Pro and mounted it to the tower of my flying club's airfield. We primarily want to use it as a "netcam" and upload a picture once a minute to our website, for pilots to judge weather condition or just admire the glider planes ;-)
This seems awkwardly difficult to achieve. The "anonymous snapshot" feature of the cam itself only returns 640px width and very highly compressed images - bummer.
I started researching and found no easy way to export still pictures from Unifi Protect nor the cam.
Finally, I came across this library. Thanks a lot for making this! I learned enough NodeJS to get it to call the "getSnapshot" via Unifi Protect API last night.
Now I can obtain 3840x2160 px resolution snapshot, but the pictures are still heavily compressed and look terrible...
Describe the solution you'd like:
I would liked to reduce JPEG compression on the getSnapshot returned image - or set it to a higher quality at least.
I am unsure if Unifi has necessary parameters, fiddling with the UI I could not find any. For playback it seems multiple channels with different compressions are supported, but I was not successful applying those params to the snapshot endpoint.
Describe alternatives you've considered:
If Unifi Protect snapshot endpoint does in fact not provide better quality image, an alternative approach might be to extract a higher quality still picture from the video stream. But I honestly don't know how to do that.
Maybe a convienience method could be added to the stream API?
Additional context:
I am attaching two JPEG show the problem. One was obtained through snapshot service, the other was exported from Unifi Protect UI. You also see a big difference in file size.
Snapshot:
Still picture taken from Unifi Protect UI:
Hi,
Is there an option to get notification for specific motion zone?
I will send a webhook to my Dominica system when there is motion detected on a specific motion zone.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.