Code Monkey home page Code Monkey logo

ecobee_influx_connector's Introduction

Ecobee -> InfluxDB Connector

Ship your Ecobee runtime, sensor and weather data to InfluxDB.

Getting Started

  1. Register and enable the developer dashboard on your Ecobee account at https://www.ecobee.com/developers/
  2. Go to https://www.ecobee.com/consumerportal/index.html , navigate to Developer in the right-hand menu, and create an App.
  3. Create a config.json file similar to config.example.json above. This file should exist where your work_dir is defined.
  4. Build the project (see Build section).
  5. Run ecobee_influx_connector -list-thermostats -config $WORK_DIR/config.json at an interactive terminal; it'll provide a PIN. Make sure to you replace $WORK_DIR with your config path.
  6. Go to https://www.ecobee.com/consumerportal/index.html, navigate to My Apps in the right-hand menu, and click Add Application.
  7. Paste the PIN there and authorize the app.
  8. Return to the ecobee_influx_connector CLI and hit Enter.

You should then be presented with a list of thermostats in your Ecobee account, along with their IDs.

Configure

Configuration is specified in a JSON file. Create a file (based on the template config.example.json stored in this repository) and customize it:

  • api_key is created above in steps 1 & 2.
  • thermostat_id can be pulled from step 5 above; it's typically your device's serial number.
  • work_dir is where client credentials, config.json, and (yet to be implemented) last-written watermarks are stored.
  • Use the influx_* config fields to configure the connector to send data to your InfluxDB. If using tokens for bucket authentication, then leave the user and password config fields empty.
  • Use the write_* config fields to tell the connector which pieces of equipment you use.

Run via Docker or Docker Compose

A Dockerfile is provided. To build your Docker image, cd into the project directory and run docker build -t ecobee_influx_connector .

A Docker image is also provided that can be configured via environment variables. View it on Docker Hub, or pull it via docker pull cdzombak/ecobee_influx_connector.

To use the Docker container make sure the path to the config.json is provided as a volume with the path /config. This location will also be used to store the refresh token and config.json.

Important

Before building a persistent container, you will want to execute docker run --rm -it -v $HOME/ecobee:/config cdzombak/ecobee_influx_connector -config "/config/config.json" -list-thermostats so that you can get your token cached (/config/ecobee-cred-cache). This will give you a single key you can then use to authenticate with your ecobee api app. After auth you should see the thermostat_ids listed for all your devices.

If you build a persistent container before performing the above, the initial token request will loop and it will be hard to get the cached token.

Docker Compose

There is an example docker-compose.yml file above. Make sure to modify the volumes section so that it maps your /config folder to containers /config folder.

Example:

volumes:
  - $DOCKERAPPPATH/ecobee_influx_connector:/config

Docker Run

Example:

If using the image you built from Dockerfile, use:

docker run -d --name ecobeetest --restart=always -v ./config:/config -it ecobee_influx_connector

If using the Docker image, use:

docker run -d --name ecobeetest --restart=always -v ./config:/config -it cdzombak/ecobee_influx_connector:latest

Install on Debian via apt repository

Install my Debian repository if you haven't already:

sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://dist.cdzombak.net/deb.key | sudo gpg --dearmor -o /etc/apt/keyrings/dist-cdzombak-net.gpg
sudo chmod 0644 /etc/apt/keyrings/dist-cdzombak-net.gpg
echo -e "deb [signed-by=/etc/apt/keyrings/dist-cdzombak-net.gpg] https://dist.cdzombak.net/deb/oss any oss\n" | sudo tee -a /etc/apt/sources.list.d/dist-cdzombak-net.list > /dev/null
sudo apt-get update

Then install ecobee_influx_connector via apt-get:

sudo apt-get install ecobee-influx-connector

Build from source

make build

To cross-compile for eg. Linux/amd64:

env GOOS=linux GOARCH=amd64 go build -ldflags="-X main.version=$(./.version.sh)" -o ./ecobee_influx_connector .

