Samfox2 / homebridge-doorbell

Apache License 2.0
4 stars 4 forks source link

Modification to trigger the event #3

Closed brownad closed 7 years ago

brownad commented 7 years ago

Hi there,

I ran the doorbell alongside a DoorBird installation in HomeKit. It fires off when homebridge is restarted, successfully sending the image to iOS - only a single device for some reason, I have three connected, any ideas why it might hold back?

The accessory is seen as "Not Supported", I had used the config in your example over the one in the docs. Do I need to add the MAC address of the DoorBird?

I can't work out how the DoorBird event (pressing DoorBell) will push to this component, could you help describe please? Would there be a way to pass in the DoorBird notification call somehow?

Thanks

Samfox2 commented 7 years ago

At this time it is just a basic demo of a doorbell plugin. If you push the "identify" option in your app a message should be send to your connected iOS devices. For an aditional pic a homekit camera must be placed in the same room. For implementing a function that pushes the event please have a look at the homebridge-homematic plugin, as there is a doorbell implemented.

brownad commented 7 years ago

Thanks I'll look at homeatic plugin, saw that mentioned earlier.

Dumb q - but where is the "identify" button? Is this part of HK? I only saw the iOS events when restarting homebridge (that did look good!) The 'button' doesn't expose any switch options e.g. ProgrammableSwitchEvent in the app. Just shows as a component with the Home icon and "Not Supported", on selection "This accessory is not currently supported by the Home app" - is that right?

brownad commented 7 years ago

Also, is the mac address mentioned in the docs irrelevant?

Samfox2 commented 7 years ago

I removed the mac address as it is not used anymore. The identify command can be used to identify a device, e.g. a bulb can blink or a switch can beep so that the user can identify it (useful if you have many accessories of the same type). For testing purposes a doorbell ring is hardcoded to this command. The home app shows "Not Supported" for the doorbell but messages are working. Seems like the integration in home app is very basic at this stage.

brownad commented 7 years ago

:+1:

brownad commented 7 years ago

Would it be possible to extend this to have a endpoint configurable, and respond to a specific JSON value to then fire off the doorbell event as it would be normally? I would guess doorbird and others could use it.

On 6 Jan 2017, at 08:46, Samfox2 notifications@github.com wrote:

I removed the mac address as it is not used anymore. The identify command can be used to identify a device, e.g. a bulb can blink or a switch can beep so that the user can identify it (useful if you have many accessories of the same type). For testing purposes a doorbell ring is hardcoded to this command. The home app shows "Not Supported" for the doorbell but messages are working. Seems like the integration in home app is very basic at this stage.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Samfox2 commented 7 years ago

I did this with a curl command, we discussed it somewhere in homebridge issue: https://github.com/nfarina/homebridge/issues/506

I also posted the command somewhere in that issue. As modifiing an accessory from outside is deactivated by default, you have run homebridge in "insecure" mode as described there.

brownad commented 7 years ago

Ok that's useful, although I think I only need to GET status of doorbird endpoint and keep polling until the required value changes. Would that need insecure mode?

Samfox2 commented 7 years ago

No polling from the plugin would not need insecure mode. You just need to check (poll) the status of your doorbell and toggle state as I did in identify.

brownad commented 7 years ago

Hi

I forked your repo and made an initial start do give pointers if you can.

Thanks

Sent from my iPhone

On 10 Jan 2017, at 21:20, Samfox2 notifications@github.com wrote:

No polling from the plugin would not need insecure mode. You just need to check (poll) the status of your doorbell and toggle state as I did in identify.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

Samfox2 commented 7 years ago

Great.. just ask if there are any questions.

brownad commented 7 years ago

Hey @Samfox2 I made some initial changes on the fork, could you take a look.

Its polling the url which is provided in config, and looks for a response doorbell=1 //success doorbell pressed

what im trying to do is give it a small wait, and avoid being hammered if someone presses the doorbell. Then resume polling every 100ms or so. any suggestions on the approach?

https://github.com/brownad/homebridge-doorbird

RienduPre commented 7 years ago

Hi @brownad,

I tried your version but keep getting these errors: I hope you can figure out what is the cause.

==================== [2017-01-24 19:50:19] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-24 19:50:19] Error: Cannot find module 'request' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (/usr/local/lib/node_modules/homebridge-doorbird/index.js:2:15) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) [2017-01-24 19:50:19] ====================

brownad commented 7 years ago

I haven't finished it yet, was missing the dependencies in package json. Just bumped it now.

If you have time to pull it again and test I can see what needs to change and probably need some help from @samfox2

I tested the doorbird apis directly and that is sound but my setup needs some polish.

Sent from my iPhone

On 24 Jan 2017, at 18:51, RdP notifications@github.com wrote:

Hi @brownad,

