How to connect Stackdriver to your smart home server for error logging

Nick Felker
Jun 13, 2018 · 5 min read

When integrating your smart home devices with the Google Assistant, you may have run into this error: “Couldn’t update the setting. Check your connection.”

A common error message reported in the Google Assistant settings

This error can stem from a number of reasons during the account linking and SYNC process.

To get better insight into these errors, you can use Stackdriver, Google Cloud’s logging system. When an error happens during account linking or the subsequent SYNC events, it is automatically logged and provides you with information.

Screenshot of error messages that may come from Stackdriver

The logs you receive are automatically cleaned to remove any Personally Identifiable Information (PII) and will not include a detailed trace.

To get started, you can navigate to the Google Cloud Console for your project and select the Logging option in the Stackdriver section of the navigation drawer:

You can filter by Google Assistant Action > All version_id to see errors specifically for your smart home fulfillment:

While this is handy, having to go to a separate page to view errors may not fit with your development workflow, and it may not present you with easily accessible data to include in a weekly stats report, for example. Let’s see how to export your logs from Stackdriver and into your infrastructure, letting you build additional integrations on top of this data.

Using StackDriver, you can set up a sink that will contain logs with a particular filter. The logs in this sink can be sent through Cloud Pub/Sub to an endpoint that you own.

Domain verification

Before you can push messages to an endpoint, you will need to verify that you own the domain. You can register it through the APIs & Services section in the Google Cloud Console.

Under Credentials > Domain Verification, add a domain. After adding your domain, you will be taken to the Google Search console. Follow the instructions there to finish verifying your website before proceeding:

Configure Pub/Sub

With Google Cloud Pub/Sub, you can configure tasks to be run on certain events such as when a new log appears in Stackdriver. By adding a filter, you can limit the types of logs that will trigger an event. You can configure a server endpoint to subscribe to these events.

To start exporting your SYNC errors, type in the filter “text:SYNC” and click the CREATE EXPORT button. Here, you can create a sink which connects to a Google Cloud Pub/Sub topic. This will enable you to handle an event each time a new log entry appears:

In the navigation drawer, open up the Pub/Sub overview and create a new subscription:

Here, you can create a new subscription. For the Delivery Type, enter the URL that you want to use to receive subscriptions. This has to be to a server that you own for purposes of domain verification:

On your server, you will need to add a handler for your receiving endpoint. In this example, it is /alerts/stackdriver. This is a webhook on your server. Cloud Pub/Sub will send a POST request to that URL with the log data in the request body. An implementation using Node.js is shown in the code snippet below:

Now we can test to see if this pub/sub topic works. In your smart home integration, set your SYNC response to return an invalid device type, such as LART. An example of this response can be seen in the code snippet below:

When you try to link your account, you will see an error in the Google Assistant settings and a corresponding error in StackDriver:

In your server, you will also see this error being logged. When you encounter this error, you can look at the SYNC response that you have sent and identify that the error has come from a typo in your device type. You can fix this error in your webhook by fixing the string where you return this device information. You can see the corrected code snippet below:

Once you start ingesting these errors, there are many things that you can do to improve the reliability of your smart home integration, such as adding email alerts or creating a dashboard of common issues. By identifying these problems early and getting detailed information about what is happening, you will be able to make changes faster and with greater confidence.

Google Developers

Engineering and technology articles for developers, written and curated by Googlers. The views expressed are those of the authors and don't necessarily reflect those of Google.

Nick Felker

Written by

Social Media Expert -- Rowan University 2017 -- IoT & Assistant @ Google

Google Developers

Engineering and technology articles for developers, written and curated by Googlers. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade