• Stars
    star
    255
  • Rank 159,729 (Top 4 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Local Home SDK sample

Local Home SDK Sample

This sample demonstrates integrating a smart home Action with the Local Home SDK. The Local Home SDK allow developers to add a local path to handle smart home intents by running TypeScript (or JavaScript) directly on Google Home smart speakers and Nest smart displays. The sample supports the following protocols along with the companion virtual device:

  • Device Discovery: UDP, mDNS or UPnP
  • Control: UDP, TCP, or HTTP

Prerequisites

Configure the Actions project

Note: This project uses Cloud Functions for Firebase, which requires you to associate a billing account with your project. Actions projects do not create a billing account by default. See Create a new billing account for more information.

  • Create a new Smart Home project in the Actions console
  • Deploy the placeholder smart home provider to Cloud Functions for Firebase using the same Project ID:
    npm install --prefix functions/
    npm run firebase --prefix functions/ -- use ${PROJECT_ID}
    npm run deploy --prefix functions/
    
  • In Develop > Actions, set the following configuration values that matches the Cloud Functions for Firebase deployment:
    • Fulfillment: https://${REGION}-${PROJECT_ID}.cloudfunctions.net/smarthome
  • In Develop > Account linking, set the following configuration values:
    • Client ID:: placeholder-client-id
    • Client secret: placeholder-client-secret
    • Authorization URL: https://${REGION}-${PROJECT_ID}.cloudfunctions.net/authorize
    • Token URL: https://${REGION}-${PROJECT_ID}.cloudfunctions.net/token
  • Click Save

Select a discovery protocol

Choose one of the supported the discovery protocols that you would like to test, and create a new scan configuration in the Actions console.

Note: These are the default values used by the virtual device for discovery. If you choose to use different values, you will need to supply those parameters when you set up the virtual device.

  • In Develop > Actions > Configure local home SDK > Add device scan configuration, Click in New scan config.

UDP

  • Broadcast address: 255.255.255.255
  • Discovery packet: A5A5A5A5
  • Listen port: 3312
  • Broadcast port: 3311

mDNS

  • mDNS service name: _sample._tcp.local

  • Name: .*\._sample\._tcp\.local

    Note: The Name attribute value is a regular expression.

UPnP

  • UPNP service type: urn:sample:service:light:1

  • Click Save

Select a control protocol

Choose one of the supported control protocols that you would like to test. You will use this value to configure both the cloud fulfillment and the virtual device.

  • UDP: Send execution commands to the target device as a UDP payload.
  • TCP: Send execution commands to the target device as a TCP payload.
  • HTTP: Send execution commands to the target device as an HTTP request.

Choose a device type

The local fulfillment sample supports running as a single end device or a hub/proxy device. This is determined by the number of channels you configure. A device with more than one channel will be treated as a hub by the local fulfillment sample code.

Set up cloud fulfillment

Configure the cloud service to report the correct device SYNC metadata based on your chosen device type and control protocol. Here are some examples for configuring the service for different use cases:

  • Report a single device (strand1) controlled via UDP commands:

    npm run firebase --prefix functions/ -- functions:config:set \
        strand1.leds=16 strand1.channel=1 \
        strand1.control_protocol=UDP
    npm run deploy --prefix functions/
    
  • Report three individual light strands connected through a proxy (hub1) and controlled via HTTP commands:

    npm run firebase --prefix functions/ -- functions:config:set \
        hub1.leds=16 hub1.channel=1,2,3 \
        hub1.control_protocol=HTTP
    npm run deploy --prefix functions/
    

Set up the virtual device

The companion virtual device is a Node.js app that emulates strands of RGB LEDs controllable using the Open Pixel Control protocol and displays the results to the terminal in a colorful way.

  • Virtual device discovery settings must match the attributes provided in Device Scan Configuration in Develop > Actions > Configure local home SDK.
    • If you modify the attributes in your Device Scan Configuration, you must configure the virtual device accordingly. See the virtual device README for more details on configuring the discovery attributes.
  • Virtual device control protocol should match control_protocol used with functions:config:set when setting up cloud fulfillment.
  • Configure the device type as end device or hub/proxy based on the number of --channel parameters provided. A device with more than one channel will be treated as a hub.

Note: The virtual device needs to listen on the same local network as the Home device.

Here are some examples for configuring the virtual device for different use cases:

  • Start the virtual device as a single device (strand1) discovered via UDP broadcast and controlled with UDP commands:

    npm install --prefix device/
    npm start --prefix device/ -- \
        --device_id strand1 \
        --discovery_protocol UDP \
        --control_protocol UDP \
        --channel 1
    
  • Start the virtual device as a hub (hub1) discovered via mDNS and controlling three individual strands with HTTP commands:

    npm install --prefix device/
    npm start --prefix device/ -- \
        --device_id hub1 \
        --discovery_protocol MDNS \
        --control_protocol HTTP \
        --channel 1 \
        --channel 2 \
        --channel 3
    

Note: See the virtual device README for more details on the supported configuration options.

Deploy the local execution app

Serve the sample app locally from the same local network as the Home device, or deploy it to a publicly reacheable URL endpoint.

Deploy locally

  • Start the local development server:

    npm install --prefix app/
    npm start --prefix app/
    

    Note: The local development server needs to listen on the same local network as the Home device in order to be able to load the Local Home SDK application.

  • Go to the smart home project in the Actions console

  • In Develop > Actions > Configure local home SDK

    • Set the testing URL for Chrome to the one displayed in the local development server logs.
    • Set the testing URL for Node to the one displayed in the local development server logs.
    • Under Add capabilities
      • Check Support local query.
  • Click Save

Deploy to Firebase Hosting

npm install --prefix app/
npm run build --prefix app/
npm run deploy --prefix app/ -- --project ${FIREBASE_PROJECT_ID}
  • Go to the smart home project in the Actions console
  • In Develop > Actions > Configure local home SDK
    • Set the testing URL for Chrome to: http://${FIREBASE_PROJECT_ID}.firebaseapp.com/web/index.html
    • Set the testing URL for Node to: http://${FIREBASE_PROJECT_ID}.firebaseapp.com/node/bundle.js
    • Under Add capabilities
      • Check Support local query.
  • Click Save

Test the local execution app

  • In Develop > Invocation, set the Display name for the smart home Action.
  • In Test, click Start testing
  • In the Google Home app
    • Click the '+' sign
    • Select Work with Google
    • In the list of providers, select your smart home Action by Display name prefixed with [test]
    • Click Link
    • Click Complete Account Link
  • Select the linked devices and click on Add to a room.
  • Reboot the Google Home Device
  • Open chrome://inspect
  • Locate the Local Home SDK application and click inspect to launch the Chrome developer tools.
  • Try the following query
    • Set the light color to magenta
  • It should display the light strand(s) in a colorful way:
    β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰β—‰
    

Troubleshooting

  • Make sure the Google Home device, the virtual device and your workstation are on the same network.
  • Make sure to disable any firewall running on your workstation.

Test and Lint

npm test --prefix app/
npm run lint --prefix device/

License

See LICENSE

More Repositories

1

actions-on-google-nodejs

Node.js client library for Actions on Google
TypeScript
900
star
2

smart-home-nodejs

A sample of the Smart Home device control APIs in Actions on Google
TypeScript
851
star
3

actions-on-google-java

Java/Kotlin library for Actions on Google
Kotlin
287
star
4

codelabs-nodejs

Actions on Google Codelabs
JavaScript
264
star
5

dialogflow-webhook-boilerplate-nodejs

Webhook Boilerplate (using Dialogflow) in Node.js
JavaScript
187
star
6

dialogflow-facts-about-google-nodejs

Custom Entities, Contexts, and Deep Links sample (using Dialogflow) in Node.js
JavaScript
185
star
7

appactions-fitness-kotlin

A sample that shows how to make Android Apps available from the Assistant using App Actions.
Kotlin
173
star
8

assistant-conversation-nodejs

A developer friendly way to fulfill Actions SDK handlers for the Google Assistant
TypeScript
104
star
9

dialogflow-number-genie-nodejs

Localization sample (using Dialogflow) in Node.js
JavaScript
87
star
10

smart-home-java

Java
86
star
11

dialogflow-interactive-canvas-nodejs

A sample that demonstrates how to create an Interactive Canvas experience using Actions on Google for the Google Assistant.
JavaScript
76
star
12

actions-on-google-testing-nodejs

TypeScript
74
star
13

smart-home-dashboard

TypeScript
73
star
14

dialogflow-iosched-nodejs

The Action for the Google Assistant for Google I/O '18
JavaScript
71
star
15

dialogflow-transactions-nodejs

Physical transactions sample (using Dialogflow) in Node.js
JavaScript
67
star
16

local-home-sdk

Local Home SDK
CSS
67
star
17

dialogflow-conversation-components-nodejs

Rich Responses sample (using Dialogflow) in Node.js
JavaScript
66
star
18

dialogflow-updates-nodejs

Daily Updates & Push Notifications Sample (using Dialogflow) in Node.js
JavaScript
59
star
19

dialogflow-silly-name-maker

Parameters sample (using Dialogflow) in Node.js (no webhook)
59
star
20

actionssdk-say-number-nodejs

Say a number Actions SDK sample for Actions on Google
JavaScript
57
star
21

gactions

Go
49
star
22

dialogflow-name-psychic-nodejs

Permissions and Google Maps Static API sample (using Dialogflow) in Node.js
JavaScript
47
star
23

dialogflow-silly-name-maker-webhook-nodejs

Parameters sample (using Dialogflow) in Node.js
JavaScript
46
star
24

appactions-common-biis-kotlin

This sample Android app manages items on to-do lists using Google Assistant implemented via App Actions.
Kotlin
44
star
25

dialogflow-webhook-boilerplate-java

Webhook Boilerplate using the Java client library for Actions on Google
Java
35
star
26

actions-builder-canvas-nodejs

Interactive Canvas sample (using Actions Builder) in Node.js
JavaScript
26
star
27

dialogflow-google-sign-in-nodejs

Google Sign-In sample (using Dialogflow) in Node.js
HTML
25
star
28

smart-home-frontend

JavaScript
24
star
29

dialogflow-quotes-nodejs

External API sample (using Dialogflow) in Node.js
JavaScript
24
star
30

dialogflow-ssml-nodejs

SSML sample (using Dialogflow) in Node.js
JavaScript
23
star
31

assistant-conversation-testing-nodejs

Assistant conversation testing library
TypeScript
21
star
32

dialogflow-snowman-nodejs

Snowman Interactive Canvas Sample
JavaScript
19
star
33

smart-home-schema

19
star
34

dialogflow-gdg-nodejs

Localization, Meetup API & Cloud Translation API sample (using Dialogflow) in Node.js
JavaScript
19
star
35

assistant-conversation-schema

JSON Schema types for fulfilling Actions SDK handlers for the Google Assistant
19
star
36

actions-builder-conversation-components-nodejs

Conversation Components sample (using Actions Builder) in Node.js
TypeScript
15
star
37

dialogflow-quickstart-nodejs

Documentation samples for Actions on Google (Dialogflow/Node.js)
JavaScript
14
star
38

actions-builder-hello-world-nodejs

Hello World sample (using Actions Builder) in Node.js
JavaScript
13
star
39

create-local-home-app

Create a new Local Home SDK app.
TypeScript
13
star
40

dialogflow-helper-intents-nodejs

Helper Intents sample (using Dialogflow) in Node.js
JavaScript
13
star
41

actionssdk-conversation-components-nodejs

Rich Responses sample (using Actions SDK) in Node.js
JavaScript
12
star
42

assistant-actions-nodejs

Node.js Actions API Client Library
JavaScript
12
star
43

actionssdk-updates-nodejs

Daily Updates & Push Notifications Sample (using Actions SDK) in Node.js
JavaScript
12
star
44

actions-builder-codelab-level-1

Actions Builder Codelab (Level 1)
JavaScript
11
star
45

dialogflow-facts-about-google-java

Custom Entities, Contexts, and Deep Links sample (using Dialogflow) in Java
Java
11
star
46

interactive-canvas-devtools

A Chrome DevTools extension for Interactive Canvas development
CSS
10
star
47

dialogflow-digital-goods-nodejs

Digital Purchase API sample (using Dialogflow) in Node.js
JavaScript
9
star
48

dialogflow-google-sign-in-java

Google Sign-In sample (using Dialogflow) in Java
Java
8
star
49

dialogflow-conversation-components-java

Rich Responses sample (using Dialogflow) in Java
Java
8
star
50

dialogflow-name-psychic-java

Permissions, SSML, Surface Transfers, and Google Maps Static API sample (using Dialogflow) in Java
Java
8
star
51

actionssdk-shiritori-ja-nodejs

γ—γ‚Šγ¨γ‚Š AoG ァンプルゲーム
JavaScript
8
star
52

actions-builder-account-linking-nodejs

Account Linking sample (using Actions Builder) in Node.js
JavaScript
8
star
53

actions-builder-patterns-nodejs

Common design patterns for Actions Builder
JavaScript
8
star
54

user-engagement-codelab-nodejs

User Engagement Codelab - https://codelabs.developers.google.com/codelabs/actions-user-engagement
JavaScript
7
star
55

actions-builder-custom-nlu-nodejs

Custom NLU sample (using Actions Builder) in Node.js
JavaScript
7
star
56

actions-builder-codelab-level-2

Actions Builder Codelab (Level 2)
JavaScript
7
star
57

actions-builder-canvas-codelab-nodejs

JavaScript
6
star
58

dialogflow-transactions-java

Physical Goods Transactions API sample (using Dialogflow) in Java
Java
6
star
59

actionssdk-updates-java

Daily Updates & Push Notifications Sample (using Actions SDK) in Java
Java
6
star
60

actions-shortcut-convert

Kotlin
6
star
61

dialogflow-silly-name-maker-webhook-java

Parameters sample (using Dialogflow) in Java
Java
5
star
62

actions-builder-transactions-nodejs

Transactions sample (using Actions Builder) in Node.js
JavaScript
5
star
63

dialogflow-quickstart-java

Documentation samples for Actions on Google (Dialogflow/Java)
Java
5
star
64

actionssdk-say-number-java

SSML sample (using Actions SDK) in Java
Java
4
star
65

app-actions-dynamic-shortcuts

A sample app that demonstrates how to push dynamic shortcuts that can be displayed in Google Assistant.
Kotlin
4
star
66

actions-builder-updates-nodejs

Daily Updates and Notifications sample (using Actions Builder) in Node.js
JavaScript
4
star
67

smart-home-error-reporting

HTML
3
star
68

dialogflow-number-genie-java

Localization sample (using Dialogflow) in Java
Java
3
star
69

actionssdk-quickstart-java

Documentation samples for Actions on Google (Actions SDK/Java)
Java
3
star
70

actionssdk-vscode-extension

2
star
71

actions-on-google-linter-nodejs

JavaScript
2
star
72

dialogflow-session-entities-plugin-nodejs

TypeScript
2
star
73

dialogflow-helper-intents-java

Helper Intents sample (using Dialogflow) in Java
Java
2
star
74

dialogflow-interactive-canvas-codelab-nodejs

Interactive Canvas with Dialogflow Codelab
JavaScript
2
star
75

actionssdk-conversation-components-java

Rich Responses sample (using the Actions SDK) in Java
Java
2
star
76

dialogflow-updates-java

Daily Updates & Push Notifications Sample (using Dialogflow) in Java
Java
2
star
77

dialogflow-digital-goods-plugin-nodejs

TypeScript
1
star
78

actions-builder-canvas-angular

TypeScript
1
star
79

dialogflow-ssml-java

SSML sample (using Dialogflow) in Java
Java
1
star
80

actionssdk-quickstart-nodejs

Documentation samples for Actions on Google (Actions SDK/Node.js)
JavaScript
1
star
81

actions-builder-location-nodejs

JavaScript
1
star
82

dialogflow-quotes-java

External API sample (using Dialogflow) in Java
Java
1
star
83

.allstar

1
star
84

actions-builder-facts-about-google-nodejs

Facts About Google sample (using Actions Builder) in Node.js
JavaScript
1
star