nkgilley / python-ecobee-api Goto Github PK
View Code? Open in Web Editor NEWPython API for controlling Ecobee Thermostats
License: MIT License
Python API for controlling Ecobee Thermostats
License: MIT License
The API provides the ability to cancel Eco+ events:
This would be useful in Home Assistant because some users are not able to opt out of Eco+ and this could allow for an automation to cancel the event if it gets triggered.
I’m still digging in a bit on this. But I’m consistently seeing an exception coming out of the request() call under request_pin.
Here’s the logging from the latest Home Assistant (with my client_id removed)
2021-02-28 20:34:35 DEBUG (SyncWorker_0) [pyecobee] Making request to authorize endpoint to request pin: url: https://api.ecobee.com/authorize, headers: {}, params: {'response_type': 'ecobeePin', 'client_id': 'xxxxxxxxxxxx', 'scope': 'smartWrite'}, body: None 2021-02-28 20:34:40 ERROR (SyncWorker_0) [pyecobee] Error connecting to ecobee while attempting to request pin. Possible connectivity outage. 2021-02-28 20:34:40 DEBUG (SyncWorker_0) [pyecobee] Error obtaining PIN code from ecobee: 'NoneType' object is not subscriptable
I set up a dev HA environment to start digging in. But, of course, that environment works fine.
The first thing that pops to mind is the empty header in the request. Non-auth_request calls set the content type in _request(), auth_request calls do not. Might that be causing issues?
Thanks.
Brent
typo (line 203 of pyecobee/init.py does not provide the log_msg_action require argument to make_request)
Line 202,203 should probably be
if self.refresh_tokens():
return self.make_request(body,log_msg_action)
I originally filed this under home assistant
home-assistant/core#11918
The following shows off how to get access to a list of all switches via polling
I Found that logging into your Ecobee account it makes a request to https://api.ecobee.com/ea/devices/ls?format=json
to pull for changes and get a list of all devices with identifiers and full metadata..
Then when you make a state change like turn on or off it makes a PATCH https://api.ecobee.com/ea/devices/ls/ID_HERE?format=json
with the state {"state":{"on":true}}
.
Hello, I apologize if this should be a home assistant issue or not But I am unable to set the min fan time.
This is the message I get in home assistant. If I should open a case over there please let me know.
2017-09-01 15:48:36 ERROR (Thread-6) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 1030, in execute_service
service_handler.func(service_call)
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/climate/ecobee.py", line 72, in fan_min_on_time_set_service
thermostat.set_fan_min_on_time(str(fan_min_on_time))
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/climate/ecobee.py", line 361, in set_fan_min_on_time
self.thermostat_index, fan_min_on_time)
File "/root/.homeassistant/deps/lib/python3.4/site-packages/pyecobee/__init__.py", line 202, in set_fan_min_on_time
return make_request(body, log_msg_action)
NameError: name 'make_request' is not defined
Hi @nkgilley, I've been looking at adding a config flow for ecobee to Home Assistant. That means that some refactoring would be needed here since I need to wrap the sync calls used in this library with hass's async wrapper for use in the config flow, and I'm trying to avoid stray sync calls in this library (e.g. init for the Ecobee class calls both request_pin() and update()). Would you be open to some PRs? In the future it could also be worth updating this to async for use in hass and I could spearhead that too if you're open to it.
Is it possible to add the "vent" command from the Ecobee API?
It has 4 options, ( The ventilator mode. Default: off. Values: auto, minontime, on, off.) but really on and off is all that is needed to all good functionality in HA.
https://www.ecobee.com/home/developer/api/documentation/v1/objects/Climate.shtml
Unfortunately I'm not really a coder, so I see the function in the API and the pattern in the code, but don't know how to test what I might cobble together or I would gladly try to add this on my own. I am guessing the fan code can be copied / modified to be on / off instead of on / auto for the fan mode.
This is different than the fan though as it shorts the aux connections that connect to a HRV / ERV.
Could you add 'includeWeather:true' to the thermostat request in get_thermostats()?
I would like to be able to track the difference between what the ecobee thinks the external temperature is vs my actual measurement.
The data I'm interested in appears to be in the following structure (once the above line is added to the request):
weather->forecasts->[0]->temperature
Would be great if there was a way to update humidity levels in the library and allow Home Assistant to use the climate.set_humidity service
I occasionally get a -500 degree F reading from my ecobee. Perusing the source code for this as well as the Home Assistant component, I think this must be coming from ecobee itself.
I see that the documentation for the Vera plugin for Ecobee mentions that -500 means "unknown" http://watou.github.io/vera-ecobee/ and according to this issue -400 and maybe 400 could also be returned.
I haven't figured out where these values might be documented on ecobee's website, despite spending about 30 minutes searching, so I am not entirely sure where the vera plugin author learned this information.
Or maybe the 500 is somehow coming from an HTTP Response code getting misapplied? Clearly I have no idea :-)
Would it make sense to guard for these somewhere?
As of March 28th, 2024, ecobee is no longer accepting new developer subscriptions, nor are existing developer accounts able to create new API keys. There is no ETA for when they will be allowed again. Existing API keys will continue to function.
Ecobee is no longer accepting new developer subscriptions, so an alternative to the transitional API-key based login flow is necessary.
Ecobee's official web pages uses a slightly different 'Auth0' login flow, which is able to produce Bearer tokens which can work with python-ecobee-api
This is fairly straightforward:
auth0
is provided, then a response is returned which tries to automatically submit a form to the redirect_uri
, containing the Bearer token and expiration. This needs to be parsed out of the response, because we cannot change the redirect_uri
to something we control (it appears to be linked to the client_id
)auth0
cookie is always set, this cookie is necessary so that new Bearer tokens can be generated without needing user interaction (by simply calling this endpoint again)auth0
cookie is not provided, then it redirects the user to login first. We can either open some kind of embedded web page, or we can just have the user steal an auth0
cookie from their browser.Until its expiration, that Bearer token can be used the same as the token from the developer API. Note that there is no refresh token, you use the above API with the auth0
cookie in a similar manner.
If there are no objections to this approach, I plan to create a PR soon.
Thanks for merging the recent changes. I would like to get Home Assistant pointed at this latest version.
Would you mind adding a tag/release for 0.2.14? That will help with the review on the HA
side.
Thanks.
I'm working on extending the Home Assistant Ecobee integration to support changing preset cool & heat temperatures as another option for automation. The Ecobee API supports changing the thermostat's program by re-uploading both the program schedule and climate (i.e. preset settings) information.
I've written a brief proof of concept below that change's a presets' temperature settings. By editing other fields of thermostat["program"]
, it would be possible to edit the thermostat's schedule and or other preset settings.
thermostat = ecobee.thermostats[thermostat_index]
# Find the first preset with name set to "Home" and change its settings
homeprogram = next(c for c in thermostat["program"]["climates"] if c["name"] == "Home")
homeprogram["coolTemp"] = 850 # 85 degrees
homeprogram["heatTemp"] = 600 # 60 degrees
body = {
"selection": {
"selectionType": "thermostats",
"selectionMatch": thermostat["identifier"],
},
"thermostat": {"program": thermostat["program"]},
}
log_msg_action = "update program"
ecobee._request("POST", ECOBEE_ENDPOINT_THERMOSTAT, log_msg_action, body=body)
Would it be possible to add a method to change a given preset's coolTemp
and heatTemp
to the library? Or perhaps change all of the preset's settings (which include options like color and whether people are away or home during the preset)? Or maybe it would be cleanest to have a method to change the whole program (including schedule and preset/climate settings)?
I had a case where pyecobee tried to get data but apparently the internet connection was down. That resulted in this bug:
home-assistant/core#10892
Specifically this stack trace:
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
result = method(*args, **kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/ecobee.py", line 97, in update
self.ecobee.update()
File "/srv/homeassistant/lib/python3.6/site-packages/pyecobee/__init__.py", line 169, in update
self.get_thermostats()
File "/srv/homeassistant/lib/python3.6/site-packages/pyecobee/__init__.py", line 133, in get_thermostats
request = requests.get(url, headers=header, params=params)
File "/srv/homeassistant/lib/python3.6/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/requests/adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.ecobee.com', port=443): Max retries exceeded with url: /1/thermostat?json=%7B%22selection%22%3A%7B%22selectionType%22%3A%22registered%22%2C%22includeRuntime%22%3A%22true%22%2C%22includeSensors%22%3A%22true%22%2C%22includeProgram%22%3A%22true%22%2C%22includeEquipmentStatus%22%3A%22true%22%2C%22includeEvents%22%3A%22true%22%2C%22includeWeather%22%3A%22true%22%2C%22includeSettings%22%3A%22true%22%7D%7D (Caused by SSLError(CertificateError("hostname 'api.ecobee.com' doesn't match either of 'www.ecobee.com', 'ecobee.com'",),))
Hi I would like to contribute to this repo and collaborate with you to introduce the capability to add the door and window smartsensors into Ecobee integration directly. Since, these are only occupancy (remote) sensors and not thermostats, currently the ecobee integration does not recognize them as binary sensors. In my understanding this is due to the way the ecobee API calls are made in the get_remote_sensors() function i.e. self.thermostats[index]["remoteSensors"]
. Please let me know if this something you have on your to do list already or you'd like to discuss more on this to get the ball rolling on this.
I'm a HomeAssistant user, and I was wondering if it would be possible to add support for the SendMessage API
https://www.ecobee.com/home/developer/api/documentation/v1/functions/SendMessage.shtml
This would allow HomeAssistant to send messages to the Ecobee thermostat's screen based on automation rules.
OpenHAB seems to have implemented something similar
https://github.com/openhab/openhab/wiki/Ecobee-Binding
Was looking something up and noticed this post that there will be changes to the API come November 1.
https://www.ecobee.com/home/developer/api/documentation/v1/auth/developer-migration-summary.shtml
Thank you for putting this library together. I'm a Home Assistant user and been using the ecobee component to monitor several thermostats. I am looking to monitor when someone overrides (HOLD) the schedule so I can be alerted. I haven't been able to find a way to trap just that event. I have been reading the ecobee API documentation and it requests the Event data. I believe you would have to change your call to get_thermostats (line 122) to add includeEvents":"true". The ecobee component would need to change to allow HA to be able to script \ notify based on an unexpected event.
Appreciate it.
I am trying to implement the Fan mode into Homeassistant but it does not appear to work.
I can see the following body get passed to the ecobee api and I get the 200 response but it actually doesn't work. Any ideas?
{"selection":{"selectionType":"thermostats","selectionMatch":"Removed"},"thermostat":{"settings":{"vent":"on"}}}
<Response [200]>
{
"status": {
"code": 0,
"message": ""
}
}
Can the ability to create vacations be added?
https://www.ecobee.com/home/developer/api/documentation/v1/functions/CreateVacation.shtml
Could you publish this package on Pypi, so it can be fetched without specifying the github URL?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.