beele / homebridge-unifi-protect-camera-motion

Camera & Motion sensor support for Unifi Protect cameras in Homekit via Homebridge
Apache License 2.0
103 stars 12 forks source link

Refactor camera logic to a more modern implementation #34

Closed JJJ closed 4 years ago

JJJ commented 4 years ago

When restarting Homebridge, the Homebridge log says "Please add" on each of the cameras, even if/when they've already been added. As a user, this makes it appear like the cameras were inadvertently removed and need to be re-added again.

[5/12/2020, 2:18:43 PM] [Unifi protect cameras & motion sensors] Motion checking setup done!
[5/12/2020, 2:18:46 PM] [Unifi protect cameras & motion sensors] Setup done
[5/12/2020, 2:18:46 PM] Camera (<snip>) is running on port 52100.
[5/12/2020, 2:18:46 PM] Please add [Camera (<snip>)] manually in Home app. Setup Code: <snip>
[5/12/2020, 2:18:46 PM] Camera (<snip>) is running on port 52101.
[5/12/2020, 2:18:46 PM] Please add [Camera (<snip>)] manually in Home app. Setup Code: <snip>
[5/12/2020, 2:18:46 PM] Camera (<snip>) is running on port 52102.
[5/12/2020, 2:18:46 PM] Please add [Camera (<snip>)] manually in Home app. Setup Code: <snip>
[5/12/2020, 2:18:46 PM] Camera (<snip>) is running on port 52103.
[5/12/2020, 2:18:46 PM] Please add [Camera (<snip>)] manually in Home app. Setup Code: <snip>

I'm not sure if there is an easy way to identify if specific cameras have already been added to HomeKit or not, but if it is in fact possible to do, I think some confirmation that each camera was found and does not need to be added would be a bit more reassuring.

beele commented 4 years ago

I'm not sure but I think this is also what homebridge-camera-ffmpeg does when you use that plugin.

beele commented 4 years ago

I've done some digging and these messages come from homebridge itself, not from the plugin. My code is based on homebridge-camera-ffmpeg (1.0.0) and that (and mine) uses an old way of adding camera's.

This is not very high on my backlog. If homebridge-camera-ffmpeg updates to the new way I'll port that over. If not I'll have a look at this myself somewhere in the future.

beele commented 4 years ago

39 related

beele commented 4 years ago

I've got the new camera setup implemented in a separate branch (no longer manually need to add cams). This will be in the next release

beele commented 4 years ago

Beta build available, this will require you to remove the old camera accessories as these will stop working!

sudo npm i -g --unsafe-perm=true homebridge-unifi-protect-camera-motion@0.4.0-Beta.7 And please check the adjusted readme on this branch for config changes: https://github.com/beele/homebridge-unifi-protect-camera-motion/tree/feature/rework-camera-and-tfjs

JJJ commented 4 years ago

this will require you to remove the old camera accessories as these will stop working!

Is that requirement going to persist even out of beta?

Deleting and re-adding cameras isn't particularly difficult, but it is relatively annoying, and in my experience I almost always have to re-setup all of their related automations.

I imagine some kind of migration from the old way to the new way would be the way to try and go?

beele commented 4 years ago

No it will be required to remove the old cameras (as they won’t work anymore) and the new ones are added automatically, they are not compatible so no migration

JJJ commented 4 years ago

I still have not tested this, but do intend to soon.

JJJ commented 4 years ago

I think it's working. 💫

I removed the cameras from HomeKit using the Home app, and confirmed they were gone.

I updated to the beta branch, and restarted Homebridge.

When I re-opened the Home app, the cameras had already magically been added back as devices, which is pretty darn neat!

beele commented 4 years ago

mostly done in: homebridge-unifi-protect-camera-motion@0.4.1-Beta.5 need to clean up logging and some minor stuff, but the main code changes are done

JJJ commented 4 years ago

Updated to 0.4.1-Beta.5 but now Homebridge is stuck in a startup loop with this error:

[7/24/2020, 14:03:55] [Unifi protect cameras & motion sensors] Initializing UnifiProtectMotion platform...
[7/24/2020, 14:03:55] [Unifi protect cameras & motion sensors] Configuring accessory Camera (Doorbell)
[7/24/2020, 14:03:55] TypeError: Cannot read property 'Switch' of undefined
    at Function.setupMotionSensor (/usr/local/lib/node_modules/homebridge-unifi-protect-camera-motion/src/characteristics/unifi-camera-motion-sensor.js:19:49)
    at UnifiProtectMotionPlatform.configureAccessory (/usr/local/lib/node_modules/homebridge-unifi-protect-camera-motion/src/unifi-protect-motion-platform.js:102:62)
    at /usr/local/lib/node_modules/homebridge/src/server.ts:307:25
    at Array.filter (<anonymous>)
    at Server.restoreCachedPlatformAccessories (/usr/local/lib/node_modules/homebridge/src/server.ts:270:69)
    at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:158:10)
    at cli (/usr/local/lib/node_modules/homebridge/src/cli.ts:80:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

I've rolled back to 0.4.0-Beta.7 successfully, and things are working again.

beele commented 4 years ago

homebridge-unifi-protect-camera-motion@0.4.1-Beta.7 should fix this (on my local machine this error does not occur because I have homebridge as a dev dependency)

JJJ commented 4 years ago

0.4.1-Beta.7 is working here.

I got this after restarting Homebridge in Status, which is new to me:

============================
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically,
install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node,
or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA)
at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
============================
jjj-sc-2020-07-27 at 14 15 04@2x
beele commented 4 years ago

That's a message that pops up sometimes but it shouldn't. It is actually using the C++ backend. Tensorflow and node is a pile of **** :(

beele commented 4 years ago

Implemented as per 0.4.1