Google Nest Device Access Console now available

Hi there,
I’m relative new to Openhab and try to integrate my NEST devices to OpenHab.
I have a Doorbell and a Camera
When using OpenHab 2.5 (a quick test setup on my workstation), things seem to work fine. Both devices are discovered, events are pushed to openhab when someone is seen by the camera or rings the doorbell.

However, when trying to get things working in my OpenHab 3.0 environment (openhabian on a Raspberry Pi 4), I have the following issues:

  • Only the doorbell thing is discovered. The Camera is missing. I however have seen the 2.5 build is from 20201117 (version 2.5.5.202011172030), while the 3.0 build is from 20201103 (202011030026). Is there a difference in functionality?
  • Second issue I see on my Openhab3.0 setup are the following errors when trying to add the thing:
22:21:57.198 [DEBUG] [l.discovery.nestdeviceaccessDiscovery] - Starting Discovery NestDeviceAccess
22:22:00.739 [INFO ] [l.discovery.nestdeviceaccessDiscovery] - nestdeviceaccessDiscovery adding Doorbell: [Voordeur] to inbox
22:22:49.341 [INFO ] [ternal.nestdeviceaccessHandlerFactory] - supportsThingType reporting nestdeviceaccess:nest-device-doorbell
22:22:49.348 [INFO ] [ternal.nestdeviceaccessHandlerFactory] - supportsThingType reporting nestdeviceaccess:nest-device-doorbell
22:22:49.351 [INFO ] [ternal.nestdeviceaccessHandlerFactory] - createHandler reporting nestdeviceaccess:nest-device-doorbell
22:22:49.353 [DEBUG] [ternal.nestdeviceaccessHandlerFactory] - createHandler reporting Doorbell..
22:22:49.359 [DEBUG] [ccess.internal.nesthelper.NestUtility] - NestUtility constructor failed to parse date Unparseable date: "Feb 25, 2021, 11:21:56 PM"
22:22:49.364 [DEBUG] [ccess.internal.nesthelper.NestUtility] - NestUtility constructor failed to parse date Unparseable date: "Feb 25, 2021, 11:21:56 PM"

Locale settings are nl_BE.UTF-8, which means I would expect dd-mm-yyyy and 24 hour format.

Any suggestions?
Thanks,
Michiel

Sorry Michiel, I only have nest thermostats… and to my dismay, after a full week of essentially flawless performance, I seem to have broken something, and now the thermostats consistently to lose their connection to OH exactly one hour after re-establishing the link (by re-discovering devices, then disabling & re-enabling the thermostat thing in the UI).

Stupidly, I think I may be responsible for this, as the change seemed to coincide with implementing two factor authentication on the google account associated with the Nests while setting up a different binding (you know, linking to a phone so that you can’t sign in without typing the code in a text message or whatever). I am a little surprised that doing that would have such an effect, but I am unable to identify any other possible culprit to explain the transition from that first week of flawless function to now only being able to maintain the connection for an hour. Curious if anyone else has had similar issues? I am no programmer, but I did a little digging, and I suspect that maybe this has something to do with the “expires_in”: 3599 property associated with the access_token provided by google… if I am correct in assuming that this number is in seconds, then that corresponds to one hour - which is the same period of time that I am able to maintain the link after losing the connection. So it seems that perhaps the refresh token is not successfully able to facilitate the generation of a new access token after the old one expires? The thing is, I have attempted to re-establish the connection using only the refresh token in the .cfg file (to prove that the refresh token is valid), and it works fine. So I am definitely confused. And also devastated, because having the nests integrated into all my other coming home/leaving home/going to bed/waking up routines was so amazing. Too good to be true maybe. Hopefully not. Any ideas would be very much appreciated! In case this clue is helpful - after the hour is up, in the OH log, I can see that the binding continues to attempt to update the thermostats every 5 minutes (which is my arbitrary refresh interval), but the actual values for current temperature and such fail to get updated. There is never any error/warning - superficially everything appears to be working fine, it is just that after that hour long period OH can no longer update values at the refresh interval, or send commands. I am running OH3.0.1 (with openHABian) on a RPi 4.

