NEST Binding Could Not Make It To Work

Wow, glad it worked for you! I think from what you posted you have a working connection there because of this log "Received ‘keep-alive’ event and “Received message to keep connection alive”.

2018-07-10 13:36:31.866 [DEBUG] [nternal.rest.NestStreamingRestClient] - Check: Receiving streaming events, millisSinceLastEvent=29855
2018-07-10 13:36:32.011 [DEBUG] [nternal.rest.NestStreamingRestClient] - Received 'keep-alive' event, data: null
2018-07-10 13:36:32.017 [DEBUG] [nternal.rest.NestStreamingRestClient] - Received message to keep connection alive
2018-07-10 13:37:01.871 [DEBUG] [nternal.rest.NestStreamingRestClient] - Check: Receiving streaming events, millisSinceLastEvent=29860
2018-07-10 13:37:02.011 [DEBUG] [nternal.rest.NestStreamingRestClient] - Received 'keep-alive' event, data: null
2018-07-10 13:37:02.016 [DEBUG] [nternal.rest.NestStreamingRestClient] - Received message to keep connection alive

I don’t see that in my debug log. The frustrating part of my struggle to make this to work is that my communication/connection gets disconnected and reconnects again.

@wborn - Do you think this problem relates to MQTT broker or Websockets? I tried pinging the IP addresses but the results are “Request Timed Out” and “Destination Host Unreachable”. :frowning:

That’s awesome! :smiley:

It’s using a Websocket to listen for events. According to your logging you receive the initial data via the websocket but nothing else. Since the data is sent by Nest it looks like it is an issue on their end. Did you already try to create a new product? If that doesn’t help, perhaps you could ask Nest support to have a look at your product/account.

Yes, I tried deleting the thermostat product and created a new one I even add another product the Nest Protect. Then I created the Nest Account in openhab binding. Next I tried adding the Thermostat and Nest Protect thing but the binding could not discover the thing.

Anyways, from the curl command, I am getting data from NEST API streaming, here’s what I got .

I just cut the whole data stream display but I’m getting a lot of it. Any unusual thing you see here @wborn?