I tried your version but keep getting these errors: I hope you can figure out what is the cause.

==================== [2017-01-24 19:50:19] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-24 19:50:19] Error: Cannot find module 'request' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/usr/local/lib/node_modules/homebridge-doorbird/index.js:2:15) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) [2017-01-24 19:50:19] ====================

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

RienduPre commented 7 years ago

The request error is solved, but now running into a new error:

/usr/local/lib/node_modules/homebridge-doorbird/index.js:49 this.httpRequest(this.url, "", "GET", this.username, this.password, function(error, response, responseBody) { ^

TypeError: this.httpRequest is not a function at DoorBirdAccessory.pollingtoevent.longpolling (/usr/local/lib/node_modules/homebridge-doorbird/index.js:49:14) at null._onTimeout (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/polling-to-event/index.js:77:5) at Timer.listOnTimeout (timers.js:92:15)

brownad commented 7 years ago

Yeah few more things to address sorry about that best to uninstall plugin for now

I'll get around to it

Sent from my iPhone

On 24 Jan 2017, at 19:53, RdP notifications@github.com wrote:

The request error is solved, but now running into a new error:

/usr/local/lib/node_modules/homebridge-doorbird/index.js:49 this.httpRequest(this.url, "", "GET", this.username, this.password, function(error, response, responseBody) { ^

TypeError: this.httpRequest is not a function at DoorBirdAccessory.pollingtoevent.longpolling (/usr/local/lib/node_modules/homebridge-doorbird/index.js:49:14) at null._onTimeout (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/polling-to-event/index.js:77:5) at Timer.listOnTimeout (timers.js:92:15)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

brownad commented 7 years ago

I made some changes to add some missing code. Nothing tested yet but if you're willing to review that might help

Sent from my iPhone

On 24 Jan 2017, at 19:53, RdP notifications@github.com wrote:

The request error is solved, but now running into a new error:

/usr/local/lib/node_modules/homebridge-doorbird/index.js:49 this.httpRequest(this.url, "", "GET", this.username, this.password, function(error, response, responseBody) { ^

TypeError: this.httpRequest is not a function at DoorBirdAccessory.pollingtoevent.longpolling (/usr/local/lib/node_modules/homebridge-doorbird/index.js:49:14) at null._onTimeout (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/polling-to-event/index.js:77:5) at Timer.listOnTimeout (timers.js:92:15)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

RienduPre commented 7 years ago

Hi,

Yes I just saw it and installed it, but new errors unfortunatelly.

[2017-01-25 18:51:44] --- [2017-01-25 18:51:44] ==================== [2017-01-25 18:51:44] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-25 18:51:44] SyntaxError: Unexpected token : at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-25 18:51:44] ====================

RienduPre commented 7 years ago

Tried the new code, new error :-(

[2017-01-26 12:57:15] --- [2017-01-26 12:57:15] ==================== [2017-01-26 12:57:15] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-26 12:57:15] ReferenceError: DoobBirdAccessory is not defined at Object. (/usr/local/lib/node_modules/homebridge-doorbird/index.js:93:1) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-26 12:57:15] ====================

Samfox2 commented 7 years ago

seems like there is a spelling error: DoorBirdAccessory not DoobBirdAccessory

RienduPre commented 7 years ago

Yes, Corrected it, and it loads now, but receive an error right after it.

[2017-01-26 13:17:26] Front Door is running on port 41385. /usr/local/lib/node_modules/homebridge-doorbird/index.js:50 this.log('DoorBird get status failed: %s', error.message); ^

TypeError: this.log is not a function at /usr/local/lib/node_modules/homebridge-doorbird/index.js:50:22 at Request._callback (/usr/local/lib/node_modules/homebridge-doorbird/index.js:104:3) at self.callback (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/request/request.js:186:22) at emitOne (events.js:77:13) at Request.emit (events.js:169:7) at Request.init (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/request/request.js:274:17) at new Request (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/request/request.js:128:8) at request (/usr/local/lib/node_modules/homebridge-doorbird/node_modules/request/index.js:54:10) at DoorBirdAccessory.httpRequest (/usr/local/lib/node_modules/homebridge-doorbird/index.js:94:4) at DoorBirdAccessory. (/usr/local/lib/node_modules/homebridge-doorbird/index.js:48:14)

Samfox2 commented 7 years ago

think you have to change the following:

self = this; <-- add this at the beginning of the function

change line 50 to the following: self.log('DoorBird get status failed: %s', error.message);

RienduPre commented 7 years ago

The function is now working, please adjust this in your code:

function DoorBirdAccessory(log, config) { self = this; this.log = log; this.name = config["name"]; this.username = config["doorbird_username"]; this.password = config["doorbird_password"]; this.ip = config["doorbird_ip"]; this.url = config["doorbird_url"]; this.binaryState = 0; // switch state, default is OFF this.log("Starting a homebridge-doorbird device with name '" + this.name + "'..."); this.service; this.timeout = 2;

var emitter = pollingtoevent(function(done) { this.httpRequest("http://" + this.ip + this.url + "?http-user=" + this.username + "&http-password=" + this.password, "", "GET", this.username, this.password, function(error, response, responseBody) { if (error) { self.log('DoorBird get status failed: %s', error.message); callback(error); } else {
done(null, responseBody); } }); }.bind(this), { longpolling:true });

brownad commented 7 years ago

done

doobird :( too

how does it look now?

RienduPre commented 7 years ago

New error

/usr/local/lib/node_modules/homebridge-doorbird/index.js:68 this.service.getCharacteristic(Characteristic.On).setValue(binaryState); ^

TypeError: Cannot read property 'setValue' of undefined at DoorBirdAccessory. (/usr/local/lib/node_modules/homebridge-doorbird/index.js:68:60) at Timer.listOnTimeout (timers.js:92:15)

brownad commented 7 years ago

was anything printed out around the state e.g. this.log("DoorBird doorbell state is currently ", binaryState);

brownad commented 7 years ago

i think I need to change this to self for

this.service.getCharacteristic(Characteristic.On).setValue(binaryState);

@Samfox2 is that correct?

RienduPre commented 7 years ago

Binarystate states "NaN"

brownad commented 7 years ago

Does the URL look right to you? I've changed it to remove the ? before the http-user and add & that looked wrong

brownad commented 7 years ago

Made a few more changes now, sorry this is rough... Looking at the future the Video Doorbell will be the way forward, but that's not in homebridge HAP yet.

RienduPre commented 7 years ago

New error again. Don't you test and get these errors

==================== [2017-01-26 16:11:45] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-26 16:11:45] SyntaxError: Unexpected token ) at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-26 16:11:45] ====================

brownad commented 7 years ago

Apologies, I am having to make changes on the fly - I do not have access to a setup environment. you're welcome to make a pull request. I wont get time to debug until late in the weekend.. sorry

brownad commented 7 years ago

There was a mistake which I've removed. Its only fair on @Samfox2 if we end the thread here and add to the fork. Its my issue at this point.

I am looking for help if you're looking to contribute. I think we can get this working but there will be a better plugin soon which will handle almost everything. That seems pending an iOS update too. Either way when I saw @Samfox2 example work it was quite a good experience to have a view on the doorbird.

brownad commented 7 years ago

Committed the changes now. Polling is a bit frequent. But gets the status correctly, you can see this in the logs.

What I'm not sure about is the call to setValue being right for the Characteristic or if this no longer works.

@samfox2 any ideas?

Sent from my iPhone

On 26 Jan 2017, at 15:13, RdP notifications@github.com wrote:

New error again. Don't you test and get these errors

==================== [2017-01-26 16:11:45] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-26 16:11:45] SyntaxError: Unexpected token ) at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-26 16:11:45] ====================

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

