pborges / gbridge

Google Home Actions on Google Smart Home integration library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Devices from Example not showing Up

localleon opened this issue · comments

commented

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
}

commented

This is my console output:

2019/12/01 18:46:40 translator.go:47: Listening: :8081
2019/12/01 18:49:08 translator.go:26: /
2019/12/01 18:49:12 translator.go:26: /
2019/12/01 18:51:27 auth.go:10: GET /oauth?redirect_uri=https%3A%2F%2Foauth-redirect.googleusercontent.com%2Fr%2Fs7-go-657fc&client_id=950e4dcfe43dc656bd7caa4f8da05fb0&response_type=code&state=AB8b_TMom3ev_hYO_RRvA4NkDf7lDe6smrfcLchyi4VDdrZdyA1hPkesvfwemMW2Eq9HuqfFDQtty-U7sExON3dJrnR2W5_9JBLFGOeTQSDmF3OtVwqj3nhzHrRWd1-NM1kP_u52xPP7Ig0Jlq-HVT7PlJYnfA2AVZdcjEHBGysS10-fE4GnZnMDaJVEwu4tlJk0m0m63MW2vMwd8OQdK24VX-hdsXgzvVVWP4CExSmnzffvMQQD8fUWaAJ4c66ePpxTCj3BT5ma6V-F7kIpJqffne1Lqfxnxz0Bs09tru_2A_VhHqH4gKafiScV6A3QVZNLS_oUfaNT0nomeaQE5SW5neD6D6JwrYjWo1yGxlC2od1mtnRc6hGyr103VO0CiYCeSO9R-5Rh4tfw-DXdOfZyat60f5kGtNYGGh_V4Vfq7dkCwijS-E2P5HXeixrL31cEFcMMbkG9fVHakx7p3Md8pIBNOGe9DfIU-yAdkhEmekYk3_DOLRnLuZzqM1QfTJMFFqDnW1YLFE8PycOsYOSezPqDqS21223mhCUyRJxMg0IFQthapZ8&user_locale=de-DE
2019/12/01 18:51:27 auth.go:17: clientId: 950e4dcfe43dc656bd7caa4f8da05fb0
2019/12/01 18:51:27 auth.go:18: redirectUrl: https://oauth-redirect.googleusercontent.com/r/s7-go-657fc
2019/12/01 18:51:27 auth.go:19: state: AB8b_TMom3ev_hYO_RRvA4NkDf7lDe6smrfcLchyi4VDdrZdyA1hPkesvfwemMW2Eq9HuqfFDQtty-U7sExON3dJrnR2W5_9JBLFGOeTQSDmF3OtVwqj3nhzHrRWd1-NM1kP_u52xPP7Ig0Jlq-HVT7PlJYnfA2AVZdcjEHBGysS10-fE4GnZnMDaJVEwu4tlJk0m0m63MW2vMwd8OQdK24VX-hdsXgzvVVWP4CExSmnzffvMQQD8fUWaAJ4c66ePpxTCj3BT5ma6V-F7kIpJqffne1Lqfxnxz0Bs09tru_2A_VhHqH4gKafiScV6A3QVZNLS_oUfaNT0nomeaQE5SW5neD6D6JwrYjWo1yGxlC2od1mtnRc6hGyr103VO0CiYCeSO9R-5Rh4tfw-DXdOfZyat60f5kGtNYGGh_V4Vfq7dkCwijS-E2P5HXeixrL31cEFcMMbkG9fVHakx7p3Md8pIBNOGe9DfIU-yAdkhEmekYk3_DOLRnLuZzqM1QfTJMFFqDnW1YLFE8PycOsYOSezPqDqS21223mhCUyRJxMg0IFQthapZ8
2019/12/01 18:51:27 auth.go:20: responseType: code
2019/12/01 18:51:27 auth.go:36: Authcode successful: 1337

Hello, you're welcome, I have not worked on this project in a while but I have been using it "in production" for years (and still am) and would be glad to help you out with this,

Where you able to complete this step on the actions management portal?

  • Click TEST DRAFT

And these on your phone using the Google Home app?

  • Open the Google Home App on your phone and navigate to the Home Control section
  • Click the 3 dots and go to Manage Accounts
  • Select your project from the Add New section

You can also try this, although I have not tested this in many moons...

curl -i -s -k -X POST -H "Content-Type: application/json" -d "{agent_user_id: \"XXXXXX\"}" "https://homegraph.googleapis.com/v1/devices:requestSync?key=XXXXXXX

Which SHOULD force google to try and issue a resync request

commented

Hello, thanks for your quick response.

I was able to complete the following steps:

  • Click TEST DRAFT
  • Open the Google Home App on your phone and navigate to the Home Control section
  • Click the 3 dots and go to Manage Accounts
  • Select your project from the Add New section

However, no new device showed up. How do i get the agent_user_id and key in your curl request?

I'm currently trying the official node.js library from Google and got some things to work. Would be nice to get your library to work and write every piece of code in Go

The "key" should be defined in your actions dashboard for the project, the "agent_user_id" might be as well or might not matter (I think it just has to be populated)

https://developers.google.com/assistant/smarthome/develop/request-sync

Looks like they changed the resync request slightly since i last looked, and want you to use a JWT file now, let me know if this works for you

commented

This request fixed it. Looks like the Google Home App is a little bit funky.

It is... but its the best we got :P glad you got it working! If you want to implement some new DeviceTypes https://developers.google.com/assistant/smarthome/guides please feel free to open a PR

commented

I actually need to create one for a blind. Will definitely open a PR for it.

https://developers.google.com/assistant/smarthome/guides/blinds

I can try to make some time tonight to add blinds, I opened #5 earlier because I realized the API for supporting different device traits is not robust enough...