Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Doorbell Service for Nest Hello #61

Closed
wants to merge 12 commits into from

Conversation

leoneleone
Copy link

This is an attempt to add the Doorbell Service for the Nest Hello based on this.device.last_event.has_person.
I'm not a coder so if anyone can help out that can be great.
If "this.device.last_event.has_person" can trigger a Doorbell Accessory in HomeKit reliably, in conjunction with KhaosT's homebridge-nest-cam plugin, then the Nest Hello Doorbell can function as a Doorbell and Motion Sensor - The video part of Video Doorbell would be handled by homebridge-nest-cam (as long as the two Accessories are placed in the same HomeKit Room).

** It may be that this.device.last_event.has_person is a unreliable event to simulate a Doorbell press.
Nest needs to update their API with support for doorbell press event.

This is an attempt to add the Doorbell Service for the Nest Hello based on this.device.last_event.has_person.
I'm not a coder so if anyone can help out that can be great. 
If "this.device.last_event.has_person" can trigger a Doorbell Accessory in HomeKit reliably, in conjunction with KhaosT's homebridge-nest-cam plugin, then the Nest Hello Doorbell can function as a Doorbell and Motion Sensor - The video part of Video Doorbell would be handled by homebridge-nest-cam (as long as the two Accessories are placed in the same HomeKit Room).
@leoneleone leoneleone closed this Aug 11, 2018
@leoneleone leoneleone reopened this Aug 11, 2018
Copy link
Owner

@chrisjshull chrisjshull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

From your description, it sounds like you aren't sure if this is going to work well. Have you been able to test this with your home setup? (If not, would you like assistance doing that?) I'd like to at least know it works for one person before merging. :)