brownad commented 7 years ago

The last commits work for me now.

However I do run it as a task using pm2

Sent from my iPhone

On 26 Jan 2017, at 15:13, RdP notifications@github.com wrote:

New error again. Don't you test and get these errors

==================== [2017-01-26 16:11:45] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-26 16:11:45] SyntaxError: Unexpected token ) at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-26 16:11:45] ====================

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

brownad commented 7 years ago

@samfox2 can you suggest how to best reset after it has been called please?

It fires off on door press but remains in state

Sent from my iPhone

On 26 Jan 2017, at 15:13, RdP notifications@github.com wrote:

New error again. Don't you test and get these errors

==================== [2017-01-26 16:11:45] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-26 16:11:45] SyntaxError: Unexpected token ) at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-26 16:11:45] ====================

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

brownad commented 7 years ago

Try the latest update on my fork, uses motion sensor instead of doorbell does the same thing really.. until someone writes a nicer one

I've tested it and getting the updates

Hope it works for your doorbird

Sent from my iPhone

On 26 Jan 2017, at 15:13, RdP notifications@github.com wrote:

New error again. Don't you test and get these errors

==================== [2017-01-26 16:11:45] ERROR LOADING PLUGIN homebridge-doorbird: [2017-01-26 16:11:45] SyntaxError: Unexpected token ) at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:65:22) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:132:14) at Array.forEach (native) [2017-01-26 16:11:45] ====================

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

brownad commented 7 years ago

@RienduPre try my latest changes it's very stable now I moved over to the streaming api update your config as per example and it works on wifi and off wifi with the notifications on iOS every time I went for a motion sensor as a way to get around the doorbell not being supported anymore

Let me know if you have issues raise the. On my GH please

Thanks to @Samfox2 for starting me on this