Monday, April 6, 2015

Nest temperature logging

I had been wanting a Nest thermostat for awhile and this past October we finally decided to get one.  Mainly because our local energy smart program with our utility providers offered a 50% off rebate on it!  But even without a rebate Nest thermostats can save $131-$145/year (or less than a two year ROI and Nest now has the data to prove it).

We had just bought this house so I did not have any historical utility bills to validate these savings.  I could have went a year to get a baseline but who wants to do that.  I use google sheets to do my monthly bills/budgeting and I have over 5 years of longitudinal data, if we had stayed in the same house and bought the nest it would have been interesting to actually see the savings.

I was just curious and wanted to see the how the temperature fluctuates based on the schedule and the weather.   I thought it would be interesting to see how outside temp impacts inside temp and how hard my furnace has to work to keep up.  The Nest app does a nice job of simple showing you how much time your furnace has run each day, and if you tap on a day it will show you the breakdown of what time it ran for and how long.  It's interesting but I was curious how much the indoor temp fluctuated as an indicator to how well my house was insulated.  Or even just a graph that shows the indoor temp over the course of a day or week.  Below is screen shot from my Nest app's Energy History, pretty basic.

So naturally I searched around for a way to pull this data and found a method using a LAMP stack and an unofficial nest-api to query this data from your nest account and add it the mysql db then present it on a php webserver local or public.  This worked as expected but then I searched around some more and found a thread on the Nest Community which uses Google Sheets... brilliant.  I had not used the Google Apps Script yet so thought this was a perfect opportunity to see what it can do.  Luckily the script on the Nest Community site worked pretty much out of the box just by adding your nest credentials and zip code.  

The only thing missing was having this script get data on a schedule w/o out errors.  When I set it up it worked great and pulled data every time I manually ran the script, but if I set it to run hourly it would work at best 20% of the time.  It didn't make sense, why would it run on demand without error when ran manually but not during the trigger?  I kept thinking about it and thought maybe its how it gets run via trigger when I am not there (not logged in) vs when I manually do it while logged in.  

More searching... and found this little hint on Issue 2758: Trigger based UrlFetchApp.fetch() fails, where you just make your main function a doGet() and publish as a web app (it seems that you do have to execute it as yourself and let anyone access it, even anonymous for it to work).

So basically you just put the meat of the script in a doGet() function, publish you web app then create another function that does a UrlFetchApp.fetch('webapp url') then you can set your timebased() trigger on and it should run on that schedule.
So without further ado here's the script I use to query the indoor temperature, target temperature and humidity along with outdoor temperature and humidity.

No comments:

Post a Comment