npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smart-home-app-sample

v0.0.1

Published

Mock implementation of device manufacturer platform to facilitate development of sample device and adapter.

Downloads

1

Readme

Actions on Google: Smart Home sample using Node.js

This sample contains a fully functioning example of a Smart Home provider cloud service designed to work with Actions on Google. This can be used with a Actions Console project to create an Action interface to your IoT devices. This sample includes everything you need to get started, including a mocked user authentication service with sample users and a user web portal to demonstrate the user experience when controlling their lights with your action.

An example of a Smart Home IoT cloud engine is written here. This project can be integrated with a web portal for an interactive experience.

Setup Instructions

See the developer guide and release notes at https://developers.google.com/actions/ for more details.

Clone the project and the included frontend as a subdirectory:

git clone https://github.com/actions-on-google/smart-home-nodejs.git
cd smart-home-nodejs
git clone https://github.com/actions-on-google/smart-home-frontend.git

Steps for testing with Google Assistant

Create and set up project in Actions Console

  1. Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
  2. Select Home Control, then click Smart Home.

Optional: Customize your action

  1. From the top menu under Develop, click on Invocation.
  2. Add your App's name. Click Save.
  3. From the top menu under DEPLOY, click on Directory Information.
  4. Add your App info, including images, a contact email and privacy policy. This information can all be edited before submitting for review.
  5. Click Save.

Add Request Sync and Report State

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).

  1. Navigate to the Google Cloud Console API Manager for your project id.
  2. Enable the HomeGraph API.
  3. Navigate to the Google Cloud Console API & Services page
  4. Select Create Credentials and create a Service account key
    1. Create a new Service account
    2. Use the role Service Account > Service Account Token Creator
  5. Create the account and download a JSON file. Save this as src/smart-home-key.json.

Connect to Firebase

  1. Open your project in the Firebase console, and configure a Cloud Firestore database.
  2. Configure a users collection with a default user and a few default fields
    users\
        1234
            fakeAccessToken: "123access"
            fakeRefreshToken: "123refresh"
            homegraph: false
  1. Update the googleCloudProjectId field in src/config.provider.ts with your project ID.
  2. Run firebase use --add <project-id>

Note: If you are not using Google App Engine to host your server, but still want to integrate with Firestore, read this guide on setting up the Firebase Admin SDK.

Deploy server to App Engine

  1. Run npm install
  2. Run npm run build

You can deploy directly to Google App Engine by running npm run deploy. If you do, you will first need the gcloud CLI configured on the same project (see gcloud config list)

Running the sample locally

You can run the sample locally using ngrok, with a few modifications:

  1. Navigate to the Google Cloud Console API & Services page
  2. Select Create Credentials and create a Service account key.
    1. Create a new Service account.
    2. Use the role Firebase > Firebase Admin SDK Administrator Service Agent.
  3. Create the account and download the JSON file that the console generated for you. Save this as src/firebase-admin-key.json.
  4. Modify the initialization code at src/firestore.
const serviceAccount = require('./firebase-admin-key.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: https://${googleCloudProjectId}.firebaseio.com,
})
  1. Run npm run build.
  2. Run npm run start:local. This should print a URL in the format https://{random-id}.ngrok.io
  3. Edit frontend/index.html to update the API_ENDPOINT constant to this URL.

Setup sample service

  1. Set up the web portal
cd frontend
npm install
npm run create-firebase-config
npm run serve
  1. Open the web portal URL.
  2. Configure the virtual devices shown as you please. Click the cloud icon shown above at least one of them to enable it for cloud control.

Start testing

  1. Navigate back to the Actions on Google Console.
  2. From the top menu under Develop, click on Actions (left nav). Click on Add your first action and choose your app's language(s).
  3. Enter the URL for fulfillment and click Done.
    1. If using Ngrok, the URL will be printed in the console, https://{random-id}.ngrok.io/smarthome
    2. If using Google App Engine, the URL will be https://{project-id}.appspot.com/smarthome
  4. On the left navigation menu under ADVANCED OPTIONS, click on Account Linking.
    1. Select No, I only want to allow account creation on my website. Click Next.
    2. For Linking Type, select OAuth.
    3. For Grant Type, select 'Authorization Code' for Grant Type.
    4. Under Client Information, enter the client ID and secret as defined src/config-provider.ts:
      • Client Id: sampleClientId
      • Client Secret: sampleClientSecret
  5. The Authorization URL is the hosted URL of your app with '/fakeauth' as the path
    1. If using Ngrok, the URL will be printed in the console, https://{random-id}.ngrok.io/fakeauth
    2. If using Google App Engine, the URL will be https://{project-id}.appspot.com/fakeauth
  6. The Token URL is the hosted URL of your app with '/faketoken' as the path
    1. If using Ngrok, the URL will be printed in the console, https://{random-id}.ngrok.io/faketoken
    2. If using Google App Engine, the URL will be https://{project-id}.appspot.com/faketoken
  7. Enter any remaining necessary information you might need for authentication your app. Click Save.
  8. On the left navigation menu under Test, click on Simulator, to begin testing this app.

Set up Account linking

  1. 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.
  2. Click Home Control.
  3. Click the '+' sign to add a device.
  4. Find your app in the list of providers.
  5. Log in to your service.
  6. Start using the Google Assistant in the Actions Console to control your devices. Try saying 'turn my lights on'.

:information_source: Assistant will only provide you control over items that are registered, so if you visit your front end and click the add icon to create a device your server will receive a new SYNC command.

References & Issues

Make Contributions

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.