项目作者: Humpheh

项目描述 :
Unofficial API for observing Google Nest devices which works with Google authentication
高级语言: JavaScript
项目地址: git://github.com/Humpheh/nest-observe.git
创建时间: 2019-10-13T17:46:29Z
项目社区:https://github.com/Humpheh/nest-observe

开源协议:MIT License

下载


nest-observe

Unofficial API for observing Google Nest devices which works with Google authentication

It provides a simple interface to create an event emitter which will stream updates whenever
a device in your home changes.

About

This repository contains a proof-of-concept library that uses the https://home.nest.com
grpc-web API to observe Nest devices. This is the same API that is used on the app
homepage, which comes with a few of benefits:

  • Access to data using a Google authenticated account (Nest API access was recently removed
    for migrated accounts)
  • Access to data from the EU/UK version of the Nest Thermostat E, which is unavailable
    through the official API

This library was created by examining the https://home.nest.com source code to retrieve
protobuf specs for the publically exposed GatewayService used by the app.
The library pretends to be a client on the web app to access the api. I have used it
here solely for the Observe rpc call, which is a streaming endpoint that pushes new states
of devices in your home to the client, other endpoints exist on the service which may allow
for updating the state of the home, however this is yet to be explored (feel free to open
a PR!).

The endpoint returns a list of ‘traits’ for each device in the home. This includes information
such as current temperature, current humidity, room names, device names, target temperatures,
eco modes and more.

Caveats about this library:

  • This has only been tested in a home using EU/UK versions of the Nest Thermostat E and
    Heat Link E. While it has been shown to provide access to this data, it would be good
    to confirm what other devices work with this.
  • Not all of the trait protobuf specs have been implemented. Please feel free to open am
    issue/PR to add them, or contact me about my method of extracting the protobuf
    specs from the source code.

There is still a lot of opportunity for this method of accessing your nest data -
please feel free to contribute!

Installation

  1. npm install nest-observe

Usage

Authentication is done using the method outlined by the homebridge-nest library to retrieve
the values for issueToken, cookie and apikey. Thankfully
you will only need to do this once (note that the other authentication methods on that
page are currently unsupported)
:
https://github.com/chrisjshull/homebridge-nest#using-a-google-account

  1. const { authGoogle, observe } = require('nest-observe');
  2. // Use auth details to get JWT token. Returned object contains {token, expiry, refresh}
  3. // where refresh is a function to get a new token object
  4. const token = await authGoogle(issueToken, cookie, apikey);
  5. // Create the observer. Can also be done using promises
  6. const observer = await observe(token.token, {
  7. protobuf: false, // set true to return protobuf object as value
  8. debug: false // set true to log a lot more
  9. });
  10. // Event emitted for new updates which include only the new values
  11. observer.on('data', state => {
  12. console.log('New state:', state);
  13. });
  14. // Event emitted when the streaming is stopped
  15. observer.on('end', () => {
  16. console.log('Streaming ended');
  17. });

For each data event, the state is an object which contains mappings of DEVICE/STRUCTURE to
values. An example of the state:

  1. {
  2. "DEVICE_XXXX": {
  3. "traits": [
  4. {
  5. // Name of the protobuf trait type
  6. "type": "nest.trait.sensor.TemperatureTrait",
  7. // Label provided by observe endpoint
  8. "label": "temperature",
  9. // Value of the trait (spec is defined in the .proto files)
  10. "value": {
  11. "temperatureValue": {
  12. "temperature": {
  13. "value": 19.8700008392334
  14. }
  15. }
  16. }
  17. },
  18. // ...
  19. ],
  20. // List of traits which have no corresponding protobuf spec yet
  21. "ignored": [
  22. {
  23. // Name of the protobuf trait type
  24. "type": "nest.trait.hvac.UtilitySettingsTrait",
  25. // Base64 encoded message
  26. "value": "CAEQARgB"
  27. },
  28. // ...
  29. ],
  30. },
  31. // more devices and structures...
  32. }

Feedback

There is a lot more we could do with this library and it is still very young and buggy. Please
feel free to contribute or contact me!

Acknowledgement

Thanks to https://github.com/chrisjshull/homebridge-nest for the method of authenticating to
Google.