- You are going to need a 'real' SSL certificate e.g. from Let’s Encrypt. The public key and the private key must copied to your Node-RED server, in a location where the Node-RED service can read them.
- You also need to be able to forward TCP traffic coming in from the Internet to your Node-RED server on a port you specify.
- This package requires NodeJS version 7.6.0 at a minimum. If, during start of Node-RED, you get this warning, your version on NodeJS is too old:
[warn] [node-red-contrib-google-smarthome/google-smarthome] SyntaxError: Unexpected token ( (line:30)
To install - change to your Node-RED user directory.
cd ~/.node-red
npm install node-red-contrib-google-smarthome
Note: This version can output a lot of debug messages on the console. These messages are optional.
- If
online
is set tofalse
for a node, Google SmartHome is not going to be able to control the node. It will also show asoffline
in the Google Home app. - The nodes will do their best to convert incoming payload data to the required type. You can send a string of e.g.
ON
and it will be converted totrue
. - Topics must be either as stated below or prepended with one or more
/
. E.g.my/topic/on
. The nodes only looks for the part after the last/
, if any.
topic
can be on
, online
or something else.
If topic
is on
then payload
must be boolean and tells the state of the light.
msg.topic = 'on'
msg.payload = true
If topic
is online
then payload
must be boolean and tells the online state of the light.
msg.topic = 'online'
msg.payload = true
If topic
is something else then payload
must be an object and tells all the states of the light.
msg.topic = 'set'
msg.payload = {
on: false,
online: true
}
topic
can be on
, online
, brightness
or something else.
If topic
is on
then payload
must be boolean and tells the state of the light.
msg.topic = 'on'
msg.payload = true
If topic
is online
then payload
must be boolean and tells the online state of the light.
msg.topic = 'online'
msg.payload = true
If topic
is brightness
then payload
must be a number and tells the brightness of the light. Range is 0 through 100.
msg.topic = 'brightness'
msg.payload = 75
If topic
is something else then payload
must be an object and tells all the states of the light.
msg.topic = 'set'
msg.payload = {
on: false,
online: true,
brightness: 100
}
topic
can be on
, online
, brightness
, hue
, saturation
, value
or something else.
If topic
is on
then payload
must be boolean and tells the state of the light.
msg.topic = 'on'
msg.payload = true
If topic
is online
then payload
must be boolean and tells the online state of the light.
msg.topic = 'online'
msg.payload = true
If topic
is brightness
then payload
must be a number and tells the brightness of the light. Range is 0 through 100.
msg.topic = 'brightness'
msg.payload = 75
If topic
is hue
then payload
must be a number and tells the hue of the light. Range is 0.0 through 360.0.
msg.topic = 'hue'
msg.payload = 120.0
If topic
is saturation
then payload
must be a number and tells the saturation of the light. Range is 0.0 through 100.0.
msg.topic = 'saturation'
msg.payload = 100.0
If topic
is something else then payload
must be an object and tells all the states of the light.
msg.topic = 'set'
msg.payload = {
on: false,
online: true,
brightness: 100,
hue: 120.0,
saturation: 100.0
}
topic
can be on
, online
, brightness
, rgb
or something else.
If topic
is on
then payload
must be boolean and tells the state of the light.
msg.topic = 'on'
msg.payload = true
If topic
is online
then payload
must be boolean and tells the online state of the light.
msg.topic = 'online'
msg.payload = true
If topic
is brightness
then payload
must be a number and tells the brightness of the light. Range is 0 through 100.
msg.topic = 'brightness'
msg.payload = 75
If topic
is rgb
then payload
must be a number and tells the RGB values of the light. Range is 0 through 16777215.
msg.topic = 'rgb'
msg.payload = 255
Hint: red = 16711680, green = 65280, blue = 255.
If topic
is something else then payload
must be an object and tells all the states of the light.
msg.topic = 'set'
msg.payload = {
on: false,
online: true,
brightness: 100,
rgb: 255,
}
topic
can be on
, online
or something else.
If topic
is on
then payload
must be boolean and tells the state of the outlet.
msg.topic = 'on'
msg.payload = true
If topic
is online
then payload
must be boolean and tells the online state of the outlet.
msg.topic = 'online'
msg.payload = true
If topic
is something else then payload
must be an object and tells both the on state as well as the online state of the outlet.
msg.topic = 'set'
msg.payload = {
on: false,
online: true
}
Messages sent to this node is simply passed through. One cannot tell Google SmartHome to activate a scene, they tell us.
topic
can be restart_server
or report_state
.
payload
is not used for anything.
restart_server
is used to stop then start the built-in webserver. Can be used when your SSL certificate has been renewed and needs to be re-read by the webserver.
report_state
will force an update of all states to Google. Mostly usefull for debugging.
Local Authentication
Username
and Password
: A username and password used when you link Google SmartHome to this node.
Actions on Google Project Settings
Client ID
: The client id you entered in the Google on Actions project.
Client Secret
: The client secret you entered in the Google on Actions project.
Google HomeGraph Settings
Jwt Key
: Full path to JWT key file (the one downloaded in the Add Report State section).
Report Interval (m)
: Time, in minutes, between report updates are sent to Google.
Built-in Web Server Settings
Port
: TCP port of your choosing for incoming connections from Google. Must match what you entered in the Google on Actions project.
Public Key
: Full path to public key file, e.g. fullchain.pem
from Let's Encrypt.
Private Key
: Full path to private key file, e.g. privkey.pem
from Let's Encrypt.
See the developer guide and release notes at https://developers.google.com/actions/ for more details.
- 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.
- On the left navigation menu under SETUP, click on Invocation.
- Add your App's name. Click Save.
- On the left navigation menu under DEPLOY, click on Directory Information.
- Add your App info, including images, a contact email and privacy policy. This information can all be edited before submitting for review.
- Click Save.
Note: I'm almost certain this part is not needed.
The Request Sync feature allows the nodes in this package to send a request to the Home Graph to send a new SYNC request.
- Navigate to the Google Cloud Console API Manager for your project id.
- Enable the HomeGraph API. This will be used to request a new sync and to report the state back to the HomeGraph.
- Click Credentials
- Click 'Create credentials'
- Click 'API key'
- Copy the API key shown and insert it in
smart-home-provider/cloud/config-provider.js
- Enable Request-Sync API using these instructions.
The Report State feature allows the nodes in this package to proactively provide the current state of devices to the Home Graph without a QUERY
request. This is done securely through JWT (JSON web tokens).
- Navigate to the Google Cloud Console API & Services page
- Select Create Credentials and create a Service account key
- Create the account and download a JSON file.
Save this as
jwt-key.json
. You must copy this file to your Node-RED server, in a location where the Node-RED service can read it.
- Navigate back to the Actions on Google Console.
- On the left navigation menu under BUILD, click on Actions. Click on Add Your First Action and choose your app's language(s).
- Enter the URL for fulfillment, e.g. https://example.com:3001/smarthome, click Done.
- On the left navigation menu under ADVANCED OPTIONS, click on Account Linking.
- 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 '/oauth' as the path, e.g. https://example.com:3001/oauth
- The Token URL is the hosted URL of your app with '/token' as the path, e.g. https://example.com:3001/token
- 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 using this app.
Note: The example.com
name in the above text must be your actual domain name (and the same name as used in your SSL certficate).
- 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. It will be
[test]
and then your app name. - Log in to your service. Username and password is the ones you specified in the configuration node.
- Start using the Google Assistant.
Parts of this README and large parts of the code comes from Google. Actions on Google: Smart Home sample using Node.js in particular has been of great value.
Copyright 2018 - 2019 Michael Jacobsen under the GNU General Public License version 3.