|
1 |
| -# Actions on Google: Smart Home sample using Node.js |
| 1 | +# Cloud-to-cloud integrations: Smart Home sample using Node.js |
2 | 2 |
|
3 |
| -This sample contains a fully functioning example of a Smart Home provider |
4 |
| -cloud service designed to work with Actions on Google. This can be used with a |
5 |
| -Actions Console project to create an Action interface to your IoT devices. |
6 |
| -This sample includes everything you need to get started, including a mocked |
7 |
| -user authentication service with sample users and a user web portal to |
8 |
| -demonstrate the user experience when controlling their lights with your action. |
| 3 | +This sample project contains a fully functioning example of a Smart Home provider |
| 4 | +cloud service designed to work with Cloud-to-cloud integrations using Node.js. This can |
| 5 | +be used with a Google Home Developer Console project to create an integration to your IoT |
| 6 | +devices. See |
| 7 | +[Create a Cloud-to-cloud integration](https://developers.home.google.com/cloud-to-cloud/integration/create) |
| 8 | +for further information. |
9 | 9 |
|
10 |
| -An example of a Smart Home IoT cloud engine is written here. This project can be |
11 |
| -integrated with a web portal for an interactive experience. |
| 10 | +## Support |
12 | 11 |
|
13 |
| -## Setup Instructions |
| 12 | +- Stack Overflow: https://stackoverflow.com/questions/tagged/google-smart-home |
14 | 13 |
|
15 |
| -See the developer guide and release notes at [https://developers.google.com/assistant](https://developers.google.com/assistant) for more details. |
16 |
| - |
17 |
| -Clone the project and the included frontend as a subdirectory: |
18 |
| - |
19 |
| -``` |
20 |
| -git clone https://github.com/actions-on-google/smart-home-nodejs.git |
21 |
| -git clone https://github.com/actions-on-google/smart-home-frontend.git smart-home-nodejs/frontend |
22 |
| -cd smart-home-nodejs |
23 |
| -``` |
24 |
| - |
25 |
| -## Steps for testing with Google Assistant |
26 |
| - |
27 |
| -### Create and set up project in Actions Console |
28 |
| - |
29 |
| -1. Use the [Actions on Google Console](https://console.actions.google.com) to add a new project with a name of your choosing and click *Create Project*. |
30 |
| -1. Select *Home Control*, then click *Smart Home*. |
31 |
| - |
32 |
| -### Optional: Customize your action |
33 |
| - |
34 |
| -1. From the top menu under *Develop*, click on *Invocation*. |
35 |
| -1. Add your App's name. Click *Save*. |
36 |
| -1. From the top menu under *DEPLOY*, click on *Directory Information*. |
37 |
| -1. Add your App info, including images, a contact email and privacy policy. This information can all be edited before submitting for review. |
38 |
| -1. Click *Save*. |
39 |
| - |
40 |
| -### Add Request Sync and Report State |
41 |
| -The Request Sync feature allows a cloud integration to send a request to the Home Graph |
42 |
| -to send a new SYNC request. The Report State feature allows a cloud integration to proactively |
43 |
| -provide the current state of devices to the Home Graph without a `QUERY` request. These are |
44 |
| -done securely through [JWT (JSON web tokens)](https://jwt.io/). |
45 |
| - |
46 |
| -1. Navigate to the |
47 |
| -[Google Cloud Console API Manager](https://console.developers.google.com/apis) |
48 |
| -for your project id. |
49 |
| -1. Enable the [HomeGraph API](https://console.cloud.google.com/apis/api/homegraph.googleapis.com/overview). |
50 |
| -1. Navigate to the [Google Cloud Console API & Services page](https://console.cloud.google.com/apis/credentials) |
51 |
| -1. Select **Create Credentials** and create a **Service account key** |
52 |
| - 1. Create a new Service account |
53 |
| - 1. Use the role Service Account > Service Account Token Creator |
54 |
| -1. Create the account and download a JSON file. |
55 |
| - Save this as `src/smart-home-key.json`. |
56 |
| - |
57 |
| -### Configure Cloud Firestore |
58 |
| - |
59 |
| -1. Open your project in the [Firebase console](https://console.firebase.google.com/), and configure a Cloud Firestore database. |
60 |
| -1. Configure a `users` collection with a default user and a few default fields |
61 |
| - |
62 |
| -``` |
63 |
| - users\ |
64 |
| - 1234 |
65 |
| - fakeAccessToken: "123access" |
66 |
| - fakeRefreshToken: "123refresh" |
67 |
| - homegraph: false |
68 |
| -``` |
69 |
| - |
70 |
| -### Deploy to Firebase Cloud Functions and Hosting |
71 |
| - |
72 |
| -1. Run the following commands: |
73 |
| - |
74 |
| -``` |
75 |
| -npm install |
76 |
| -npm --prefix frontend install |
77 |
| -npm run deploy |
78 |
| -``` |
79 |
| - |
80 |
| -1. Open the web frontend URL. |
81 |
| -1. Configure the virtual devices shown as you please. Click the cloud icon shown |
82 |
| - above at least one of them to enable it for cloud control. |
83 |
| - |
84 |
| -### Start testing |
85 |
| - |
86 |
| -1. Navigate back to the [Actions on Google Console](https://console.actions.google.com). |
87 |
| -1. From the top menu under *Develop*, click on *Actions* (left nav). Click on *Add your first action* and choose your app's language(s). |
88 |
| -1. Enter the URL for fulfillment: [`PROJECT_ID`](https://firebase.google.com/docs/projects/learn-more#project-id)`.web.app/smarthome`. and click *Done*. |
89 |
| -1. On the left navigation menu under *ADVANCED OPTIONS*, click on *Account Linking*. |
90 |
| - 1. Select *No, I only want to allow account creation on my website*. Click *Next*. |
91 |
| - 1. For Linking Type, select *OAuth*. |
92 |
| - 1. For Grant Type, select 'Authorization Code' for Grant Type. |
93 |
| - 1. Under Client Information, enter the client ID and secret as defined `src/config-provider.ts`: |
94 |
| - * Client Id: `sampleClientId` |
95 |
| - * Client Secret: `sampleClientSecret` |
96 |
| - 1. The Authorization URL: [`PROJECT_ID`](https://firebase.google.com/docs/projects/learn-more#project-id)`.web.app/fakeauth` |
97 |
| -path. |
98 |
| - 1. The Token URL: [`PROJECT_ID`](https://firebase.google.com/docs/projects/learn-more#project-id)`.web.app/faketoken` |
99 |
| - 1. Click *Save*. |
100 |
| -1. On the left navigation menu under *Test*, click on *Simulator*, to begin testing this app. |
101 |
| - |
102 |
| -### Set up Account linking |
103 |
| - |
104 |
| -1. On a device with the Google Assistant logged into the same account used |
105 |
| -to create the project in the Actions Console, enter your Assistant settings. |
106 |
| -1. Click Home Control. |
107 |
| -1. Click the '+' sign to add a device. |
108 |
| -1. Find your app in the list of providers. |
109 |
| -1. Log in to your service. |
110 |
| -1. Start using the Google Assistant in the Actions Console to control your devices. Try saying 'turn my lights on'. |
111 |
| - |
112 |
| -:information_source: 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. |
113 |
| - |
114 |
| -## References & Issues |
115 |
| -+ Questions? Go to [StackOverflow](https://stackoverflow.com/questions/tagged/actions-on-google), [Assistant Developer Community on Reddit](https://www.reddit.com/r/GoogleAssistantDev/) or [Support](https://developers.google.com/assistant/support). |
116 |
| -+ For bugs, please report an issue on Github. |
117 |
| -+ Actions on Google [Documentation](https://developers.google.com/assistant) |
118 |
| -+ Actions on Google [Codelabs](https://codelabs.developers.google.com/?cat=Assistant). |
119 |
| - |
120 |
| -## Make Contributions |
121 |
| -Please read and follow the steps in the [CONTRIBUTING.md](CONTRIBUTING.md). |
| 14 | +If you've found an error in this sample, please file an issue: |
| 15 | +https://github.com/google-home/smart-home-nodejs/issues |
122 | 16 |
|
123 | 17 | ## License
|
124 | 18 | See [LICENSE](LICENSE).
|
125 | 19 |
|
126 | 20 | ## Terms
|
127 |
| -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](https://developers.google.com/terms/). |
| 21 | +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](https://developers.google.com/terms/). |
0 commit comments