Reply
New Member
Posts: 34
Registered: ‎05-19-2017
Kudos: 19

Re: Unifi Protect API or Motion alerts hit API?

agree with much of what was posted here. 

 

 

I'd also request that semantic versioning of the API be used, as well as autogenerated documentation. The API should be what the frontend talks to, just like any other api customer. 

 

IMHO, taking this approach would help ensure that anything implemented in the GUI would be doable without the gui, or with a different gui.

 

New Member
Posts: 33
Registered: ‎10-16-2016
Kudos: 613

Re: Unifi Protect API or Motion alerts hit API?

It is extremely disappointing that API access or integrations for automation platforms like SmartThings or Home assistant are not a priority to Ubiquity. Considering the investment in this space that Ubiquity has made by hiring Paulus Schoutsen of Home Assistant. More and more folks are moving to UniFi Cameras as a replacent for several other platforms. It just seems that API integration would be a big win. 

New Member
Posts: 4
Registered: ‎04-12-2018
Kudos: 4

Re: Unifi Protect API or Motion alerts hit API?

+1 Vote here as well.

 

Having the ability to access Protect recordings/triggers programmatically would be very helpful. Like the others I'm looking to take action with my HA system based on motion detection.

 

Respectfully,

 

Tom

New Member
Posts: 4
Registered: ‎12-28-2018
Kudos: 2

Re: Unifi Protect API or Motion alerts hit API?

I really need this. Actually I found this feature so basic that I didn't review if the Unifi Protect series would have this. I had assumed it had. But now I am disappointed.

 

An HTTP GET request, MQTT or a simple bash script is absolutely necessary.

 

New Member
Posts: 1
Registered: ‎02-10-2017
Kudos: 1

Re: Unifi Protect API or Motion alerts hit API?

Another request for  a method of integrating with something like Home Assistant here. Thanks!

New Member
Posts: 1
Registered: ‎12-03-2017

Re: Unifi Protect API or Motion alerts hit API?

+1 from me.

Agree with everyone here that an API is a MUST, I want to be able to control (motion) recording ON/OFF and other things.

Please make the API a high priority feature.

 

Thanks!

New Member
Posts: 2
Registered: ‎05-31-2018

Re: Unifi Protect API or Motion alerts hit API?

I too need an API, or other means of automating against unifi-video & unifi-protect. (ssh commands or rest-api would be best)

I've seen someone that made an integration with mqtt to unifi-video, which seems quite nice, but I have no experience with mqtt, so for me rest or ssh commands would be easier.

 

Need to do:

* Switch between no record / record, on spesifc cameras from an external source like home-automation. (This way, recordings could be on when the home automation detects that we are not home)

* Get triggers on motion detection for each camera, with last motion date/time (would act as a motion sensor for home automation)

 

 

 

 

New Member
Posts: 7
Registered: ‎11-04-2016
Kudos: 2

Re: Unifi Protect API or Motion alerts hit API?

[ Edited ]

+1 for API

 

I have a CloudKey 1 and ordered already a Cloud Key 2 together with 5 UniFi Cameras. I also have HomeMatic from EQ3 running since a few years along with iobroker to connect it to everything else (e.g. FritzBox). For iobroker, there is already a UniFi plugin that interfaces with the API of the UniFi networking product line and it would be really nice, if UniFi Protect could also be integrated. This would enable to arm the alarm system when all Smartphones left the house and also arm the motion detection and recording of UniFi Protect. It could then also be triggered by window and door sensors...

New Member
Posts: 6
Registered: ‎04-02-2014
Kudos: 5

Re: Unifi Protect API or Motion alerts hit API?

+1 for the API. As example applications:

 

- Turn on alerts if nobody is home (tie in with home automation/security system)

- Take snapshots if a door is opened

 

I think a solid API should also help internal development. Write the API first, than built frontends in JS for browser or built a mobile app and such using the API.

 

New Member
Posts: 10
Registered: ‎10-24-2017
Kudos: 13

Re: Unifi Protect API or Motion alerts hit API?

I wrote a script for Unifi Video to monitor the motion log in /var/log/unifi-video/motion.log and send events to MQTT, not sure if Protect has a similar log file in /var/log/unifi-protect/motion.log ?

 

https://github.com/mzac/unifi-video-mqtt

 

New Member
Posts: 4
Registered: ‎12-28-2018
Kudos: 2

Re: Unifi Protect API or Motion alerts hit API?

I found log file on my Cloud Key Gen 2+.

It's located at /srv/unifi-protect/logs/events.cameras.log

 

It has a very different structure. But I think something can be done with this ;-)

New Member
Posts: 4
Registered: ‎12-28-2018
Kudos: 2

Re: Unifi Protect API or Motion alerts hit API?

Also by digging around I found that the Cloud Key Gen 2+ is running Postgres.

 

