This sample contains a fully functioning example of a Smart Home provider cloud service designed to work with Actions on Google. This can be used with a Actions Console project to create an Action interface to your IoT devices. This sample includes everything you need to get started, including a mocked user authentication service with sample users and a user web portal to demonstrate the user experience when controlling their lights with your action.
An example of a Smart Home IoT cloud engine is written here. This project can be integrated with a web portal for an interactive experience.
See the developer guide and release notes at https://developers.google.com/assistant for more details.
Clone the project and the included frontend as a subdirectory:
git clone https://github.com/actions-on-google/smart-home-nodejs.git
git clone https://github.com/actions-on-google/smart-home-frontend.git smart-home-nodejs/frontend
cd smart-home-nodejs
- Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
- Select Home Control, then click Smart Home.
- From the top menu under Develop, click on Invocation.
- Add your App's name. Click Save.
- From the top menu under DEPLOY, click on Directory Information.
- Add your App info, including images, a contact email and privacy policy. This information can all be edited before submitting for review.
- Click Save.
The Request Sync feature allows a cloud integration to send a request to the Home Graph
to send a new SYNC request. The Report State feature allows a cloud integration to proactively
provide the current state of devices to the Home Graph without a QUERY
request. These are
done securely through JWT (JSON web tokens).
- Navigate to the Google Cloud Console API Manager for your project id.
- Enable the HomeGraph API.
- Navigate to the Google Cloud Console API & Services page
- Select Create Credentials and create a Service account key
- Create a new Service account
- Use the role Service Account > Service Account Token Creator
- Create the account and download a JSON file.
Save this as
src/smart-home-key.json
.
- Open your project in the Firebase console, and configure a Cloud Firestore database.
- Configure a
users
collection with a default user and a few default fields
users\
1234
fakeAccessToken: "123access"
fakeRefreshToken: "123refresh"
homegraph: false
- Run the following commands:
npm install
npm --prefix frontend install
npm run deploy
- Open the web frontend URL.
- Configure the virtual devices shown as you please. Click the cloud icon shown above at least one of them to enable it for cloud control.
- Navigate back to the Actions on Google Console.
- From the top menu under Develop, click on Actions (left nav). Click on Add your first action and choose your app's language(s).
- Enter the URL for fulfillment:
PROJECT_ID
.web.app/smarthome
. and click Done. - On the left navigation menu under ADVANCED OPTIONS, click on Account Linking.
- Select No, I only want to allow account creation on my website. Click Next.
- For Linking Type, select OAuth.
- For Grant Type, select 'Authorization Code' for Grant Type.
- Under Client Information, enter the client ID and secret as defined
src/config-provider.ts
:- Client Id:
sampleClientId
- Client Secret:
sampleClientSecret
- Client Id:
- The Authorization URL:
PROJECT_ID
.web.app/fakeauth
path. - The Token URL:
PROJECT_ID
.web.app/faketoken
- Click Save.
- On the left navigation menu under Test, click on Simulator, to begin testing this app.
- On a device with the Google Assistant logged into the same account used to create the project in the Actions Console, enter your Assistant settings.
- Click Home Control.
- Click the '+' sign to add a device.
- Find your app in the list of providers.
- Log in to your service.
- Start using the Google Assistant in the Actions Console to control your devices. Try saying 'turn my lights on'.
ℹ️ Assistant will only provide you control over items that are registered, so if you visit your front end and click the add icon to create a device your server will receive a new SYNC command.
- Questions? Go to StackOverflow, Assistant Developer Community on Reddit or Support.
- For bugs, please report an issue on Github.
- Actions on Google Documentation
- Actions on Google Codelabs.
Please read and follow the steps in the CONTRIBUTING.md.
See LICENSE.
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.