Skip to content

Commit

Permalink
Merge branch 'feature/rework-camera-and-tfjs'
Browse files Browse the repository at this point in the history
  • Loading branch information
beele committed Aug 2, 2020
2 parents 6a44356 + 86e7642 commit 2269c9d
Show file tree
Hide file tree
Showing 56 changed files with 4,461 additions and 41,313 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ resources/test-config/persist/
resources/test-config/unifi-protect-google-settings.json

.idea/

.DS_Store
8 changes: 7 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
.idea
*.iml
.git/
.github/
.travis.yml
jest.config.js
tsconfig.json
*.ts
*.js.map

dist/
tests/
coverage/
resources/test-config
resources/tfjs-arm
resources/images/readme/*
resources/test.jpg
src/experimental
66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ This plugin will automatically discover all of the Unifi Protect cameras from yo

# Motion Events
Motion is detected by the Unifi Protect API and is used to generate a Motion Event in Homekit. This plugin can use one of two methods to generate these events:
- The "score" of the Unifi Protect motion event
- The "score" plus additional object detection step by use of a Tensorflow model. This logic/model runs on-device, and no data is ever sent to any online/external/cloud source or service. It is based on [this](https://github.com/tensorflow/tfjs-models/tree/master/coco-ssd) project.
- The basic method: The "score" of the Unifi Protect motion event (which currently has a bug and is 0 as long as the motion is occurring!)
- The advanced method: Object detection by use of a Tensorflow model. This logic/model runs on-device, and no data is ever sent to any online/external/cloud source or service. It is based on [this](https://github.com/tensorflow/tfjs-models/tree/master/coco-ssd) project.

# Installation:
Before installing this plugin, please make sure all of the prerequisites are completely first.
Expand All @@ -25,8 +25,11 @@ First, this plugin requires node-canvas:
- install: `sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev`
- Mac OS:
- install via homebrew: `brew install pkg-config cairo pango libpng jpeg giflib librsvg`
- Linux:
- install g++: `sudo apt install g++`
- Other OSes:
- [See the node-canvas documentation](https://github.com/Automattic/node-canvas#compiling)
- [See the node-gyp documentation](https://github.com/nodejs/node-gyp) => install any dependencies for your OS!

Next, to install this plugin simply type:

Expand All @@ -45,28 +48,38 @@ Next, open the `config.json` that contains your Homebridge configuration, and ad
"controller_rtsp": "rtsp://protect-ip:controller-rtsp-port",
"username": "username",
"password": "password",
"excluded_cameras": [
"id-of-camera-to-exclude-1",
"id-of-camera-to-exclude-2"
],
"motion_interval": 5000,
"motion_repeat_interval": 30000,
"motion_score": 50,
"motion_score": 0,
"enhanced_motion": true,
"enhanced_motion_score": 50,
"enhanced_classes": ["person"],
"debug": false,
"enable_motion_trigger": true,
"enable_doorbell_for": [
"id-of-camera-to-act-as-doorbell-1",
"id-of-camera-to-act-as-doorbell-1"
],
"save_snapshot": true,
"upload_gphotos": false
"upload_gphotos": false,
"debug": false,
"debug_network_traffic": false,
},
"videoConfig": {
"vcodec": "h264_omx",
"audio": true,
"maxStreams": 2,
"maxWidth": 1024,
"maxHeight": 576,
"maxFPS": 15,
"mapvideo": "0:1",
"mapaudio": "0:0",
"maxBitrate": 3000,
"packetSize": 376,
"additionalCommandline": "-protocol_whitelist https,crypto,srtp,rtp,udp"
"vcodec": "h264",
"audio": true,
"maxStreams": 2,
"maxWidth": 1920,
"maxHeight": 1080,
"maxFPS": 15,
"mapvideo": "0:1",
"mapaudio": "0:0",
"maxBitrate": 3000,
"packetSize": 188,
"additionalCommandline": "-protocol_whitelist https,crypto,srtp,rtp,udp -loglevel verbose"
}
}
```
Expand All @@ -77,6 +90,9 @@ The config must be valid or Homebridge will fail to restart correctly.

If you are using Homebridge Config X, it will do its best to alert you to any syntax errors it finds.

If you are upgrading from a pre 0.4.1 version please note that your camera's will be added in automatically by the plugin from now on.
This means that the old camera's need to be removed as these will no longer work.
Tap on a camera preview to open the camera feed, click the settings icon and scroll all the way to the bottom, there select `Remove camera from home`.

## Config fields:

Expand All @@ -92,19 +108,23 @@ If you are using Homebridge Config X, it will do its best to alert you to any sy
### Unifi config fields:
|Field|Type|Required|Default value|Description|
|-----|----|--------|-------------|-----------|
|controller|string|yes|/|Contains the URL to the CloudKey or UDM with UnifiOS, or as legacy the URL to the Unifi Protect web UI, including port (no / at the end)|
|controller|string|yes|/|Contains the URL to the CloudKey or UDM with UnifiOS, or as legacy the URL to the Unifi Protect web UI, including port (no / or /protect/ at the end!)|
|controller_rtsp|string|yes|/|Contains the base URL to be used for playing back the RTSP streams, as seen in the RTSP configuration (no / at the end)|
|username|string|yes|/|Contains the username that is used to login in the web UI|
|password|string|yes|/|Contains the password that is used to login in the web UI|
|excluded_cameras|no|string[]|[]|An array that contains the IDs of the cameras which should be excluded from the enumeration in Homekit, all available IDs are printed during startup|
|motion_interval|number|yes|/|Contains the interval in milliseconds used to check for motion, a good default is 5000 milliseconds|
|motion_repeat_interval|number|no|/|Contains the repeat interval in milliseconds during which new motion events will not be triggered if they belong to the same ongoing motion, a good default is 30000 to 60000 milliseconds. This will prevent a bunch of notifications for events which are longer than the motion_interval! Omit this field to disable this functionality|
|motion_score|number|yes|/|Contains the minimum score in % that a motion event has to have to be processed, a good default is 50%|
|motion_score|number|yes|/|Contains the minimum score in % that a motion event has to have to be processed, a good default is 50%, set this to 0 when using enhanced motion!|
|enhanced_motion|boolean|yes|/|Enables or disables the enhanced motion & object detection detection with Tensorflow|
|enhanced_motion_score|number|sometimes|/|This field is required if the `enhanced_motion` field is set to true and contains the minimum score/certainty in % the enhanced detection should reach before allowing an motion event to be triggered |
|enhanced_classes|string[]|sometimes|[]|This field is required if the `enhanced_motion` field is set to true and contains an array of classes (in lowercase) of objects to dispatch motion events for. The array should not be empty when using the enhanced detection! Look in look in src/coco/classes.ts for all available classes|
|debug|boolean|no|false|Contains a boolean indicating whether or not to enable debug logging for the plugin and FFmpeg|
|enable_motion_trigger|boolean|no|false|Contains a boolean that when set to true will enable an extra button for each camera to manually trigger a motion notification|
|enable_doorbell_for|string[]|no|[]|Contains the id of the camera's for which the doorbell functionality should be enabled, all available IDs are printed during startup|
|save_snapshot|boolean|no|false|Contains a boolean indicating whether or not to save each detection to a jpg file in the `.homebridge` directory. When using enhanced mode the image is annotated with the class/score that was detected.|
|upload_gphotos|boolean|no|false|Contains a boolean indicating whether or not to upload each detection to a google photos album. When using enhanced mode the image is annotated with the class/score that was detected.|
|debug|boolean|no|false|Contains a boolean indicating whether or not to enable debug logging for the plugin and FFmpeg|
|debug_network_traffic|boolean|no|false|Contains a boolean indication whether or not to enable logging of all network requests|

### Google Photos config:

Expand Down Expand Up @@ -186,17 +206,17 @@ The enumerated cameras (and the motion sensors) will not show up automatically,

- Running this plugin on CPUs that do not support AVX (celerons in NAS, ...) is not supported because there are no prebuilt Tensorflow binaries. Compiling Tensorflow from scratch is out of scope for this project!
- Run it on a RBPI or MacOS/Windows/Linux (Debian based)
- Previews in notifications are requested by the Home app, and can thus be "after the fact" and show an image with nothing of interest on it.
- The actual motion detection is done with the snapshot that is requested internally.
- ~~Previews in notifications are requested by the Home app, and can thus be "after the fact" and show an image with nothing of interest on it.~~
- ~~The actual motion detection is done with the snapshot that is requested internally.~~
- Unifi Protect has a snapshot saved for every event, and there is an API to get these (with Width & Height) but the actual saved image is pretty low res and is upscaled to 1080p. Using the Anonymous snapshot actually gets a full res snapshot (better for object detection).
- There is no way to know what motion zone (from Unifi) a motion has occurred in. This information is not present is the response from their API.
- The enhanced object detection using CoCo is far from perfect and might not catch all the thing you want it to.

### TODOs:

- Add more unit and integration tests
- Upgrade tfjs-node, now held back because newer versions [will not install correctly on RBPI](https://github.com/tensorflow/tfjs/issues/3052)
- ~~Implement required changes to make this work with Unifi OS (In progress)~~
- Implement required changes to make this work with Unifi OS (In progress)
- ~~Upgrade tfjs-node, now held back because newer versions~~ (Fix in beta)
- ~~Figure out how to get higher res streams on iPhone (only iPad seems to request 720p streams)~~ (Not possible)
- ~~Extend documentation & wiki~~ (Done)

Expand Down
Loading

0 comments on commit 2269c9d

Please sign in to comment.