Nest is an implementation of the Nest API in Go.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
auth
config
device
.gitignore
.travis.yml
LICENSE
README.md
cameras.go
cameras_test.go
event.go
event_test.go
go.mod
go.sum
helpers.go
nest.go
nest_test.go
smokecoalarms.go
smokecoalarms_test.go
thermostats.go
thermostats_test.go

README.md

Nest Build Status Coverage Status GoDoc Version

Gopher Stand by: Kari Linder

A Go library for Nest devices. This library provides basic support for Nest Cameras (work-in-progress), Thermostats, and SmokeCoAlarms. There is support for integrating golang OAuth2.0 support into the HTTP client and is expected when constructing a new client.

Installation

go get github.com/jtsiros/nest

Usage

Devices

Existing Token

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/jtsiros/nest"
	"github.com/jtsiros/nest/auth"
	"github.com/jtsiros/nest/config"
)

func main() {
	// Interactive OAuth2 configuration
	appConfig := config.Config{
		APIURL: config.APIURL,
	}

	conf := auth.NewConfig(appConfig)
	tok, err := auth.NewConfigWithToken("[TOKEN]").Token()
	if err != nil {
		log.Fatal(err)
	}
	client := conf.Client(context.Background(), tok)

	n, err := nest.NewClient(appConfig, client)
	fmt.Println(n.Devices())
}

No existing Token

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/jtsiros/nest"
	"github.com/jtsiros/nest/auth"
	"github.com/jtsiros/nest/config"
	"golang.org/x/oauth2"
)

func main() {
	// Interactive OAuth2 configuration
	appConfig := config.Config{
		ClientID: "[CLIENT_ID]",
		Secret:   "[SECRET]",
		APIURL:   config.APIURL,
	}

	conf := auth.NewConfig(appConfig)
	url := conf.AuthCodeURL("STATE")

	fmt.Printf("Enter code from this authorization URL: %v\n", url)

	var code string
	if _, err := fmt.Scan(&code); err != nil {
		log.Fatal(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()
	token, err := conf.Exchange(ctx, code,
		oauth2.SetAuthURLParam("client_id", appConfig.ClientID),
		oauth2.SetAuthURLParam("client_secret", appConfig.Secret),
	)
	if err != nil {
		log.Fatal(err)
	}

	client := conf.Client(ctx, token)
	n, err := nest.NewClient(appConfig, client)

	fmt.Println(n.Devices())
}

Thermostats

thermostat, err := n.Thermostats.Get("[DEVICE_ID]")
// ... error handling
fmt.Println(thermostat.TargetTemperatureF)

n.Thermostats.SetHVACMode(thermostat.DeviceID, nest.Heat)

SmokeCoAlarms

smokeCoAlarm, err := n.SmokeCoAlarms.Get("[DEVICE_ID]")
// ... error handling
fmt.Println(smokeCoAlarm.LastConnection)

Cameras

At this time, only read-only portion of the API is implemented. I'm planning on implementing the write calls once I integrate with my HomeKit integration.

camera, err := n.Cameras.Get("[DEVICE_ID]")
// ... error handling
fmt.Println(camera.IsStreaming)

Author

Jon Tsiros

Credits

Go Gopher Coding it up by: Kari Linder