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:
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.
npm install --prefix functions/
npm run firebase --prefix functions/ -- use ${PROJECT_ID}
npm run deploy --prefix functions/
https://${REGION}-${PROJECT_ID}.cloudfunctions.net/smarthome
placeholder-client-id
placeholder-client-secret
https://${REGION}-${PROJECT_ID}.cloudfunctions.net/authorize
https://${REGION}-${PROJECT_ID}.cloudfunctions.net/token
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.
255.255.255.255
A5A5A5A5
3312
3311
_sample._tcp.local
Name: .*\._sample\._tcp\.local
Note: The Name attribute value is a regular expression.
UPNP service type: urn:sample:service:light:1
Click Save
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.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.
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/
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.
control_protocol
used with
functions:config:set
when setting up cloud fulfillment.--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.
Serve the sample app locally from the same local network as the Home device, or deploy it to a publicly reacheable URL endpoint.
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
Click Save
npm install --prefix app/
npm run build --prefix app/
npm run deploy --prefix app/ -- --project ${FIREBASE_PROJECT_ID}
http://${FIREBASE_PROJECT_ID}.firebaseapp.com/web/index.html
http://${FIREBASE_PROJECT_ID}.firebaseapp.com/node/bundle.js
[test]
chrome://inspect
inspect
to launch the
Chrome developer tools.Set the light color to magenta
◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉
npm test --prefix app/
npm run lint --prefix device/
See LICENSE