Google Nest Logo

Google Doorbell

Getting notified about Google Doorbell Chime event in Discord group channel

This integration will allow you to flexibly get notified in the right channel when someone is at your door so you can then remotely unlock the door with Kisi if you are authorized to do so.

This example shows how to forward the Google Doorbell to Discord, but it will work in a similar way with Microsoft Teams, Slack, or other communication tools.

Prerequisite:

  1. A physical Google Nest Doorbell (battery)
  2. A Google account
  3. A Discord account

1. Getting started

Google Device Access program allows users to access, control, and manage Google Nest devices using the SDM API.

To get started with Device Access, you need to complete the following tasks:

  • Register for the Device Access program.
  • Activate a supported Nest device with a Google account.
  • Create a GCP project to enable the SDM API and get an OAuth 2.0 client ID.
  • Create a Device Access project to receive a Project ID.

Kindly refer to Google documentation here on how to achieve the above.

Screenshot of Google Device Access Console

2. Link your Google account and Google Device Access project

To view structures and devices, you must link a Google account to your Device Access project using the PCM. PCM allows the user to grant permission to allow developers to access their structures and device data. Google has provided comprehensive steps on how to achieve this here.

3. Enable Subscription to Events

Events are asynchronous and managed by Google Cloud Pub/Sub, in a single topic per Project. Events provide updates for all devices and structures and receipt of events is assured as long as the access token is not revoked by the user and the event messages have not expired. Steps to subscribe to events are listed here.

4. Subscribe to events

Subscribe to ‘sdm.devices.traits.DoorbellChime’ events.

This trait belongs to any device that supports a doorbell chime and related press events. The chime event of a Google Nest Doorbell is a read only event. The only way to initiate this action is to physically press the doorbell. The payload will be of the form:

{
"eventId" : "544c2908-6b92-4ac5-b961-95207ca055d0",
"timestamp" : "2019-01-01T00:00:01Z",
"resourceUpdate" : {
"name" : "enterprises/project-id/devices/device-id",
"events" : {
"sdm.devices.events.DoorbellChime.Chime" : {
"eventSessionId" : "CjY5Y3VKaTZwR3o4Y19YbTVfMF...",
"eventId" : "DWNzHmF1TMav3cJFSAf_i5s1qw..."
}
}
}
"userId" : "AVPHwEuBfnPOnTqzVFT4IONX2Qqhu9EJ4ubO-bNnQ-yi",
"eventThreadId" : "d67cd3f7-86a7-425e-8bb3-462f92ec9f59",
"eventThreadState" : "STARTED",
"resourceGroup" : [
"enterprises/project-id/devices/device-id"
]
}

5. Create Discord Webhook

  • Open the server settings in Discord and navigate to the integrations tab.
Screenshot of how to navigate to the integrations tab in Discord
  • Click on “New Webhook” if you have previous webhooks or “Create Webhook” in case this is your first webhook.
    • You’ll be able to:
      • Customize the avatar
      • Choose what channel to receive the webhook messages
      • Name the webhook
Screenshot of setting a Google Chime Webhook on Discord
  • Copy the webhook url, the webhook url is in the form: https://discord.com/api/webhooks/1044978160875352165/s3b……
  • We want to send a message with the content “The doorbell has been pressed” to the webhook url anytime the doorbell is pressed.

6. Gcloud emulator environment

Before we write our application, we need to ensure we are working in an installed google cloud (gcloud) emulator environment. If you don’t have this already, you can install gcloud SDK from the official website here.

  • To initialize the gcloud environment, login with the command:
    • gcloud init
  • Install the pub/sub component emulator for gcloud in your local environment
    • gcloud components install pubsub-emulator
  • To get started with Google pubsub service, run the command
    • gcloud beta emulators pubsub start --project=pubsubdemo --host-port=localhost:8085
  • The pseudo-code to achieve this functionality is below:

const WEBHOOK_URL = "YOUR_DISCORD_WEBHOOK_URL";


function listenForMessages(){
// listen for message from your event subscription
subscription.on('message', ()=>{
//Sends a doorbell pressed information message
hook.info('The doorbell has been pressed');
}
}

sendDiscordNotification()

A full snippet on this functionality has been written in JavaScript and can be found in this GitHub gist.

  • A message will be sent to Discord every time the doorbell is pressed.
Screenshot of a Google Chime Bot Discord notification for doorbell being pressed