Run via systemd on Linux

  1. Build the ecobee_influx_connector binary or install it per the instructions above.
  2. Copy it to /usr/local/bin or your preferred location.
  3. Create a work directory for the connector. (I put this at $HOME/.ecobee_influx_connector.)
  4. Run chmod 700 $YOUR_NEW_WORK_DIR. (For my work directory, I ran chmod 700 $HOME/.ecobee_influx_connector.)
  5. Create a configuration JSON file, per the Configure instructions above. (I put this at $HOME/.ecobee_influx_connector/config.json.)
  6. Customize ecobee-influx-connector.service with your user/group name and the path to your config file.
  7. Copy that customized ecobee-influx-connector.service to /etc/systemd/system.
  8. Run chown root:root /etc/systemd/system/ecobee-influx-connector.service.
  9. Run systemctl daemon-reload && systemctl enable ecobee-influx-connector.service && systemctl start ecobee-influx-connector.service.
  10. Check the service's status with systemctl status ecobee-influx-connector.service.

FAQ

Does the connector support multiple thermostats?

The connector does not directly support multiple thermostats. To support this use case, I'd recommend running multiple copies of the connector. Each copy will need its own working directory and config file, but you should be able to use the same API key for each connector instance.

(If deploying using the "systemd on Linux" instructions, give each connector's service file a unique name, like ecobee-influx-connector-1.service, ecobee-influx-connector-2.service, and so on.

License

Apache 2.0; see LICENSE in this repository.

Author

Chris Dzombak (GitHub: @cdzombak).

ecobee_influx_connector's People

Contributors

ablyler avatar cdzombak avatar dependabot[bot] avatar iwvelando avatar

Stargazers

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

Watchers

 avatar  avatar

ecobee_influx_connector's Issues

Self-Signed SSL certs not working

Could you provide an option to support self signed SSL certificates? I'm now using openssl 1.1.1 to address the "x509: certificate relies on legacy Common Name field", but now get "x509: certificate signed by unknown authority".

Initial setup fails

Influx buckets

Apparently this refers to "buckets" in influx but I don't seem to have "buckets". I do however have "databases" but I don't see where to specify which database to write to. Is there some kind of undocumented parameter for the database? I've looked through the source but don't see anything.

Toggle InfluxDB Health Check

Hi there,

I just started trying out your tool and so far so good. The only issue is in my case I had to disable the InfluxDB health check. In my setup I've migrated to InfluxDB 2 but still use Kapacitor for various automations. As a result I use a telegraf instance as a router where it receives all data points and then tees them off to both InfluxDB 2 and to Kapacitor. This telegraf router doesn't support the health check API so this utility fails immediately.

I'm going to try this out for a little while and hopefully this weekend if nobody beats me to it I'll be able to find some time to contribute a patch to allow this.

Documentation could use improvement

Noting this on behalf of Damir Krstic, communicated via email:

Date: Sun, 30 Oct 2022 20:36:34 -0500
To: [email protected]
From: Damir Krstic <[email protected]>
Subject: ecobee and influxdb

Your README on this page states:
The project's README covers setup, configuration, and usage pretty well.
Nowhere on this page does your README cover usage, much less "pretty 
well." Likewise, setup and configuration are equally shit.

Your guide has been one of the most incomplete and frustrating guides to 
follow. Next time maybe keep this shit to yourself instead of "blogging 
it."

d

Add weather symbol and sky to InfluxDB

I have an automation I'd like to perform where I alter the ecobee comfort setting based on some weather conditions. As far as I can tell this data is not currently collected from this software in the ecobee_weather measurement, but it is available in the WeatherForecast struct. Based on https://www.ecobee.com/home/developer/api/documentation/v1/objects/WeatherForecast.shtml I think that the WeatherSymbol field is the most suitable, but Sky would be useful for correlation (for example: WeatherSymbol may indicate windy but Sky could clarify if it's clear or not regardless).

I will be adding this in a local build to complete my project. Would you be interested in a patch that adds this to fields like weather_symbol for WeatherSymbol and sky for Sky?

Edit: I've added this in my fork, happy to PR it back to here if you're interested though iwvelando@2218356

docker setup flow is rough