const formatDoorbellDetectionState = function(val) {
if (val) {
return "true";//return "0";(Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS = 0;)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray comment to clean up?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven’t managed to test it out yet so this comment in particular is just a reminder for me to try if Characteristic.ProgrammableSwitchEvent doesn’t fire.

**More importantly, the comment before that should have been a TODO comment, sorry.

I’m trying to write a line of code that adds a (constant) DoorbellSrv to the NestCamAccessory only if the nest device.long_name contains “Nest Hello”, or simply the word “Hello”. My Nest Hello “long_name” is formatted as “Front Door (Nest Hello)”.
This is to avoid the other Nest cams populating with HomeKit Doorbell Services.
I believe that’s all that missing from my code. Then I’ll be able to test.

If you can help me write a line of code which helps limit creating a HomeKit Doorbell.Service to only the Nest Hello I can test it asap and report back with results.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the absence for an official Nest API which supports Doorbell Press events, perhaps a rule that limits the Characteristic.ProgrammableSwitchEvent to trigger only when all Nest last_events return a true value. Ex: if “has_sound” + “has_motion” + “has_person” = true, then trigger HomeKit Characteristic.ProgrammableSwitchEvent.

Again, my coding skills are lacking to implement this. So your help is much appreciated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: how to only do this for Doorbells: you could add a section to the config which requires someone to specify the name or ID of their doorbell, and then check against that. (More user work, but no guessing.)

Re: synthesizing a Doorbell Press event: I don't have a Nest Hello, so I recommend you play with what combination of values is most reliable.

Re: how to code the event, see inline comment.

Copy link
Author

@leoneleone leoneleone Aug 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisjshull

  1. Less user work is best in my opinion. Most Nest Hello users would logically have the words "Nest Hello", "Hello", or the word "Door" as part of the Nest Hello this.device.long_name string.
    Please have a look at the changes I've made:
if (this.device.long_name = 'Nest Hello') {
    const doorbellSvc = this.addService(Service.Doorbell);
  this.bindCharacteristic(doorbellSvc, Characteristic.ProgrammableSwitchEvent, "Doorbell",
    getDoorbellDetectionState.bind(this), null, formatDoorbellDetectionState.bind(this));
  }

is there any way to refine this?
??
if (this.device.long_name = str.includes("Nest Hello")) {
??
I'm trying to avoid having to add anything to the config.

  1. Synthesizing a Doorbell Press Event:
return this.device.last_event &&
        this.device.last_event.has_person &&
        this.device.last_event.has_motion &&
        this.device.last_event.has_sound &&
        !this.device.last_event.end_time;

Does this seem correct to you? I believe a combination of all last_events, or simply a combination of has_person + has_sound will work. The Nest Hello always makes a "ding dong" sound outside the door where the Nest Hello is placed (there is no way to turn that button press sound off currently). So has_person + has_sound could work to synthesize a Hello button press.

  1. Coding for "formatDoorbellDetectionState" done.

Let me know what you think and I'll test this evening. I want to get the coding right before testing so I don't mess up my HomeKit setup by making too many changes to my Homebridge server 😉

!this.device.last_event.end_time;
};

const formatDoorbellDetectionState = function(val) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the formatting function is just for logging. return whatever string you want.

what you want, I think, is to return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS from getDoorbellDetectionState if you think it's been pressed ... and otherwise undefined (maybe, this is really hard to know without having a Hello to test with)

Copy link
Author

@leoneleone leoneleone Aug 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🙂

I do have a Nest Hello installed!!

Just want to get to coding right "in theory" then I'll load the changes onto my Homebridge Server. The homebridge-nest plugin is running on my main Homebridge Pi so I don't want to be fiddling with the code too much. That usually ends up in me having to delete my current Home and setup everything from scratch again.

*Service.Doorbell - create a Doorbell Service only if this.device.long_name contains "Nest Hello" (or the word "Door"??)
Note: Doorbell Service does not appear as an Accessory in  Home.app

**Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS - simulated Nest Hello button press, only if last_even.has_person + last_event.has_motion + last_event.has_sound all return a value of "true". **this combination needs to be tested for reliable Hello Button press simulation.
@leoneleone
Copy link
Author

@chrisjshull
Have you had a look at my most recent changes? Are there any obvious errors in my coding you can spot?
Thanks

if (this.device.long_name = str.includes("Hello")) {
    const doorbellSvc = this.addService(Service.Doorbell);
this.device.name_long
@chrisjshull
Copy link
Owner

@leoneleone
Copy link
Author

“Allow edits from maintainers” is already ticked for this pull request.

Copy link
Author

@leoneleone leoneleone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

Copy link
Author

@leoneleone leoneleone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

leoneleone and others added 8 commits August 14, 2018 11:18
TODO: Characteristic.Away will be replaced by ONE HomeKit Occupancy Sensor for the entire Nest.structure.away
with 2 additional Characteristics to control Home/Away toggle:

this.addCharacteristic(Characteristic.OccupancyDetected); - Read Only Nest.structure.away Status
*** this.addCharacteristic(Characteristic.SecuritySystemCurrentState); - addedCharacteristic to Service.OccupancySensor
*** this.addCharacteristic(Characteristic.SecuritySystemTargetState); - addedCharacteristic to Service.OccupancySensor
Copy link
Owner

@chrisjshull chrisjshull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the tweak I was suggesting. Let me know how it goes.

@@ -0,0 +1,109 @@
/**
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did this file come from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m testing something out
#64

@leoneleone
Copy link
Author

@chrisjshull
https://nestdevelopers.io/t/how-to-get-the-nest-hello-camera-button-press-event/1516/2

Any idea how to incorporate GCM Google Cloud Messaging or FCM Firebase Cloud Messaging into the plugin? It appears that is the only current way to incorporate Nest Hello Doorbell Press in the plugin.
The Doorbell press notification is sent as a message to the Cloud Messaging service associated with the Nest account.

@adriancable
Copy link
Collaborator

Closing since this is old, and unfortunately there is still no way to detect a doorbell press event via the Nest API. Seems that this event is shared only over Bluetooth and the API doesn't know about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants