WARNING work in progress
porting from actionssdk-smart-home-nodejs
- https://developers.google.com/actions/smarthome/
- https://github.com/actions-on-google/actionssdk-smart-home-nodejs
- https://console.actions.google.com/
- Create an action.json file
{
"actions": [{
"name": "actions.devices",
"deviceControl": {
},
"fulfillment": {
"conversationName": "automation"
}
}],
"conversations": {
"automation" :
{
"name": "automation",
"url": "https://<YOUR URL>/smarthome"
}
}
}
-
Create a project on https://console.actions.google.com/
-
Click Use Actions SDK
-
Use the gActions CLI to run the command given with the 'action.json' file as your Action Package.
-
Click Okay.
-
Click ADD under App information.
-
Give your App some information like an invocation name, some description, and some policy and contact info.
-
Click Save.
-
Click Add under Account Linking.
-
Select Authorization Code for Grant Type.
-
Under Client Information, enter the client ID and secret from earlier.
-
The Authorization URL is the hosted URL of your app with '/oauth' as the path, e.g. https://<YOUR URL>/oauth
-
The Token URL is the hosted URL of your app with '/token' as the path, e.g. https://<YOUR URL>/token
-
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
package main
import (
"net/http"
"fmt"
"github.com/gorilla/mux"
"github.com/pborges/gbridge"
"log"
"os"
)
var addr = ":8085"
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, "Hello")
})
b := gbridge.Bridge{
ClientId: "123456", //as long as this matches the settings "Account linking" on actions console it works
ClientSecret: "654321", //as long as this matches the settings "Account linking" on actions console it works
}
b.HandleDevice(NewSwitch("1", "alarm"), func(dev gbridge.Device, req gbridge.CommandRequest, res *gbridge.CommandResponse) {
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 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
}
*NOTE place this service behind caddy or some other reverse proxy that does LetsEncrypt SSL, or do your own SSL encryption