Pachube and the wifi thermostat

A few months ago, I installed a wifi-enabled thermostat. It connects to a service in the cloud ( ) and from there you can connect to it from its Android and iOS apps, or directly from the Web. And I was pretty excited (maybe inordinately so) to find out it has an open REST API with some pretty decent documentation. This thermostat speaks JSON.

Literally within an hour of finding the API docs, I had a Python script grabbing temperature readings from the thermostat and pumping them intro a Pachube feed. It took longer to get the thing attached to the A/C and reliably connected to wifi.


I used the requests module for retrieving the JSON. Here’s the short version (config variables have been hardcoded and error checking removed for brevity ;).

response = requests.get( '' )
indoor_temp = json.loads( response.content )['temp']

It helped speed things along significantly having the Pachube part mostly taken care of by the eeml module. Adding that temperature as a new datapoint to my feed goes something like this.

import eeml
pachube = eeml.Pachube( PACHUBE_API_URL, PACHUBE_API_KEY )
# This particular feed has named datastreams -- if you're posting to one with a numerical ID instead, enter that here.
datastream = 'temp'
pachube.update( [ eeml.Data(datastream, indoor_temp) ] )


I was about to wrap this up with a list of reasons I haven’t posted the entire chunk of code on github yet. But like many unpublished personal software projects, it really comes down to some combination of perfectionism and (perceived) lack of free time. “The perfect is the enemy of the good enough” and all that. The right way would be to just post it already – having code out there publicly means other people can spend their free time to help me make it perfect. 😉

Maybe next weekend.