Actions on Google: Java Smart Home Sample
This sample to help you get started quickly with the Java smart home library for Actions on Google.
See the developer guide and release notes at https://developers.google.com/assistant for more details.
All smart home intents are located inside the
MySmartHomeApp class which extends
Specifically, there are four intents that must be implemented:
- Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
- Click Home Control, then click Smart Home.
- From the top menu under Develop, click on Invocation (left nav).
- Add your App's name. Click Save.
Optionally, you can add directory information as well:
- From the top menu under Deploy, click on Directory Information (left nav).
- Click Save.
This projects uses a collection of HttpServlets and extends the
SmartHomeApp class to receive
requests both from the frontend application and the Google Assistant platform.
To fully utilize the features of this project, including the Report State API, you must setup
- Navigate to the Google Cloud Console API & Services page
- Be sure you are currently inside your project (view dropdown on the top of the page)
- Select Create Credentials and create a Service account key
- Create the account and download a JSON file.
Save this as
- 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, e.g. https://xyz123.appspot.com/smarthome, click Done.
- From the top menu under Develop, click on Account Linking (left nav).
- 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 from earlier.
- The Authorization URL is the hosted URL of your app with '/fakeauth' as the
path, e.g. https://xyz123.appspot.com/fakeauth
- The Token URL is the hosted URL of your app with '/faketoken' as the path,
- 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.
Setup Account linking
- 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'.
- (Optional) You can also follow the setup for a local frontend to test adding and testing devices
here: git clone https://github.com/actions-on-google/smart-home-frontend.git
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.
Connect to Firebase
- 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 that match exactly:
Note: If you are not using Google App Engine to host your server, but still want to
integrate with Firestore:
GOOGLE_CLOUD_PROJECT environment variable to the name of the Firebase project.
- read this guide on setting up the Firebase Admin SDK.
When a new project is created using the Actions Console, it also creates a Google Cloud project in the background.
Copy the name of this project from the Action Console project settings page.
Build for Google Cloud Platform
- Instructions for Google Cloud App Engine Standard Environment
- Use gcloud CLI to set the project to the name of your Actions project. Use 'gcloud init' to initialize and set your Google cloud project to the name of the Actions project.
- Deploy to App Engine using Gradle by running the following command:
gradle appengineDeploy. You can do this directly from
IntelliJ by opening the Gradle tray and running the appEngineDeploy task. This will start the process to deploy the fulfillment code to Google Cloud App Engine.
For more detailed information on deployment, see the documentation.
References & Issues
How to make contributions?
Please read and follow the steps in the CONTRIBUTING.md.
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.