There are a number of different third party services such as IFTTT, Blynk, etc that offer to integrate your DIY smart devices with Google Assistant. With such integrations, the full potential of either the device or the Assistant cannot be tapped into.
Here I will demonstrate an easy way to integrate your smart devices with Google Assistant with a Firebase backend.
How toRefer to the video below for step by step guidelines.
Note: You can run this either on a Raspberry Pi or a Windows device, as a matter of fact on any device. If you are performing the installation on windows, do not use the "sudo" in the commands.
- Go to the Actions on Google Developer Console.
- Click New Project, enter a name for the project, and click CREATE PROJECT.
- Select the Smart Home App.
- On the Overview screen in the Actions console, select Smart home.
- Choose the Smart home experience card, and you will then be directed to your project console.
- Download and install Node.js from https://nodejs.org/en/download/.
- To install the firebase CLI, run the following npm command from the terminal:
sudo npm install -g firebase-tools
- To verify that the CLI has been installed correctly, run:
firebase --version
- Authorize the Firebase CLI with your Google account by running:
firebase login
- Install git and clone the project using:
sudo apt-get install git
git clone https://github.com/shivasiddharth/google-actions-smarthome
Change directory using:
cd /google-actions-smarthome/smarthome-control/functions/
- 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 in the functions folder as smart-home-key.json
- Connect to firebase using:
firebase use <project-id>
- Deploy firebase using:
sudo npm install
firebase deploy
- In the Actions console under Overview > Build your Action, select Add Action(s). Enter the URL for your cloud function that provides fulfillment for the smart home intents and click Save.
https://us-central1-<project-id>.cloudfunctions.net/smarthome
- On the Develop > Invocation tab, add a Display Name for your Action, and click Save. This name will appear in the Google Home app.
To enable Account linking, select the Develop > Account linking option in the left navigation. Use these account linking settings:
Client ID : ABC123
Client secret : DEF456
Authorization URL : https://us-central1-<project-id>.cloudfunctions.net/fakeauth
Token URL : https://us-central1-<project-id>.cloudfunctions.net/faketoken
- Click Save to save your account linking configuration, then click Test to enable testing on your project.
- On your phone, open the Google Assistant settings. Note that you should be logged in as the same account as in the console.
- Navigate to Google Assistant > Settings > Home Control (under Assistant).
- Select the plus (+) icon in the bottom right corner.
- You should see your test app with the [test] prefix and the display name you set.
- Select that item. The Google Assistant will then authenticate with your service and send a SYNC request, asking your service to provide a list of devices for the user.
- Now pre-programmed devices will appear in the Google Home app.
The codes in this project will create the following devices:
- 1 RGB light with brightness, color and on/off control.
- 1 Normal light with brightness and on/off control.
- 1 Fan with speed and on/off control (speed control trait is currently disabled by google hence the corresponding segments of codes have been commented out).
- 1 Thermostat with mode change and temperature control.
- 1 Temperature sensor device with temperature readout only.
- 1 Plug/Switch.
The devices can be added or modified from the devices.json within the functions folder. Use https://jsonlint.com to validate your device list in the JSON file.
Note- Use the Arduino Json library version 5.13.0
- Use Firebase Arduino library from here: https://github.com/FirebaseExtended/firebase-arduino.git
- Default agentUserId is set to 123 in the index.js file. Please change it to something unique to make use of Homegraph based reporting.
- Use esp8266 core version 2.5.2
Comments