IndigoDomotics / indigo-ecobee-plugin

Plugin for Indigo home automation software to support Ecobee thermostats and remote sensors
1 stars 1 forks source link

Allow API key configuration through plugin GUI #13

Closed shumonsharif closed 5 years ago

shumonsharif commented 5 years ago

My Indigo logs have periodically been inundated with the below: Ecobee not authenticated to pyecobee yet; not initializing state of device 951059099874 Ecobee not authenticated to pyecobee yet; not initializing state of device 951053877056 I am unable to refresh the tokens, and nothing seems to work until the problem eventually disappears.

As per https://www.ecobee.com/home/developer/api/introduction/licensing-agreement.shtml the maximum number of queries per developer API account on the free tier is 85,000 per month (apologies if I am incorrectly assuming that we are on the free tier).

This number comes down to 118 calls per 24 hour period, which may be the reason for these failures, given there are likely enough users using this plugin, all against the same hard-coded API_KEY. https://github.com/IndigoDomotics/indigo-ecobee-plugin/blob/master/Ecobee.indigoPlugin/Contents/Server%20Plugin/plugin.py#L22

Creating and using a personal API_KEY has resolved these issues for me, but I'd have to manually update the code each time there's a new release, so am requesting that we include the ability to configure the API_KEY value in the plugin's GUI configuration screen.

shumonsharif commented 5 years ago

If this is the root cause of all the authentication related failures, I am happy to submit a pull request with this change.

FlyingDiver commented 5 years ago

Can you briefly describe the steps you went through to get your API key? I'll need to add that to the wiki after I make this change.

FlyingDiver commented 5 years ago

Have you already made the change to add the API key to the plugin config dialog? If so, a pull request would be great.

shumonsharif commented 5 years ago

I haven't made the change to add the API key to the plugin config dialog, and though it is fairly trivial, unfortunately won't be able to submit a PR for the next week or so. Happy to submit one if it can wait.

Instructions for creating an API key pulled from ecobee's site:

Click on the 'Developer' tab located in ecobee's right-hand-side portal menu. Then create a new app by clicking 'Create New', select 'ecobee PIN' as the Authorization Method and click Save. Make note of the API Key.

FlyingDiver commented 5 years ago

If you haven't already written the code, don't worry about it.

FlyingDiver commented 5 years ago

Basic code is done, but I need to look at the startup sequence again. Right now it requires restarting the plugin to get the new API key activated.

shumonsharif commented 5 years ago

Cool, please let me know if I can help. Apologies couldn't offer sooner; I was at a conference all of last week.

Makes sense regarding the reload of the plugin. Would something like the below work?

plugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.ecobee")
if plugin.isEnabled():
   plugin.restart()
FlyingDiver commented 5 years ago

Yeah, I could brute-force it that way, but it would be better if I could get it to re-initialize without that.

I'm still not 100% convinced this is necessary. I have a ticket in with Ecobee developer support for clarification on the usage limits.

shumonsharif commented 5 years ago

Agreed, reloading the plugin is not the optimal way ... please keep us posted, and thanks so much!!

FlyingDiver commented 5 years ago

Still waiting on reply from Ecobee Developer support on whether this is necessary.

shumonsharif commented 5 years ago

Just wanted to mention; I downloaded your Ecobee 2 plugin, and it is some awesome work, thank you so much!! Also wanted to mention -- I am using your plugin with the Carrier Cor Thermostat (which I figured out was a rebranded Ecobee with some minor API differences), I've had to make some minor tweaks to get it to work. Please let me know in case you'd like to officially support both Ecobee and Cor thermostats, would be happy to contribute.

FlyingDiver commented 5 years ago

Yes, let me know the differences and I'll add support. There's a modelNumber key in the JSON data from the server that should identify those models as "corSmart" (vs "athenaSmart" for the Ecobee 3).

shumonsharif commented 5 years ago

It's not just the modelNumber key, there are some failures in the API calls. I'll create an issue on the Ecobee 2 project, if you're OK with that?

FlyingDiver commented 5 years ago

Works for me.

FlyingDiver commented 5 years ago

Closing this because I won't be making this change to the old code. If necessary, we'll open a new one for the new code.

shumonsharif commented 5 years ago

Sounds good, BTW I had no clue you had a several discussion threads over on the Domotics forums, I just noticed them now. I happened to come across your Ecobee 2 plugin while browsing your repos. Let me get caught up on all your discussions, I will follow up on the new project! Thanks.

shumonsharif commented 5 years ago

Just a quick update -- I went through the Ecobee 2 source code more thoroughly and realized I was using an incorrect configuration to set up my thermostats. I had used 'Ecobee 3' instead of 'Ecobee Smart' for my Cor thermostats; using the proper type now, and everything is working beautifully. So please ignore my previous comments regarding the API calls and thank you for everything.