Git Product home page Git Product logo

smart-home-java's Introduction

Actions on Google: Smart Home sample using Java

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.

Get the sample source files

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

Run the sample

Set up the Smart Home Action

  1. Use the Actions console to add a new project with a name of your choosing and click Create Project.
  2. Select Home Control, then click Smart Home.

Optional: Customize the Action

  1. From the top menu under Develop, click Invocation.
  2. Add your Action's name. Click Save.
  3. From the top menu under DEPLOY, click Directory Information.
  4. Add your Action info, including images, a contact email, and privacy policy. This information can all be edited before submitting for review.
  5. Click Save.

Add Request Sync and Report State support

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.

  1. Navigate to the Google Cloud Console API Manager for your project ID.
  2. Enable the HomeGraph API.
  3. Navigate to the Google Cloud Console API & Services page.
  4. Select Create Credentials and create a Service account key.
    1. Create a new Service account.
    2. Use the role Service Account > Service Account Token Creator.
  5. Create the account and download a JSON file. Save this as src/main/resources/smart-home-key.json.

Connect to Firebase

  1. Open your project in the Firebase console
  2. Select a Cloud Firestore database.
  3. 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.

Deploy backend to App Engine

  1. Run ./gradlew build
  2. Run ./gradlew appengineDeploy

Run frontend locally

  1. Set up the web frontend
cd frontend
npm install
npm run create-firebase-config
npm run serve
  1. Open the web frontend URL.
  2. Add new virtual devices and configure them as you please.
  3. Click the cloud icon to enable it for cloud control.

Start testing

  1. Navigate back to the Actions console.
  2. From the top menu under Develop, click on Actions (left nav). Click Add your first action and choose your app's language(s).
  3. Enter the URL for fulfillment and click Done.
    1. If using Google App Engine, the URL will be https://{project-id}.appspot.com/smarthome
  4. On the left navigation menu under ADVANCED OPTIONS, click on Account Linking.
    1. Select No, I only want to allow account creation on my website. Click Next.
    2. For Linking Type, select OAuth.
    3. For Grant Type, select Authorization Code for Grant Type.
    4. Under Client Information, enter the client ID and secret as defined below:
      • Client Id: sampleClientId
      • Client Secret: sampleClientSecret
  5. The Authorization URL is the hosted URL of your app with /fakeauth as the path
    1. If using Google App Engine, the URL will be https://{project-id}.appspot.com/fakeauth
  6. The Token URL is the hosted URL of your app with /faketoken as the path
    1. If using Google App Engine, the URL will be https://{project-id}.appspot.com/faketoken
  7. Enter any remaining necessary information you might need for authentication your app. Click Save.
  8. On the left navigation menu under Test, click on Simulator, to begin testing this app.

Set up account linking

  1. 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.
  2. Click Home Control.
  3. Click the '+' sign to add a device.
  4. Find your app in the list of providers.
  5. Log in to your service.
  6. Start using the Google Assistant on the mobile device to control your devices. Try saying 'turn my lights on'.

Get support and report issues

Contribute

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

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.

smart-home-java's People

Contributors

2m avatar fleker avatar kokoro-team avatar proppy avatar taycaldwell avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.