How to integrate the Smart Home API with your devices

As an Amazon Associate I earn from qualifying purchases.

Woodworking Plans Banner

JULIUS FULGENCIO:
Greetings, I'm Julius, and this video will go
over the Smart Home API and the steps needed to
integrate your device with it. Let's take a look at
the steps to integrate. After setting up
your OAuth server, your action must successfully
respond to a SYNC, QUERY, EXECUTE, and DISCONNECT intent. I will detail each
step within this video. Let's go. OAuth is an industry standard
that securely delegates access. Every Smart Home action
must include a mechanism for authenticating users. Google Smart Home only supports
OAuth with an authorization code flow, which
requires you to have two endpoints– the Authorization
and Token exchange endpoints. Google uses these
endpoints together to get permission
from your users to call these APIs
on their behalf. When a user successfully links
their accounts using OAuth, Google Assistant
triggers a SYNC intent. This will let Google
know all the devices and their capabilities,
also known as traits, linked for that individual
user as well as populate and/or update HomeGraph. Here is a sample request and
response for SYNC intent. Use SYNC Data Validator to
validate the SYNC response as the first step
of troubleshooting when you don't see devices
populate in HomeGraph.

This tool checks for bad
formatting and required attributes per trait,
but it does not check for required
traits per device type. Proactively triggering SYNC
improves a user experience when your action or user
configuration gets updated. Known as Request SYNC,
this API eliminates the need of the
user to relink when things change, like adding
or removing devices, or name changes. Request SYNC must be
implemented for certification. When a user asks
for the temperature of their thermostat, Google
Assistant sends a QUERY intent. Google Assistant will QUERY
on the behalf of the user to ensure reports
data is accurate.

A QUERY response will not
update HomeGraph like how Report State currently does. Here is a sample
request and response for QUERY intent for when the
user asked, is my light on. You can see the
response indicates the light is currently on. When the user requests an
action to be done on the device, Google Assistant sends
an EXECUTE intent to your fulfillment URL with
all the necessary parameters. When a user utters, for
example, turn on the lights, Google Assistant processes
this and determines which device the user is
trying to move into what state. We send this command
to the Developer Cloud to send to the user's device. Here's a sample request and
response for EXECUTE intent that occurs successfully. Here's an example of a failure. The user is trying to
change their brightness when the device is offline
and shown by the error code.

Returning error
codes and exceptions are helpful for users since they
will hear a TTS response back giving them an understanding why
the requests failed to execute. Here's an example of a follow-up
response to a user requesting to close a garage door. Since it takes time for
the door to fully close, Google will send
a unique follow-up token expecting the developer
to return back at the success or failure of the EXECUTE. While the command is
processing, return Pending State to prevent a timeout to occur. Once the EXECUTE finishes,
return a follow-up response with the follow-up
token attached. Developers can also implement
non-blocking exceptions. In this case, a user
tries to lock the door and the batteries are
low on the device.

The response is still a
success since the state changes to "isLocked" is true. The DISCONNECT
intent is important since it notifies a
developer that the user is no longer linked. This event should
also go hand in hand with terminating state pushes
to HomeGraph for the devices linked to that user. This has been the
steps to integrate your devices with Google
using the Smart Home API. Check out the links
in the description below for more information. Thanks for watching..

As an Amazon Associate I earn from qualifying purchases.

You May Also Like

About the Author: tech