* Hostname was NOT found in DNS cache
*   Trying XXXXXXXXXX...* **IP ADDRESS edited by me**
* Connected to developer-api.nest.com (SOME IP ADDRESS) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / XXXXXXXXXXXXXXXXXXX * **EDITED BY ME**
* Server certificate:
* 	 subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=developer-api.nest.com
* 	 start date: 2017-08-22 15:34:41 GMT
* 	 expire date: 2018-08-21 00:00:00 GMT
* 	 subjectAltName: developer-api.nest.com matched
* 	 issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* 	 SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: developer-api.nest.com
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer c.**EDITED BY ME**
> 
< HTTP/1.1 307 Temporary Redirect
< Content-Type: application/json; charset=UTF-8
< Access-Control-Allow-Origin: *
< Cache-Control: private, no-cache, no-store, max-age=0
< Pragma: no-cache
< Location: https://firebase-apiserver35-tah01-iad01.dapi.production.nest.com:9553/
< Connection: close
< Authorization: Bearer c**.EDITED BY ME**
< content-length: 0
< 
* Closing connection 0
* SSLv3, TLS alert, Client hello (1):
* Issue another request to this URL: 'https://firebase-apiserver35-tah01-iad01.dapi.production.nest.com:9553/'
* Hostname was NOT found in DNS cache
*   Trying 18.208.179.116...
* Connected to firebase-apiserver35-tah01-iad01.dapi.production.nest.com (18.208.179.116) port 9553 (#1)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ***EDITED BY ME**
* Server certificate:
* 	 subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.dapi.production.nest.com
* 	 start date: 2017-08-22 15:41:46 GMT
* 	 expire date: 2018-08-21 00:00:00 GMT
* 	 subjectAltName: firebase-apiserver35-tah01-iad01.dapi.production.nest.com matched
* 	 issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* 	 SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: firebase-apiserver35-tah01-iad01.dapi.production.nest.com:9553
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer c**EDITED BY ME**

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Access-Control-Allow-Origin: *
< Cache-Control: private, no-cache, no-store, max-age=0
< Pragma: no-cache
< Connection: close
< content-length: 6919
< 
{"devices":{"thermostats":{"EDITED BY ME":{"humidity":35,"locale":"en-US","temperature_scale":"C","is_using_emergency_heat":false,"has_fan"

just need to cut the data here..

Nothing unusual as far as I can see. The binding only uses normal HTTP requests for sending commands to the NEST API.

You can also use curl to connect to the REST event stream that the binding is using for streaming updates. It’s documented in the REST Streaming Guide:

curl -v --location-trusted https://developer-api.nest.com/ \
  -H "Accept:text/event-stream" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -H "Cache-Control: no-cache" -v -L

Can you test if that does work properly?

So the streaming protocol is Server-sent events and not Websockets. It only allows for receiving data and not also sending data like Websockets.

I tried this curl and it took some time to display the result. Here’s what I got

event: put
data: {"path":"/","data":{"devices":{"thermostats":{"xJe7UOr6aAyC5RER":{"humidity":35,"locale":"en-US","temperature_scale":"C","is_using_emergency_heat":false,"has_fan":true,"software_version":"5.8-8","has_leaf":true,"where_id":"M9KhBjTip6s_zo2vT_MShb_Uvhllw37It7g-0q-3wkPsCw","device_id":"e7UOr6aAR_QAfC2pmdAb5RER","name":"Living Room","can_heat":true,"can_cool":true,"target_temperature_c":27.0,"target_temperature_f":81,"target_temperature_high_c":24.0,"target_temperature_high_f":75,"target_temperature_low_c":20.0,"target_temperature_low_f":68,"ambient_temperature_c":27.5,"ambient_temperature_f":82,"away_temperature_high_c":28.0,"away_temperature_high_f":83,"away_temperature_low_c":16.0,"away_temperature_low_f":62,"eco_temperature_high_c":28.0,"eco_temperature_high_f":83,"eco_temperature_low_c":16.0,"eco_temperature_low_f":62,"is_locked":false,"locked_temp_min_c":23.0,"locked_temp_min_f":74,"locked_temp_max_c":28.0,"locked_temp_max_f":83,"sunlight_correction_active":false,"sunlight_correction_enabled":true,"structure_id":"QDo_I83RH8MvJ-A","fan_timer_active":true,"fan_timer_timeout":"1970-01-01T00:00:00.000Z","fan_timer_duration":15,"previous_hvac_mode":"","hvac_mode":"cool","time_to_target":"~0","time_to_target_training":"ready","where_name":"Living Room","label":"","name_long":"Living Room Thermostat","is_online":true,"last_connection":"2018-07-13T01:00:51.868Z","hvac_state":"cooling"}},"smoke_co_alarms":{s-MKeQRNmmCFS2pmdAb5RER":{"locale":"en-US","structure_id":G553yxgl_v6U-gdqL4vX3_Wjuk7J-A","software_version":"3.1.4rc3","where_id":"M9KhBjTipo2ebJMJxtRvThb_llw37It7genGug3OI0Iw","device_id":"mmCFS2pmdAb5RER","where_name":"Hallway","name":"Hallway","name_long":"Hallway NesProtect","is_online":true,"last_connection":"2018-07-12T18:22:08.705Z","battery_health":"ok","co_alarm_state":"ok","smoke_alarm_state":"ok","ui_color_state":"green","is_manual_test_active":false,"last_manual_t
.result
.removed
.by
.me
.
event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: put
data: {"path":"/","data":{"devices":{"thermostats":{"xJeb5RER":{"humidity":35,"locale":"en-US","temperature_scale":"C","is_using_emergency_heat":false,"has_fan":true,"software_version":"5.8-8","has_leaf":true,"where_id":"MJMJxtRvT_MShb_U37It7g-0q-3wkPsCw","device_id":"xJe7UOrC2pmdAb5RER","name":"Living Room","can_heat":true,"can_cool":true,"target_temperature_c":27.0,"target_temperature_f":81,"target_temperature_high_c":24.0,"target_temperature_high_f":75,"target_temperature_low_c":20.0,"target_temperature_low_f":68,"ambient_temperature_c":27.5,"ambient_temperature_f":82,"away_temperature_high_c":28.0,"away_temperature_high_f":83,"away_temperature_low_c":16.0,"away_temperature_low_f":62,"eco_temperature_high_c":28.0,"eco_temperature_high_f":83,"eco_temperature_low_c":16.0,"eco_temperature_low_f":62,"is_locked":false,"locked_temp_min_c":23.0,"locked_temp_min_f":74,"locked_temp_max_c":28.0,"locked_temp_max_f":83,"sunlight_correction_active":false,"sunlight_correction_enabled":true,"
.
.result
.removed
.by 
.me
.

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: keep-alive
data: null

event: auth_revoked
data: c.J7fghtrhrfgdjd673

Not really sure what causing the connection problem, might be my internet/wireless connection. I even tried rebooting my router hoping that Nest devices can be discovered. All my wireless devices was discovered except for Nest products. :frowning:

Do you also see this when using the binding?

That would be logged on debug as “API authorization has been revoked for access token:”
The Account Thing would be set to offline with reason “Authorization token revoked:”

I am really giving up on this. I already tried everything, from router reboot, removing/recreating nest product, changing email address, signed up a new account blah blah blah. still not working for me.

Anyways, with my desperation to make this to work I keep on searching the internet and I found this thread in google groups. I recognized familiar names in there who are an avid contributor here.

I tried the example given there, install HTTP binding and somehow it worked! Though there is still an error/problem I could not solve.

Here’s the openhab debug log.

2018-07-17 16:40:56.626 [DEBUG] [ab.binding.http.internal.HttpBinding] - transformed response is 'null'

Here’s the transform/GetNestValue.js

JSON.parse(input).ambient_temperature_c;

I followed the example but I could not figure out why I am still getting ‘null’ result.

Here’s my item config

Number  Ambient_Temp "Ambient Temperature [%.1f °C]" <thermostat> 	{ http="<[nest:60000:JS(GetNestValue.js)]" }

This is my http.cfg (redacted my device_id and access token

nest.url=https://developer-api.nest.com/devices/thermostats/IVR7xImXXXXXXXXXX0?auth=c.FCXXXXXXXXXXXXXXXXXWF8mpTGloVc8v9hb3lt4QlZ5n6VQTTnMlMWWxoZieJddgR2tmxxxxxxxxxx
nest.updateInterval=60000

nest.url=https://developer-api.nest.com/devices/smoke_co_alarms/iRFgN4xxxxxxxxxxxxxx?auth=c.FXXXXXXXXXXXXXXXXXXXXXXXpTGloVc8v9hb3lt4QlZ5n6VQTTnMlMWWxoZieJddgR2tmbzifDOfSsx9XtJOcfzFxxxxxxxxxx
nest.updateInterval=60000

For Nest Protect it is working fine but for thermostat I am getting the ‘null’ result.

nest_OH

If polling does work for you, you might as well give the original openHAB 1.x Nest Binding a try. :wink:

Yes polling is working for me now, I am starting to see data in my Nest items and this thread gave me hope, :smile: I finally got the Nest integration to my OH setup. How I wish NEST binding worked for me because I think it is a neat way integrating Nest products in anyone’s home automation system.

Thank you everyone for your inputs!