Relays requests from Google Smart Home API to WebSocket clients.
- Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
- Select Home Control, then click Smart Home.
The Request Sync feature allows a cloud integration to send a request to the Home Graph to send a new SYNC request. The Report State feature allows a cloud integration to proactively provide the current state of devices to the Home Graph without a QUERY
request. These are done securely through JWT (JSON web tokens).
- 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 to
jwt
directory.- Please note that
/jwt
is not under git control (by virtue of.gitignore
)
- Please note that
- Run
npm run init-dotenv
to generate the .env file. - (Optional) Similarly, configure similar environment variables for your cloud environment.
- If you use Heroku, run
heroku config:set TOKEN_CREATOR_JWT=...
etc.
- If you use Heroku, run
This program uses a Postgres database to store information related to users, clients, tokens, and sessions.
To set up one in a local Docker environment, run local-postgres/run.sh
. The script reads password and port from .env file and configures the container accordingly.
To use other Postgres database, set DATABASE_URL
enviroment variable (or .env variable). If you are using Heroku Postgres, the platform will automatically set the DATABASE_URL
enviromnet variable.
Once the database is created, to initialize tables, run following command with $DATABASE_URL
set to your database.
psql $DATABASE_URL < node_modules/connect-pg-simple/table.sql
Registrations can be made by directly INSERTing required information to the database e.g. via psql.
Before registering yout passwords, they have to be hashed by executing:
node -e "console.log(require('bcryptjs').hashSync('your-password'))"
You have to register an user to connect Google Smart Home API with this app. You can set the password as you like.
insert into
users (username, password, name, "createdAt", "updatedAt")
values ('%yourusername%', '%YOUR_PASSWORD_HASH%', '%readable user name%', now(), now());
You need at least two clients.
Set isTrusted
to FALSE
.
insert into
clients ("clientId", "clientSecret", name, "isTrusted", "createdAt", "updatedAt")
values ('yourclientname', '%YOUR_PASSWORD_HASH%', 'readable client name', FALSE, now(), now());
Set isTrusted
to TRUE
.
insert into
clients ("clientId", "clientSecret", name, "isTrusted", "createdAt", "updatedAt")
values ('yourclientname', '%YOUR_PASSWORD_HASH%', 'readable client name', TRUE, now(), now());
- Google API Client
- userId: the
id
of user created before. Check byselect * from users;
- scopes:
'smart-home-api'
- userId: the
- Relay Clients
- userId:
NULL
- scopes:
'device-manager'
- userId:
insert into
scopes ("userId", "clientId", scopes, "createdAt", "updatedAt")
values (%id%, '%clientId%', '%scope-name%', now(), now());
- Go to Action on Google console and navigate to your project page.
- Go to Develop > Account Linking.
- Fill in the form as follows:
- Client ID and Client Secret: Those of Google API client registered to Postgres database. Here raw client secret, i.e. before hashing, is needed.
- Authorization URL:
https://%YOUR_DEPLOYMENT_URL%/dialog/authorize
- Token URL:
https://%YOUR_DEPLOYMENT_URL%/oauth/token
- Click Save.
- Run your server and relay client.
- Lauch Google Home App.
- Add devices. Choose a service provider whose name starts with
[test]
. - You will be asked your username and password. Here raw password, i.e. before hashing, is needed.