[RELEASE] Google SDM API - Nest integration

I finally migrated my Nest account to a Google one and implemented this integration with Hubitat for my Thermostats only. All seems to be working manually controlling them from the device page and if changing things from the Nest App, the pub/sub is sending those change events back to Hubitat for updated status.
My issue is with a test RM rule that simply turns on a virtual switch and the action is to set the thermostats mode and temperature. The actions are inconsistent and unreliable.
Of the 3 thermostats, 1 might turn on one with the right temp setting while the other 2 don't change. Or if the Thermostats were in the "Off" mode, the logs will complain "unable to set temp while in off mode"... even though the RM action specifies mode=heat. Its as if its not able to send multiple actions to the thermostats in the right order:

  1. Change mode to "Heat"
  2. Set temp to X degrees

The only event in the logs is a warning I'm getting often:

I have no other error events.

I also tried the RM action rule with the Thermostats already set to "auto" mode with the temp range 12-28. The rule should have changed the temp range to 21-28. But again inconsistent behaviour as 2 thermostats actually changed their mode from "auto" to "heat" and the 3rd did nothing.

Without seeing the exact rule you have implemented, the rest of this is a guess - but in general it sounds like you are running into issues where Hubitat's local processing and Rule Machine execution are "too fast" for Google, so you run into race conditions and errors. In general, the app/driver waits for Google to confirm any changes via an event before updating any local state, and the same conditions required by the Google APIs are enforced locally, to avoid unnecessary calls to Google (which could contribute to rate-limiting from Google). I can recall at least one post a little while back, where another user struggled with such races. The best suggestion, unfortunately, is to add a wait/delay between commands. This could be a time delay, or a wait for event... which is looking for the state change of the command just sent.

Example:

  • Set thermostatMode to heat
  • Wait for event: thermostatMode changes to heat
  • Set heatingSetpoint to 21

I was thinking along the same lines, however Hubitats "Set Thermostat" feature allows for setting multiple conditions in the one action. Here is mine:

Here is the same rule modified with Wait For Events:

Thoughts?

Yes, Rule machine allows you to change multiple attributes of the thermostat in one action, but under the hood, sends individual commands to the device.

You're moving in the right direction with the new rule - instead of waiting for an "operating state" event, I'd suggest using the exact attribute you just changed, e.g. set thermostat mode, then wait for thermostat mode, set heat point, then wait for heat point. You are also still changing multiple attributes in single actions (thermostat mode and fan mode, heat point and cool point) - which may lead to unexpected behavior.

1 Like

It's all working now. The Waits in between actions did the trick and I changed it to wait for the actual mode I'm setting as suggested. Thanks for your help, great integration you created here.

I've had this integration working for a while with both my battery doorbell and camera/floodlight. I've heard some people referring to getting the doorbell image in a dashboard using the image attribute but never got it working and gave up. I tried it again at the weekend and magically it works. No changes made at my end....

If you're using HPM, it probably pulled in several recent app updates with fixes for this, specific to the newer Google battery/wired doorbells. You can thank @nathaniel.knautz for reporting the issues and helping with the back and forth to troubleshoot.

2 Likes

My image stopped working a week or so ago and its been updating with HPM but its currently still not working.

Uh oh... Which camera model do you have?

Can you turn on debug logging for the app and camera, then trigger the camera in some capacity (walking in front of it), then post the logs? I'll take a look, sounds like I broke something by accident.

The nest Hello

Ill PM you the logs

Found the issue, thanks! I had forgotten the break at the end of each case in the switch statement, for generating the mp4 vs jpg image events in Hubitat, after uploading the file to Google Drive. As a result, a "duplicate" mp4 event would always overwrite the jpg event in Hubitat - Google Drive archives were correct.

App:1.0.7 released with a fix.

2 Likes

Yes that fixed it thanks!

I am running into an error that I feel is on me but cannot figure out where I got this, can you help?

app:9802023-04-12 02:28:15.941 PMerrorgroovy.json.internal.Exceptions$JsonInternalException: unexpected character m on line 198 (method mainPage)

That is the error I am logging when I go to open the API after hitting done for the first time

Looks like a parsing error when attempting to load the credentials.json input -- essentially indicating that it isn't valid JSON. Are you able to load the App page at all (I'm guessing no)? You should be able to skip across to the Settings by clicking the Gear in the top-right, then Remove Google SDM API in the bottom-right, to clear it out and start from scratch.

I'm also adding some robustness to tolerate improper inputs better

Thanks, I have tried to do the remove and reinstall several times and I end up with the same error but now letter s instead of m

Have you reviewed the data you're pasting into the credentials.json input to make sure it's valid json? Online tools such as jsoneditoronline.com can validate, if it isn't obvious.

Should look something like this:

{
    "web": {
        "client_id": "aaa",
        "project_id": "bbb",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "ccc",
        "redirect_uris": [
            "https://www.google.com"
        ]
    }
}

Sooooooo, I am the idiot as I expected.

When you said " Copy and paste the contents of your Oauth2 credentials.json file downloaded from GCP (step 7 in Google Pre-requisites above) into the Google credentials.json input field" in your directions, you meant the whole file not just the Oauth2 client ID.

Yup, new it was my issue and felt like it was a "reading is fundamental" - type problem. Thank you for responding so quickly. I have made progress and will check back if I have other issues. Thanks again.

No worries -- always opportunities to improve robustness!

Various parts of the auth flow need several attributes from this JSON -- I figured it was easier to just get the whole thing and parse out what we need, than to try to direct a user to populate different inputs!

App:1.0.8 released which contains robustness improvements to handle unexpected/invalid inputs during setup. I also updated the README with some additional details/examples of the inputs -- hopefully this helps future newbies trying to set up and install this!

4 Likes

seen this today