The initial setup for docker isn't especially nice, because it's not possible to perform the interactive pin/authorization flow until the full config file is setup and the service is up and running: there's a chicken and egg issue with knowing the thermostat_id and then the docker logs are spammed with multiple pin association attempts

InfluxDB 2 Auth Error

System = Raspberry Pi B3+
OS = Raspbian Lite
InfluxDB = v2.3
Using Docker

Hi,
I've gotten pretty far with this on my own, but I've hit a wall and I'm not exactly sure what's going wrong on my end.

When I run docker start -i ecobee I get the following output:

2022/08/11 13:11:48 latest runtime interval available is 154
Thermostat conditions at 2022-08-11 12:45:00 +0000 UTC:
	current temperature: 74.4 degF
	heat set point: 68.0 degF
	cool set point: 74.0 degF
	demand management offset: -0.2
	current humidity: 65%
	humidity set point: 0
	HVAC mode: heatOff
	fan runtime: 0 seconds
	humidifier runtime: 0 seconds
	heat pump 1 runtime: 0 seconds
	heat pump 2 runtime: 0 seconds
	heat 1 runtime: 0 seconds
	heat 2 runtime: 0 seconds
	cool 1 runtime: 0 seconds
	cool 2 runtime: 0 seconds
2022/08/11 13:11:48 influxdb2client E! Write error: unauthorized: unauthorized access
2022/08/11 13:11:48 influxdb2client E! Write error: unauthorized: unauthorized access

I've tried many variations on the JSON file to try to get things working.
I've verified that the API token is correct, and I've tried changing the bucket from the pretty name to the Bucket ID listed in the dashboard.
I've also tried creating a v1 Auth Token with credentials, as I wasn't certain if this script was compatible with InfluxDB 2.x, but I haven't managed to get past this unauthorized access error.

Any thoughts as to what might be causing this?

Celsius support

Wrote this in response to an email, so I'm noting this here for when someone (maybe me) has time to work on it:

The Ecobee API returns values in Fahrenheit ( https://www.ecobee.com/home/developer/api/introduction/core-concepts.shtml#representation ). You’d want to add a setting to use Celsius instead (adding it to https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L22 , following the convention there, would work fine). When that option is enabled, I think the best way to go about logging in Celsius would be to convert these temperature values as soon as they’re read from the API ( https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L186-L191 , https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L283 , https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L336-L339 ).

There are some other parts of the program that assume Fahrenheit, like log statements ( https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L203 , https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L291 ), the indoor humidity recommendation ( https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L371 ), and the wind chill calculation ( https://github.com/cdzombak/ecobee_influx_connector/blob/main/main.go#L344 ). Those would need to be adjusted accordingly as well.

Libwx Humidity format change

I upgraded my docker image to the new one using the updated libwx code and it started throwing errors about the format of the recommended max humidity now being a string instead of an integer.
unprocessable entity: failure writing points to database: partial write: field type conflict: input field "recommended_max_indoor_humidity" on measurement "ecobee_weather" is type string, already exists as type integer dropped=1

Better handle Ecobee API outages

I've had a number of instances where the script has crashed due to receiving non-200 status codes from Ecobee. My assumption is they've had outages (instead of the script having issues) since I've seen 403s and 500s.

Either way, the script doesn't seem to handle these outages very gracefully. Looks to me like it does instant retries 10 times before exiting. Seems like it would be preferable to do exponential back offs for the retries, possibly with a config variable for how many reties to do before exiting.

Here are the logs showing the instant reties. I've configured the container to automatically restart on exit, which is why you can see multiple sets of reties.
Screenshot 2023-04-14 094452

Add a LICENSE

Note go-ecobee code appears to be Apache 2, so whatever I pick must e compatible with that.

Debian repo installation

Instructions for installing via Debian repo need to be updated - apt can't find any package by the name provided.

Sensor data not captured

Running the find-thermostats returns only one ID, the main ecobee unit. I have 4 remote sensors as well connected to that main unit: is there a way to pull the temperature/humidity data from those as well?

Multiple Thermostats

Appologies if I'm being obtuse, how do you specify multiple thermostats in the config file?

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.