Also - in case this helps anyone else out (especially you @kovacsi2899) I found the solution to the problem I was experiencing in my last post above, when following the instructions here Get Started  |  Device Access  |  Google Developers. Specifically, at step #1 under “Get an access token” - when attempting to use the code within the google cloud shell terminal:

curl -L -X POST 
'https://www.googleapis.com/oauth2/v4/token?
client_id=oauth2-client-id&
client_secret=oauth2-client-secret&
code=authorization-code&
grant_type=authorization_code&
redirect_uri=https://www.google.com'

I was receiving this error:

A parameter cannot be found that matches parameter name 'L'.
At line:1 char:6
+ curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token?
+      ~~
+ CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : 
NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

It turns out that the error was related to paragraph formatters within the text copied/pasted from the instructions at the above linked site - after removing those in notepad, the code ran perfectly. The code that ended up working was just one really long text string - like this:

curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token?client_id=oauth2-client-id&client_secret=oauth2-client-secret&code=authorization-code&grant_type=authorization_code&redirect_uri=https://www.google.com'

One last thing in case it helps anyone - after succeeding with this step, I frustratingly got stuck again, at the very last step entitled “make a device list call” after attempting the code below in google cloud shell terminal:

curl -X GET 'https://smartdevicemanagement.googleapis.com/v1/enterprises/project-id/devices' \    -H 'Content-Type: application/json' \    -H 'Authorization: Bearer access-token'

I got the error something to the effect of, invalid request or invalid code or some such. I have no idea why this worked, but all I had to do was repeat the preceding steps in the instructions to generate a new authorization code, access token and refresh token - and it miraculously worked like a charm.

Thanks so much to @BHigg, @wborn, and everyone else who I am not informed enough to mention specifically for all your hard work on this binding! I am so excited about it and very appreciative to you guys and everyone else in here helping each other out :+1:

2 Likes

While I am at about the same skill level as you on troubleshooting this stuff, I may have a few things for you to consider.

If the binding is working - checking your logs, you should see some messages related to the channel refresh for the thermostats. They would be in the openhab.log and the events.log. The openhab.log would have INFO entries similar to this:

==> /var/log/openhab2/openhab.log <==
2021-02-28 19:24:55.066 [INFO ] [nal.thermostat.NestThermostatHandler] - refreshChannels process a timer for Updating thing Channels for:nestdeviceaccess:nest-device-thermostat:AVPHwEs0OlH-kM0VcvCbIAJP_BhqtJqhoHfsdQoZrm3Jgz5P1sM1CUa732N5uP69SCddtXA_Oiu3CHzFrynPqgS9GjnKQQ
2021-02-28 19:24:55.640 [INFO ] [nal.thermostat.NestThermostatHandler] - refreshChannels process a timer for Updating thing Channels for:nestdeviceaccess:nest-device-thermostat:AVPHwEtiwOaLlO-WxC0CsAs7ecHUT0RdXAQSWzkWXa2v1v5wM67K4sPVc4osEWUHNXtOL5N8ugyuLm4SonccnCJI_55Lxw

And the event.log would have entry(s) around same time frame that look like this:

==> /var/log/openhab2/events.log <==
2021-02-28 19:24:56.092 [vent.ItemStateChangedEvent] - nestdeviceaccess_nest_device_thermostat_AVPHwEtiwOaLlO_WxC0CsAs7ecHUT0RdXAQSWzkWXa2v1v5wM67K4sPVc4osEWUHNXtOL5N8ugyuLm4SonccnCJI_55Lxw_thermostatHumidityPercent changed from 50.0 in to 48.0 in

Since the subscription is set up as a “pull”, the binding needs to request the messages from the queue. There seems to be a set time frame configured in the binding to do that pull - hence the process timer log entries.

As for the token expiration, it is true that it lasts one hour, but if the binding gets an error using the token, it should be doing a token request with the refresh-token. I assume that the refresh token does not expire and is the way you get a new token much like you did when you got an authorization token and made the initial request for your tokens during setup. Hope that makes sense.

I have had times when the thermostat stops getting updated, and hard to say what caused it but as in your case I was fiddling around on the Google side trying to understand this stuff a little better and probably messed it up. I have found that stopping and starting the binding seems to clear up those issues 99% of the time. You can do that from the openhab-cli console. In an extreme way you can also stop and start openHAB - that way your positive everything is starting fresh.