Events are recorded there in table "events" of database "unifi-protect".

 

unifi-protect=# select schemaname, tablename from pg_tables where tableowner = 'unifi-protect';
 schemaname |       tablename
------------+-----------------------
 public     | alerts
 public     | partitions
 public     | sessionIDs
 public     | cameras
 public     | users
 public     | groups
 public     | events
 public     | backups
 public     | recordingFiles
 public     | stats
 public     | thumbnails
 public     | recordingSchedules
 public     | nvrs
 public     | heatmaps
 public     | liveviews
 public     | notificationSchedules
(16 rows)

New Member
Posts: 21
Registered: ‎06-18-2015
Kudos: 31
Solutions: 1

Re: Unifi Protect API or Motion alerts hit API?

Really clever to consider using a camera events log, or the Postgres database to build a simple script that fires events to an external resource.

New Member
Posts: 10
Registered: ‎10-24-2017
Kudos: 13

Re: Unifi Protect API or Motion alerts hit API?

Awesome I'm glad to see that Protect also has a way to monitor either the log or the database!  Now we just need a script to monitor it and push it to an API (could be a curl call) or MQTT!

New Member
Posts: 6
Registered: ‎04-02-2014
Kudos: 5

Re: Unifi Protect API or Motion alerts hit API?

I just played a bit with it, and figured out part of the API, in particular enough to retrieve events.

 

First, to get basic information about the system (e.g. firmware version)

 

GET /api/ump/info

 

Next, to authenticate, send username and password (json encoded) to

 

POST /api/auth

 

you will get a JWT Bearer style authentication header back, that you need to include in later requests (in addition to a number of other items about the user.

 

next you need to request an access key. this key is required to get images later:

 

POST /api/auth/access-key

(no data, just the Authorization header from above)

 

to get a list of events:

 

GET /api/events?end=[unix timestamp]&start=[unix timestamp] &type=motion

 

this returns a list of events like:

 

[{"type":"motion","start":1547086305207,"end":1547086314307,"camera":"5c30d50f03008f03e7000799","score":39,"thumbnail":"5c36a9e803611d03e700046c","heatmap":"5c36a9e9006a1d03e700046d","id":"5c36a9e3010c1d03e7000469"}....]

 

To retrieve a thumbnail image for the event use the "thumbnail" parameter and request:

 

GET /api/thumbnails/[hex thumbnail id]?accessKey=[key returned from 'access-key' request above]

 

Also, to reboot a camera:

 

POST /api/camera/[hex cameraid]/reboot

 

 

 

New Member
Posts: 34
Registered: ‎05-19-2017
Kudos: 19

Re: Unifi Protect API or Motion alerts hit API?

This is a FANTASTIC first step. Ubnt: we NEED this officially documented. To be truly usable, it also MUST be versioned, and semantic versioning must be enforced. Ideally there would be a test harness which exercises each facet of the API that is publicly shared, and that you encourage contributions to. I know this sounds ... burdensome. But I wholeheartedly believe the long term benefits will payback the cost. You make it much easier to re-tool different parts of your codebase when things have a prescribed, and tested way of interacting without stepping on each other’s toes. Where this goes wrong is when the mandates above aren’t adhered to. Without being diligent to keep the promise of versioning, documentation, and tests, you get fewer benefits, more frustration, and essentially end up with the worst of both worlds.... this isn’t the part to half-ass. But whe do e properly, the benefits of isolated facades do outweigh the costs. Thank you guys so much for listening to us here I believe the end result will truly be a better product that is more extensible, and more supportable in the long run. ❤️
New Member
Posts: 2
Registered: ‎09-13-2018
Kudos: 2

Re: Unifi Protect API or Motion alerts hit API?

In that case we could potentially use postgres triggers ( https://www.postgresql.org/docs/9.1/sql-createtrigger.html ) to get push notifications for new events.

 

(e.g. this npm package uses triggers to get live updates to queries on postgres: https://github.com/nothingisdead/pg-live-query ).

New Member
Posts: 2
Registered: ‎12-19-2017
Kudos: 4

Re: Unifi Protect API or Motion alerts hit API?

I forked the repo above: 

    https://github.com/mzac/unifi-video-mqtt

 

And produced:

    https://github.com/terafin/unifi-video-mqtt

 

This appears to work on my CloudKey G2+, but please let me know if you have any problems, I can try to poke at things!

New Member
Posts: 10
Registered: ‎10-24-2017
Kudos: 13

Re: Unifi Protect API or Motion alerts hit API?

Awesome!!!  Now if only Ubiquiti could integrate this into Video and Protect, it could be configured from the GUI!

New Member
Posts: 2
Registered: ‎12-19-2017
Kudos: 4

Re: Unifi Protect API or Motion alerts hit API?

Agreed! Also - Thanks for your template to start from! Man Happy
Reply