Code Monkey home page Code Monkey logo

nest-observe's Introduction

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

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

const { authGoogle, observe } = require('nest-observe');

// Use auth details to get JWT token. Returned object contains {token, expiry, refresh}
// where refresh is a function to get a new token object
const token = await authGoogle(issueToken, cookie, apikey);

// Create the observer. Can also be done using promises
const observer = await observe(token.token, {
    protobuf: false, // set true to return protobuf object as value
    debug: false // set true to log a lot more
});

// Event emitted for new updates which include only the new values
observer.on('data', state => {
    console.log('New state:', state);
});

// Event emitted when the streaming is stopped 
observer.on('end', () => {
    console.log('Streaming ended');
});

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

{
  "DEVICE_XXXX": {
     "traits": [
       { 
         // Name of the protobuf trait type
         "type": "nest.trait.sensor.TemperatureTrait",

         // Label provided by observe endpoint
         "label": "temperature",

         // Value of the trait (spec is defined in the .proto files)
         "value": {
            "temperatureValue": {
               "temperature": {
                  "value": 19.8700008392334
               }
            }
         }
       },
        // ...  
     ],

     // List of traits which have no corresponding protobuf spec yet
     "ignored": [
       {
          // Name of the protobuf trait type
          "type": "nest.trait.hvac.UtilitySettingsTrait",

          // Base64 encoded message
          "value": "CAEQARgB"
       },
       // ...
     ],
    },
    // more devices and structures...
}

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.

nest-observe's People

Contributors

humpheh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

keithkml

nest-observe's Issues

Interested in how you extracted the protobuf spec

Hi Humpheh,

I stumbled upon your library while trying to reverse engineer the Nest browser client Observe API. It has been extremely helpful so far. I am trying to reverse engineer the Nest Security products. I am focusing on the detects and the guard itself right now.

I see the events coming in, but obviously the protobufs haven't been dissected yet and the important parts are gibberish. For example, I can see arm/disarm events, but no protobuf decoder/base64->UTF-8 decoder yields anything meaningful for the data that I assume tells me the arm state. At this point I only know the arm state changed.

I am about to dive into the rabbit-hole of trying to build the protobuf from the un-uglified/minified JS, but I wanted to see what your approach was. I would love to contribute and help build this library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.