The binding is still under development which means you can expect to have issues. Hopefully Brian is still active here and can help.

Lately I have noticed (two thermostats and 5 cameras) - some handler Missing errors when I try to update the Thing definition for my nest devices (i.e. assign a location or refresh interval) using the Paper UI. This always messes up the device and the binding stops updating the device. That’s when I resort to restarting the binding…

Today, I completed documenting the setup process for the Device Access Console; not being a programmer, this was the best I could do to help others understand the steps behind getting the Google SDM API set up on Googles cloud platform. I will post a link to the Wiki after this reply. Perhaps there are some other clues in there to help you as well…

1 Like

Since setting up Device Access using Google’s new Smart Device Management (SDM) API isn’t the easiest process to follow, I went ahead and documented, as best I could, the steps to set this up and collect the information needed to configure the Nest Device Access Binding that @BHigg developed for the community.

Here’s a link to that guide on a GitHub Wiki I created:

Nest On OpenHAB - Step By Step Guide

My intent is to improve/keep this information up to-date. Constructive feedback is always welcome and can be provided here on openHab’s Community forum for this Topic.

5 Likes

Thank you Dave, this is very helpful!

I noticed a lot of commits by @wborn on github against the Nest binding. I am still on the “Works with Nest” API with my devices so holding off to convert to SDM for my OH3 setup. Looking forward however to convert once this is integrated in OH. Meanwhile hoping no family member “upgrades” the account…

1 Like

Hello, I have found out these hints by myself also, but it was working neither with Windows CMD nor with Windows Power Shell. Does not matter wich version I used. This was the magic word what helped me: Google Cloud shell console. I Looked for that and in a Chrome browser it started to work. Thanks! But as I migrated to OH3 in a meantime I can’t use it, till OH3 version will be ready.

1 Like

Thank you so much for the reply and for the amazing documentation!! You did a really good job with this, it is going to make this process much more straightforward anyone setting this up in the future.

In case this tidbit helps anyone… the solution to the problem i described above regarding the connection between OH3 and Nest expiring after one hour despite having a valid access token and refresh token was extremely simple… all I had to do was delete the nest thermostat thing from the UI and then add it again. After doing that, the refresh token has successfully maintained the connection for going on 10 days now. Somehow, restarting the binding and clearing the cache were not sufficient. I don’t know what caused the problem but as I said it seems to have vanished, so I am happy :+1:

Also @kovacsi2899, happy to hear that the Google Cloud shell console hint helped. Just to be clear though, I am also on OH3, and it is working for me - so I think you should be able to get the binding working with OH3 in its current state!

Thanks @Marcusfacius for the feedback.

As an FYI, I found that if you have camera devices, the credentials (.json) file needs to include parameters for a service account if you want to reliably retrieve the camera info. I was having hit or miss luck on this till I made this change. I have 5 nest cameras (Dropcam, Nestcam, Outdoor cam), while all showed on-line, only one or two of these would actually be updated when an event occurred. After this change, all 5 cameras are updating as expected.

I have an open issue on my doc to update it, so will get to that soon - you can find more info about that by reading the issue Update instructions for Credentials file to include service type.

Hi @Marcusfacius, how did you get the binding working in OH3? My building just installed Nests, and I’d like to give it a try!

Hi @dschoepel,

Thank you for the detailed step-by-step guide. I am running into trouble getting my access token. In short, I cannot seem to get beyond Step 3, I click all buttons, then I am re-directed to http://nestservices.google.com. I am not getting a screen to “choose an account”. So, I am not getting an access token. My nestservices.google.com screen just shows a box to change the amazon alexa settings. Any help would be appreciated.

~John

Hi @jsable (John),

Happy to try and help. Can you give me a little more detail on which sub-step of 3 your having a problem with. You may have already created your OAuth client - you can check using this link GPC Credentials Page. I mention this in the last paragraph on step 3.

