This sample contains a fully functioning example of a Smart Home provider cloud service. This sample is intended to be used together with a Smart Home project you create in the Actions console, to demonstrate how to integrate smart devices with the Google Assistant.
This sample includes the following features to help you get started:
- Fulfillment backend for Smart Home Action.
- Mocked user authentication backend which comes prepopulated with sample users.
- Web frontend with an interactive experience for users to control smart devices.
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-java.git
cd smart-home-java
git clone https://github.com/actions-on-google/smart-home-frontend.git
- Use the Actions console to create a new project by clicking New Project.
- Enter a name of your choosing in the text box and click Create Project.
- Select the Smart Home, then click Start Building.
- From the top menu under Develop, click Invocation.
- Add your Action's name. Click Save.
- From the top menu under DEPLOY, click Directory Information.
- Add your Action 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 your cloud integration to send a request to Home Graph to
send a new SYNC request. The Report
State
feature allows your cloud integration to proactively provide the current state of
devices to Home Graph without a QUERY
request.
- 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 > Service account.
- Provide a name for the service account and click Create and continue.
- Select the role Service Account Token Creator and click Continue.
- Click Done.
- Create a key for the service account key account, and download the JSON file.
- Click the pencil icon beside the newly created service account.
- Select Keys > Add Key > Create new key.
- Create JSON key and save the file as
src/main/resources/smart-home-key.json
.
- Open your project in the Firebase console.
- Select Build > Firestore database.
- Create a new database by clicking Create database.
- Select the appropriate security rules for your database and click Next (We recommend using test mode for development, and updating your rules to production mode later.).
- Select a Firestore location from the dropdown and click Enable.
- From the data tab, select Start collection to configure a
users
collection with a default user and a few default fields
users\
1234
fakeAccessToken: "123access"
fakeRefreshToken: "123refresh"
homegraph: false
Note: If you are not using Google App Engine to host your server, but still want to integrate with Firestore:
- Set the
GOOGLE_CLOUD_PROJECT
environment variable to the name of the Firebase project. - Read this guide on setting up the Firebase Admin SDK.
- Run
./gradlew build
- Run
./gradlew appengineDeploy
- Set up the web frontend
cd frontend
npm install
npm run create-firebase-config
npm run serve
- Open the web frontend URL.
- Add new virtual devices and configure them as you please.
- Click the cloud icon to enable it for cloud control.
- Navigate back to the Actions console.
- From the top menu under Develop, click on Actions (left nav). Click Add your first action and choose your app's language(s).
- Enter the URL for fulfillment and click Done.
- If using Google App Engine, the URL will be https://{project-id}.appspot.com/smarthome
- 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 below:
- Client Id:
sampleClientId
- Client Secret:
sampleClientSecret
- Client Id:
- The Authorization URL is the hosted URL of your app with
/fakeauth
as the path- If using Google App Engine, the URL will be https://{project-id}.appspot.com/fakeauth
- The Token URL is the hosted URL of your app with
/faketoken
as the path- If using Google App Engine, the URL will be https://{project-id}.appspot.com/faketoken
- Enter any remaining necessary information you might need for authentication your app. Click Save.
- On the left navigation menu under Test, click on Simulator, to begin testing this app.
- On a mobile 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 on the mobile device to control your devices. Try saying 'turn my lights on'.
- Questions? Go to StackOverflow, Assistant Developer Community on Reddit, or Support.
- For bugs, please report an issue on Github.
- Smart Home Documentation
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.