Nest thermostat hacking

I got a Nest thermostat a few months ago. I mostly like it, even if it is a bit overdesigned, it’s a lovely product. But a few days ago the battery stopped charging. Turns out charging is complicated on these things; it’s trying to vampire off the furnace control lines. Mine report to be running at about 35V, 20mA. That’s less than a Watt of power, not a huge amount, although it’s been enough so far and Nest tells me it should be sufficient.

Anyway, the diagnostics on the unit for battery charging are not very good. But the Nest helpfully uploads its battery state every few minutes, at least if it has enough battery charge to do that. Unhelpfully the webapp doesn’t show battery history. So I have to make my own.

I ended up using python-nest and writing a simple script to get the battery state.

import nest
username = 'nelson@monkey.org'
password = file('password').read().strip()
with nest.Nest(username, password) as napi:
    for structure in napi.structures:
        for device in structure.devices:
            target = device.target
            temperature = device.temperature
            ts = device._device['$timestamp']
            battery = device._device['battery_level']
            print "%.3f,%.3f,%.1f,%.1f" % (ts/1000.0, battery, temperature, target)

Boy that Python Nest API is funky. And undocumented. I have no idea what a “structure” is supposed to mean. The object doesn’t really exist until you query it with the iterator protocol and it lazily makes an HTTP request. Once it does I think you can also access it as an array, but not before. Then there’s the device which you access with properties, but that only has some data, the battery level is hidden in the device._device object which you access as a hash table. And while the command line tool can print whether the heat is actually running at the moment or not I never could find that in the data structures. At least I got my battery recording.

The Internet of Things enables whole new worlds of yak shaving.

One thought on “Nest thermostat hacking

Comments are closed.