Coder Social home page Coder Social logo

gbridge's Introduction

gBridge_banner

G Bridge

GoDoc Go Report Card GitHub

-- work in progress --

Google smart home lets users control your connected devices through the Google Home app and the Google Assistant, which is available on more than 1 billion devices, like smart speakers, phones, cars, TVs, headphones, watches, and more. To connect your device with the Google Assistant, you need to build a smart home Action. Assistant handles how users trigger your Action (in multiple languages) and provides you with relevant metadata through Home Graph (such as a specific device based on user’s room); all you need to do is respond to the requests in your service.

This libary helps you to create a backend service for your Google Smart Home Action.

This libary is ported from actionssdk-smart-home-nodejs

Philosopy

-- TODO: Explain how this libary is structured.. e.g duck-typing and interfaces usage--

Useful links

Instructions

(these may not be up to date, google changed their process recently)
  1. Create an action.json file
    {
      "actions": [{
        "name": "actions.devices",
        "deviceControl": {
        },
        "fulfillment": {
          "conversationName": "automation"
        }
      }],
      "conversations": {
        "automation" :
        {
          "name": "automation",
          "url": "https://<YOUR URL>/smarthome"
        }
      }
    }
  1. Create a project on https://console.actions.google.com/

  2. Click Use Actions SDK

  3. Use the gActions CLI to run the command given with the 'action.json' file as your Action Package.

  4. Click Okay.

  5. Click ADD under App information.

  6. Give your App some information like an invocation name, some description, and some policy and contact info.

  7. Click Save.

  8. Click Add under Account Linking.

  9. Select Authorization Code for Grant Type.

  10. Under Client Information, enter the client ID and secret from earlier.

  11. The Authorization URL is the hosted URL of your app with '/oauth' as the path, e.g. https://<YOUR URL>/oauth

  12. The Token URL is the hosted URL of your app with '/token' as the path, e.g. https://<YOUR URL>/token

  13. Click TEST DRAFT

  14. Open the Google Home App on your phone and navigate to the Home Control section

  15. Click the 3 dots and go to Manage Accounts

  16. Select your project from the Add New section

Example

Please see /examples/gbridge/ for examples on how to use this libary.

Notes

  • If you push an update to actions.json, you might have to unlink your account in google home and re-link it for testing to work from your phone

  • Place this service behind caddy or some other reverse proxy that does LetsEncrypt SSL, or do your own SSL encryption. Google needs your service to be reachable via HTTPs and a valid SSL certificate.

gbridge's People

Contributors

localleon avatar pborges avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gbridge's Issues

Create GoDoc

To improve the usability of this libary, one should create a GoDoc. This could also improve adoption.

Currently all librarys, even the ones from Google are badly documented and hard to understand. Our goal should be to provide a simple and well documented library.

https

Hi, it doesn't work, seems it need certificate files for SSL and aouth.

Devices from Example not showing Up

Hey @pborges ,

thank you for creating this libary. I'm currently trying to create a simple Google Actions Skill with it.

However i'm not able to get your example to work. The Action shows up on my Google Home Skill and i can get an Oauth Token from it. But after that, nothing happens. I expected the defined devices to show up in the Google Home App. The gBridge did not log an SYNC Request either.

Would be great if you could take a look at my code. I'm using a ngrok Tunnel for communication between the cloud and my pc.

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/gorilla/mux"
	"github.com/pborges/gbridge"
)

var addr = ":8081"

func main() {
	log.SetOutput(os.Stdout)
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	r := mux.NewRouter()

	r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		log.Println("UNKKNOWN:", r.RequestURI)
	})

	r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		log.Println("/")
		fmt.Fprint(w, "gAssistant Translator for S.A.M Online")
	})

	b := gbridge.Bridge{
		ClientId:     "950e4dcfe43dc656bd7caa4f8da05fb0", //as long as this matches the settings "Account linking" on actions console it works
		ClientSecret: "759568585e122274798c900839929486", //as long as this matches the settings "Account linking" on actions console it works
	}

	b.HandleExec(NewLight("1", "Testlampe"), func(dev gbridge.Device, req gbridge.CommandRequest, res *gbridge.CommandResponse) {
		log.Printf("DEBUG: Intent received.")
		log.Printf("Exec Cmd: %+v\n", req)
		res.Status = gbridge.CommandStatusSuccess
		res.States.Online = true
		res.States.On = req.Params.On
		log.Printf("Exec Res: %+v\n", res)
	})

	r.HandleFunc("/oauth", b.HandleOauth)
	r.HandleFunc("/token", b.HandleToken)
	r.HandleFunc("/smarthome", b.HandleSmartHome)
	log.Println("Listening:", addr)
	log.Println(http.ListenAndServe(addr, r))
}

func NewLight(id string, name string) gbridge.Device {
	d := gbridge.Device{
		Id:     id,
		Type:   gbridge.DeviceTypeLight,
		Traits: []gbridge.DeviceTrait{gbridge.DeviceTraitOnOff},
		Name: gbridge.DeviceName{
			DefaultNames: []string{name},
			Name:         name,
			Nicknames:    []string{name},
		},
	}
	return d
}

func NewSwitch(id string, name string) gbridge.Device {
	d := gbridge.Device{
		Id:     id,
		Type:   gbridge.DeviceTypeSwitch,
		Traits: []gbridge.DeviceTrait{gbridge.DeviceTraitOnOff},
		Name: gbridge.DeviceName{
			DefaultNames: []string{name},
			Name:         name,
			Nicknames:    []string{name},
		},
	}
	return d
}

Do "Executions" in parallel

Commands like "turn on all the lights" can fire off many requests that take too long and time out, making google say gbridge failed, so lets execute all the Executions in parallel.

Add a license

Under which terms/conditions can people use this project?

An MIT License would be great.

Api key

This lib not use API key and Homegraph?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.