mikejac / node-red-contrib-google-smarthome

A collection of Node-RED nodes to control your smart home devices via Google Assistant.
GNU General Public License v3.0
115 stars 36 forks source link

Table of Contents


Introduction

A collection of Node-RED nodes to control your smart home devices via Google Assistant or the Google Home app.

This is done by implementing a smart home provider that runs on your own host. So you don't have to rely on any third party services (other than Google) that can go offline, charge you, or leak your data.

What this module does NOT do:


Prerequisites and Setup Instructions

Follow our setup instructions.


Nodes in this package

General Information

Google device node

This is a generic node that supports the following Google devices:

and the following Google traits:

Example flow: See the flow used for the automated tests here

Management

topic can be restart_server, report_state or request_sync.

payload is not used for anything.

restart_server restarts the built-in web server.

report_state will force an update of all states to Google. Mostly useful for debugging.

request_sync will ask Google for a sync to learn about new or changed devices. This is usually done automatically.


The config node

Name: A name for your config node.

Enable Node Debug: If enabled, debug messages will be written to Node-RED's log output.

Default Language: The language of your project.

Local Authentication

Use Google Login: If checked, use Google login authentication.

Login Client ID: If Google Login is enabled, the client ID you received from the Google Sign-In integration.

Authorized emails: If Google Login is enabled, the email addresses authorized to log in.

Username and Password: If Google Login is disabled, a username and password used during account linking in the Google Home app.

Actions on Google Project Settings

Client ID: The client ID you entered in the Actions on Google project.

Client Secret: The client secret you entered in the Actions on Google project.

Google HomeGraph Settings

Jwt Key: Path to the JSON file that you downloaded during setup. Can be an absolute path or a path relative to Node-REDs user dir (where your settings.js, flows.json etc. are stored).

Web Server Settings

Port: TCP port of your choice for incoming connections from Google. Must match what you specified in the Actions on Google project. If empty, it will use the same port as Node-RED.

URL subpath: URL subpath to add to the URL. If set, the URL will change from https://example.com:3001/check to https://example.com:3001/<subpath>/check (resp. /<subpath>/smarthome, /<subpath>/oauth, /<subpath>/token).

Use http Node-RED root path: If enabled, use the same http root path prefix configured for Node-RED, otherwise use /.

Use external SSL offload: If enabled, the smarthome service will use HTTP instead of HTTPS. Check if you want to do SSL termination on a reverse proxy.

Public Key: Full path to the SSL certificate file, e.g. fullchain.pem from Let's Encrypt.

Private Key: Full path to private SSL key file, e.g. privkey.pem from Let's Encrypt.

Note: Certificates are automatically reloaded after renewal. You don't need to restart Node-RED.

Local Fulfillment

Scan Type: The service discovery method to use. Must match what is set in the Actions on Google project.

Discovery Port: A port number to use for UDP or mDNS service discovery.

HTTP Port: A port number to use for the connection from your smart speaker to Node-RED. If empty, it will use the same port as Node-RED. If you are using Node-RED's built-in HTTPS encryption or have a httpAdminRoot set, you need to set a port. Don't create a forwarding rule for this port!

Advanced Settings

Token Duration: The duration of the authorization token used by Google SmartHome to identify itself to the Node-RED SmartHome plugin. Default is 60 minutes.

Report Interval (m): Time in minutes between sending report updates to Google (default is 60 minutes).

Request sync delay (s): Delay in seconds, for requesting devices sync after a deployment. 0 or empty for disable (default is 0).

Set state delay (s): Delay, in seconds, for sending the set_state message after state changes, 0 or empty to disable (default value 0).


Sending spoken notifications

Some devices support sending spoken notifications to your smart speaker. For example, you can play a notification on your speaker when someone rings at the front door or when the washing machine completes a cycle. Unfortunately, you cannot send custom notifications, you can only trigger predefined notifications.

See https://developers.google.com/assistant/smarthome/develop/notifications.

  1. Using the "Google Device" node, create a device with one of the supported traits in Node-RED and deploy it. Currently, only the Object Detection, Run Cycle, and Sensor State traits support notifications.
  2. In the Google Home app, open your new device and enable Spoken Notifications.
  3. To trigger the notification, send a message with a specific payload to the device node. You can find examples for all supported notifications in the examples folder (examples/Spoken%20Notifications). Payloads are documented here.

Inviting other users

You can invite other people into your smart home in the app by following these steps.

Inviting people will not work in all cases. For example, it won't work if either you or the other person has a commercial Google Workspace account. If this is the case, you can share access to your Smart Home project as follows:

  1. If you are currently using username/password authentication, switch to Google Sign-In by following the instructions on Integrating Google Sign-In. Proceed only after you have successfully unlinked and relinked your own account.
  2. In "Authorized emails", add the email address of the account you want to add. Save and deploy.
  3. Open your project in the Google Actions Console.
  4. Select "Manage user access" from the menu (three dots on the top right) choose "Manage user access".
  5. Select "Add".
  6. Enter the email address for the account you want to add. Select at least "Viewer" as the role.
  7. Return to the Google Actions Console. On the Test tab, select Settings and disable On device testing. Then click Start testing.
  8. The person you just added should now able to link to your project by following the steps in Setup Account linking.

Troubleshooting

For problems related to local fulfillment, see Troubleshooting local fulfillment.


Contact us


Developer resources


Credits

Parts of this README and much of the code come from Google. In particular, Actions on Google: Smart Home sample using Node.js was of great value.

Copyright and license

Copyright 2018 - 2024 Michael Jacobsen and others under the GNU General Public License version 3.