Code Monkey home page Code Monkey logo

go-ecobee's Introduction

go-ecobee

A go library and simple tools for accessing the Ecobee Thermostat API.

The go-ecobee CLI is built with the underlying go-ecobee API, and serves as it's primary example.

Setup

Install

go install -u github.com/rspier/go-ecobee`

Build

go build main.go

# fully static binary
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main

Application ID

Enable your developer dashboard, if you have not already.

Create an Ecobee API Application ID (API key) by going to the consumer portal, clicking the "Developer" option in the menu, and clicking the "Create New" button.

You probably want to use the ecobee PIN authorization method for non-web based tools.

Thermostat ID

You'll need to know the serial number (Thermostat ID) of your thermostat. You can find it on the About page of the Ecobee portal.

Config

You can store your default thermostat id and appid in ~/.go-ecobee.yaml or you can use the --thermostat and --appid flags to the CLI.

thermostat: <Thermostat ID>
appid: <App ID>

CLI Usage

Status

$ go-ecobee --command=status
Current Settings (Home): 68.0 - 75.0.  Fan: auto
Holding at 68.0 - 75.0 (Fan: auto) until 2017-04-22 00:00:00
Temperature: 75.0
  Bedroom\*: 74.7
  My ecobee3\*: 76.2

Hold Temperature

$ go-ecobee hold --heat 70 --cool 76 --duration 10m
Successfully Held Temperature

Message

$ go-ecobee message --message="Hi there!"
Successfully sent message: "Hi there!"

Fan

$ go-ecobee fan --duration=5m
Running fan for 5 minutes"

List

$ go-ecobee list
${THERMID}: My ecobee3

Development

Lint

Use golangci-lint:

docker run --rm -v $(pwd):/app -w /app \
  golangci/golangci-lint:v1.35.2 golangci-lint run \
  -E golint,goimports,misspell

Ideas for future development

Sensor Failure Test

Use includeSensors on the thermostat endpoint to analyze sensors where the presence sensor may have failed -- i.e. present all the time.

Disclaimer

This is not an official Google project.

go-ecobee's People

Contributors

jkowalski avatar jnathanh avatar jnoxon avatar petewall avatar rspier avatar tedpearson avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

go-ecobee's Issues

Ecobee changed their API to bearer token authentication

Ecobee changes: https://www.ecobee.com/home/developer/api/documentation/v1/auth/developer-migration-summary.shtml

I noticed in the code we're calling an *http.client and then passing it into the GetThermostats function, however this isn't working anymore. We need to pass the bearer token (access token) into this call now for it to authenticate and be able to pull data from the API for the thermostats.

I'll take a stab at this later, we might have to create our own http.client vs pulling in the default one.

Need a non-caching version of the client

I'm using this to build a deployment in Kubernetes, so the process will stay alive for a long time, unlike a CLI program. It'd be nice to make a version of the client that doesn't use the cache file.

Unclear how to do first-time auth

I am unsure how to create an app ID for use with the tool. The README says,

Create an Ecobee API Application ID (API key) at https://www.ecobee.com/consumerportal/index.html#/dev

You probably want to use the ecobee PIN authorization method for non-web based tools.

But when I visit this page, and hit the "Add Application" button, I see:

image

It wants a PIN before presumably issuing me an app ID.

It's not clear to me how to get a PIN from go-ecobee, and the tool wants an app ID before it does anything. There doesn't appear to be an explicit auth command, so it feels like a chicken and egg problem.

If I just put some random string into my config for the app ID and run go-ecobee list, I get:

% go-ecobee list
2023/10/16 13:56:21 error fetching thermostats: error on get request: Get "https://api.ecobee.com/1/thermostat?json=%7B%22selection%22%3A%7B%22selectionType%22%3A%22registered%22%2C%22selectionMatch%22%3A%22%22%2C%22includeRuntime%22%3Afalse%2C%22includeExtendedRuntime%22%3Afalse%2C%22includeElectricity%22%3Afalse%2C%22includeSettings%22%3Afalse%2C%22includeLocation%22%3Afalse%2C%22includeProgram%22%3Afalse%2C%22includeEvents%22%3Afalse%2C%22includeDevice%22%3Afalse%2C%22includeTechnician%22%3Afalse%2C%22includeUtility%22%3Afalse%2C%22includeManagement%22%3Afalse%2C%22includeAlerts%22%3Afalse%2C%22includeWeather%22%3Afalse%2C%22includeHouseDetails%22%3Afalse%2C%22includeOemCfg%22%3Afalse%2C%22includeEquipmentStatus%22%3Afalse%2C%22includeNotificationSettings%22%3Afalse%2C%22includePrivacy%22%3Afalse%2C%22includeVersion%22%3Afalse%2C%22includeSecuritySettings%22%3Afalse%2C%22includeSensors%22%3Afalse%2C%22includeAudio%22%3Afalse%7D%2C%22page%22%3A%7B%22totalPages%22%3A0%2C%22pageSize%22%3A0%2C%22total%22%3A0%7D%7D": error on initial authentication: invalid server response: 400 Bad Request

Which makes sense I guess.

So, some additional instructions on how to complete the first run process would be helpful.

Events validation

Seems there's not enough validation is happening with:

go-ecobee status
Current Settings (Away): 64.4 - 82.4.  Fan: auto
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/rspier/go-ecobee/cmd.showStatus(0xc0000c00e0, 0xc0004e7c38, 0xc0004db300)
	/Users/artemshymko/Sites/ecobee/cmd/status.go:84 +0xd40
github.com/rspier/go-ecobee/cmd.glob..func7(0x19ae960, 0x19e2508, 0x0, 0x0)
	/Users/artemshymko/Sites/ecobee/cmd/status.go:64 +0x285
github.com/spf13/cobra.(*Command).execute(0x19ae960, 0x19e2508, 0x0, 0x0, 0x19ae960, 0x19e2508)
	/Users/artemshymko/go/pkg/mod/github.com/spf13/[email protected]/command.go:830 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0x19ae6e0, 0x0, 0x0, 0x1)
	/Users/artemshymko/go/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/artemshymko/go/pkg/mod/github.com/spf13/[email protected]/command.go:864
github.com/rspier/go-ecobee/cmd.Execute()
	/Users/artemshymko/Sites/ecobee/cmd/root.go:49 +0x31
main.main()
	/Users/artemshymko/Sites/ecobee/main.go:26 +0x95

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.