Thanks @dschoepel (Dave), yes, you are correct, I have already created the OAuth client. I think I was unclear, I am in Step 5, sub-step 3, getting the access token. The trouble I have is between sub-step 3 and 4. When I click “next” in sub-step 3, I do not get the choose an account, I can see that my google account is already logged in, so it appears to connect to this account. I don’t get a “confirm your choices” dailog box either. I just get forwarded to the nest services page. I don’t get re-directed to the google page with the authorization code.

~John

John @jsable, can you tell me a little bit about the devices your trying to connect to? Are they thermostats, doorbell, cameras? I assume your on the step called 5.1 link your account, correct? And your getting the the Google Partner Connections screen where you can toggle access to your devices on or off? Once you click next on that screen, you are not being asked to select an account?

Hey Dave (@dschoepel), ok so I have two nest thermostat devices. The issue is that it seems like my account is already linked, it seems like I cannot select an account and it just goes on to the Google Partner Connections screen. When I click “next” this is what I see:

John (@jsable) When you click on the arrow “>” that you see on the right side of the box in your image, what happens? It should open up and show you the details for the devices. The other thing I noticed is that the box in your image shows Amazon Alexa - It should show the name of the Device Access Project you set up in Step 4? That could be another reason why this isn’t working for you.

Hello,

At step 5.1 (after “2-3. Choose Account/Nest permissions” ) I am receiving this message:

No partner connections found
New partner connections will show up here. If you’re trying to link other services, you can add them from the Home view in the Google Home app.

I have deleted everything and restarted from scratch, but without any success.
Anyone with more experience can guide me? BTW, I am new into this world (openhab).

Thank you,
Catalin

Hi Catalin (@ccs),

Based on the details you provided, it seems your using the guide I put together - correct? If so, then a couple questions -

  1. Are your Nest devices migrated to a Google account and you are signed in with that account when you execute these steps?
  2. Can you confirm you created your OAuth credential first, then created your Device Access project? The sequence is important to ensure the OAuth credential gets associated with the project. (FYI: Found this issue and possible explanation here: Can’t link to partner connection)
  3. When you build your command to call the Google Partner Connections screen for the first time, you copied your project Id and OAuth id from the project detail on the Nest device access screen:

URL code block:

    https://nestservices.google.com/partnerconnections/YOUR_DEVICE ACCESS _PROJECT_ID_HERE/auth?
    redirect_uri=https://www.google.com&
    access_type=offline&
    prompt=consent&
    client_id=YOUR_OAUTH_ID_HERE&
    response_type=code&
    scope=https://www.googleapis.com/auth/sdm.service
  1. When you paste the URL into your browser, you are getting the message you displayed above? If so, the Google doc explains this here. Partner Connections Manager Error Reference - which would indicate your logged in to a Google account but that this error occurs when the user has not connected any partners for Device Access. I would interpret that as meaning no OAuth account associated with the project.

Hope this helps a bit to get you on the right track to solving what’s causing your issue…

1 Like

Hi Dave,
Yes, the device is migrated to google account.
I am trying to upload some screenshots during the process.

https://drive.google.com/drive/folders/1ad8j8nPi69iHOzfX9eDdT4o3Lb4qnUN6?usp=sharing

Please tell me that I am doing something wrong and I am not again into an impossible situation.

Thank you,
Catalin

Hi Catalin,

Looks like you have done everything you needed to do. What browser are you using (I have tried this in Edge, Firefox, and Chrome)? Since you have an OAuth id, you should be able to use the [Google Credentials Page] (https://console.developers.google.com/apis/credentials) to view it. When you go there, you should be able to see that your project name (Openhab) listed in the upper left banner for the web page. That would confirm your OAuth Id is associated with your project.

Then, you could try accessing the PCM directly using this link: Partner Connections Manager and see if it works that way. It may not, if you have not made it through the process at least once but may be worth trying.

The only thing I see that looks different on the screenshot you have for the PCM is that there is typically a round circle in the upper right corner of the web page with your account icon to indicate that your signed in. Hence: The reason I was asking about what browser you were using…

Other than that I am running out of ideas…

1 Like

Hi Dave,

I got it figured out, apparently, it kept picking the OAuth from the Alexa skill and not the one I created. I have it resolved and working my way through the rest of the steps!

Thanks again,

~John

1 Like