Nest Binding on OH 2

@watou or anyone else who can help me. I’m working through migrating to OH 2 and documenting the process as I go along. I’m getting close but I have two errors, one of which I’m hoping you or someone who knows the Nest binding well can help out with.

I have openHAB 2 running in a Docker container generated from the official image on Docker hub. I’ve made no modifications to this image.

I have installed the Nest binding through PaperUI. Initially I tried just copying the values from my OH 1 config file to the nest.cfg and it didn’t work. I then tried to configure it through the configuration widget on PaperUI and it still doesn’t work.

I see following three lines in the log every polling period for Nest:

2016-09-08 21:13:37.952 [WARN ] [st.internal.messages.AbstractRequest] - Method failed: HTTP/1.1 400 Bad Request
2016-09-08 21:13:37.953 [ERROR] [ab.binding.nest.internal.NestBinding] - Error retrieving access token: AccessTokenResponse[accessToken=<null>,expiresIn=<null>,error=oauth2_error,errorDescription=authorization code not found]'
2016-09-08 21:13:37.953 [WARN ] [ab.binding.nest.internal.NestBinding] - Periodic poll skipped.

All of my Nest Items remain uninitialized.

When I run openHAB 1 with the same client-id, secret, and pin it works just fine.

I looked in the Docker container and there is a

/openhab/.java/.userPrefs/_!'8!cg"n!#4!bw"w!'`!bg"o!'%!}g!u!'4!~@"z!(@!.g"%!%`! g""!&`!^!"`!&8!_@"^!%`!`g==/prefs.xml

which exactly corresponds to the same folder in /var/lib/openhab for my OH 1 install (not running in a Docker image).

Is there a potential problem with using the same keys and whatnot from what for all intents and purposes is another machine? Do I have to reauthorize it to work, and if I do so will it disable my OH 1 authorization? Or do you think something else has gone wrong?

I’m not sure yet how to enable trace logging in OH 2. When I figure it out I’ll post some Trace level logs.

As soon as a PIN is used (as your 1.x installation has done), then the PIN is no longer valid. You need to get a new PIN for a new instance of the binding. The client ID and secret (where Nest changed their lingo to “product” instead of “client” after the binding was written) remain valid for all instances, but a new PIN should be retrieved for each instance of the binding you want to run. The binding running under OH2 in your Docker container should detect you have provided a new PIN, and then try the authorization process again on the next poll.

Hmmm. Presumably this needs to be done from within the Docker container (I did try generating a new pin). That will be a challenge as there is no browser in the container. Furthermore I’d have to generate a new key every time I start the machine as each time it starts it creates a new container which looks like a new machine.

Grumble. Unless I’m wrong it looks like the Nest binding is not compatible with running in Docker. :frowning:

To quote Marvin the Martian, “Back to the drawing board.”

You don’t need to request a PIN from any particular browser – any will do.

The Nest binding depends on persisted tokens, which are saved with the Java Preferences API. After the binding first starts with the client ID, client secret and PIN, it uses those values to request tokens which are persisted. At that point, the PIN is no longer valid, as it was traded in for a token. If, on restart, the persistent storage for tokens isn’t there to be read, but the old, now invalid PIN is still present in the configuration settings, the binding will fail to authenticate.

If starting openHAB, and thus the Nest binding, starts from a “clean” environment every time, losing the tokens stored using the Preferences API, then you are right, it won’t work that way, and you would need a new PIN, update the nest.cfg of openhab.cfg with it, and then the binding should work. But that sounds hardly usable…

Aha! OK. I can deal with that by mounting a volume so the .java directory gets persisted outside the container, same as I’m trying to do with the logging config (I used to be a champ at log4j, but I can’t make this one pump just Nest stuff to a separate file :expressionless: ). If I save that folder it should have the token it needs to connect.

Given that, theoretically I can put a copy of my existing OH 1 tokens in the container and it should be OK. I’ll probably not try that in case I hose up my OH 1 install right now.

That explains why it still wasn’t working despite getting a new pin.

Question: If one creates a config using the PaperUI widget and one fills out nest.cfg, which takes precedence? Do I need to fill them both out with the new pin (since filling them both out was part of my debugging efforts)?

Many thanks for the help!

I doubt you would want to supply the configuration values in two places, but I would ask @Kai what happens when both are supplied.

Let us know what is your recommended OH2/Docker configuration when you get it ironed out. Thanks! John

Absolutely!

Also, have a look at how to specify the userRoot for Java Preferences storage via a system property, if you would prefer to keep them somewhere other than ~/.java . Here is a stackoverflow discussion.

I’ll look into that sometime but for now I just wanted to report that it worked!

I mounted a blank .java volume over /openhab/.java in the container, generated a new pin and set that pin in both the widget and nest.cfg and restarted the container. The .userprefs folder was created with the gobbly-gook folder under that and Nest is successfully pulling down data. More importantly, it continues to work after a restart/recreation of the container.

It did not work, however, to copy over the working .java directory. I may need to recreate a new pin for my old setup until I fully transition to OH 2.

Now to figure out why it doesn’t like my rule and suddenly my presence detection isn’t running.

Once my install stabilizes I intend to rewrite the Docker Installation page on the Docs with all the lessons I’ve learned thus far.

1 Like

Rich,

Do you have the specifics on this mount work around for the Nest binding?

It’s not clear to me where this /openhab/.java path is/should be in the docker container configuration. Did you add your mount to fstab? How are you mounting after a restart?

I’m getting tons of User Prefs errors now with the Nest binding.

Regards,

Tony