Ecobee invalid_grant errors

Would you mind adding a clear, concise explanation of your observation and what it might mean for others in a similar situation, at the bottom the Authorization section? If you have a Github account, click on the Edit button on the page. Many thanks!

Thank you. That solution helped me. Excellent advice as always.

Glad it worked for you. And thank you to @RedOranges for updating the wiki!

I just started having this error message on my system. I run OpenHAB2 on a RPI3. I have a couple questions to make sure I am doing this correctly.
(1) What’s the best way to stop the OpenHAB server. Would it be:

sudo systemctl stop openhab2.service

(2) What is the complete directory name where the tokens are stored?
(3) Can I use the same pin I already had or to I have to apply for a new one?
Thanks for the help.

Hi Mike,

If you installed openHABian or the Debian package via apt-get, yes.

Again, assuming the apt-get or openHABian install, it’s a horribly obfuscated directory name directly under ~openhab/.java/.userPrefs. (The equivalent of ~openhab with this install is /var/lib/openhab2.) If you only have one directory there, then that’s it. I have three directories there, because I have two Ecobee accounts and one Nest account. The obfuscated directory name was the terrible brainchild of whoever implemented the Java Preferences API on Unix-style operating systems. You can actually cd to the directory, if you need to, with the help of the TAB key, expanding out the directory name as far as it can go uniquely.

The “brute force” command to wipe out all Java user Preferences in this install is:

sudo -u openhab rm -rf ~openhab/.java/.userPrefs

No. By the time you have hit the “invalid_grant” situation, the PIN and any access and refresh tokens are no longer valid. Removing the preferences directory described above, stopping and restarting either the binding or openHAB server, and your log will again show the new PIN to register at ecobee.com.

I have only ever seen the “invalid_grant” situation when 1) you waited more than 9 minutes to register the PIN, or 2) you have a disk I/O problem when it came time to rotate the tokens. Token rotation happens about every hour.

John,
Thanks for your help. I got it back working. Yeah, I think something happen to my sd card last night. OpenHAB completely stopped working. I tried to ssh into it my RPI3, but no luck. So I unplugged it and plugged it back in. It seem to work again but the Ecobee errors starting appearing. Lucky I had recent image backup and I used a brand new sd card.

1 Like

Glad you had an image backup! So much configuration to be lost otherwise. Unfortunately, there is no way to use the Ecobee API without reliable persistent storage. (I wrote the Ecobee plugin for the Vera home controller, and, well, some things like reliable storage you take for granted until you don’t have it…)

I am having this problem now. I am running on Windows and do not have a clue how you would make the change in the registry. I do know how to get into the registry but that is about it. Any help would be appreciated.

On Windows, you have to use the Registry Editor to locate and delete them. This Stackoverflow article describes where they live on different versions of Windows. The Ecobee tokens are kept under the userRoot.

When I contribute an OH2 binding for Ecobee, I will store the ever-rotating tokens in a text file for easier access. That being said, the cases where the tokens become invalid (disk error, not registering the PIN in time) can’t be changed in code, as PIN registration and token rotation every hour is imposed by the Ecobee API.

Thanks for the quick reply. I can find userRoot but there are several values, access/Token, app/Key, auth/Token and refresh/Token. Do I delete all of them or just one. Thanks

Delete them all! Then restart openHAB, watch the log, register the new PIN logged at ecobee.com, and you should be good to go.

1 Like

On closer reading it looks like I would delete the whole directory which in the windows registry would be the key not just one or more of the individual values mentioned above is that correct?

1 Like

Missed your post while I was writing my new one.

Either should work, but deleting more rather than less won’t hurt anything.

I deleted the whole key as named below (Windows 64bit, Java 64 bit) got a new PIN and entered it and everything is working well now.

HKEY_CURRENT_USER\Software\JavaSoft\Prefs\org.openhab.ecobee./D/E/F/A/U/L/T_/U/S/E/R

Thanks

1 Like

Update, i just did a broad wipe of the key.
So…question…is there a good way to tell when the userpref or key or whatever refreshes every hour?
I don’t want to bring my VM down for maintenance/snapshot and have the key expire.
It’d be nice to be able to tell when it was last updated, so i know when to expect it again, shut down, image the VM, start back up before the new key.

Not great with linux, how do i get to this directory:
~/.java/.userPrefs

i can’t cd there nothing shows up. i go to /etc/.java i see nothing.
Can’t find it anywhere else.

Another scenario where this happens, is when you snapshot images and revert…ughhhhhhhhggg

Ok I see what you mean with TAB but i can’t get into user prefs

I just started having this problem after a Windows 10 update. I’ve checked the registry key but it doesn’t exist anywhere… Everything was working before the update

Hi,

I am using the ecobee binding on latest release of openhab2, yesterday for the first time in 3 years I got the error message about invalid_grant in the logs.

I run Openhabian on a Pi and I can’t find a way to delete the .userPrefs.
I tried everyting to get rid of this and get the authorization code again but I am stock.

Tried :
sudo -u openhab rm -rf ~openhab/.java/.userPrefs
sudo -u openhab rm -rf /var/lib/openhab2/.java/.userPrefs
I hava a directory .java in /var/lib/openhab2 but this directory is empty.
Tried to go manually to directory etc.

On SSH I am connecting to my instance with openhabian@openHABianPi

Where is this directory on Openhabian on my PI ?
Can you help me to find it?
Is there any way to get the code again without deleting this directory.

Thanks a lot !

I find it I am running on root for some GPIO settings on the pi.

sudo -u root rm -rf ~root/.java/.userPrefs fixed it.

1 Like

Thank you, I don’t know who can get this information over to the binding info page:
https://www.openhab.org/addons/bindings/ecobee1/#troubleshooting-authorization

However after hitting this issue, it was definitely not clear that the folder was in the openhab user’s home directory, a folder that doesn’t show in the filesystem (I’m still using Ubuntu 16.04), or at least I was not experienced enough to know how to look for it.

A “request” is for these things to be indicated better in the logs (hey, go to this folder and delete stuff to reset) or for the binding to have a reset flag in the config so that I don’t need to be stuck trying to find where files are stored. Usually updates are the cause of problems for me, and thus I have no idea what happened, so I don’t have 100% confidence I’m even in the right folder (this is a case in point) resulting in the Homer Simpson spinning in circles on the floor getting nowhere.

To put it in context, I could have built a new VM and reinstalled faster than it took to find the folder to delete it, and get a new PIN. There’s a forehead hole in my desk (kidding of course).

Above all thanks, I would never have found the folder to delete without your description.