Getting Started
Contents |
Supported Platforms
There's a curl for most platforms. On most linux and all Mac OSX distributions, it's included by default, or easily installable via your package manager. For Windows users users, curl is available from http://curl.haxx.se/download.html.
Usage
First, you must identify the IP address of your thermostat. This can be done by doing <insert stuff here>.
Retreiving Values
Next, once you have the IP, you can interact with the thermostat directly by passing the API in to curl like this (substituting your IP address for thermostat listed below. Here, we'll use the power API:
NOTE: Bold text is what you type on the command line, and italic text is what is returned from the thermostat
[proach@central Radio]$ curl http://thermostat/tstat/power
Power is 350 mW
You can see a nice, friendly and human formatted response. This is not what you will see, however, with a direct API call. It seems that the thermostat sees the curl user-agent and politely formats the responses. Here's an example of curl with and without friendly formatting on a more complex API, /tstat.
[proach@central Radio]$ curl http://thermostat/tstat
Temperature: 67.50 F
Thermostat operating mode is Heat
Fan mode is AUTO
Temperature override is not set
Temperature Program Hold is enabled
Target Temperature: 68.00 F
Thursday 1240
Thermostat running state is Heating
Fan state is OFF
[proach@central Radio]$ curl -A bogus http://thermostat/tstat
{"temp":67.50,"tmode":1,"fmode":0,"override":0,"hold":1,"t_heat":68.00,"tstate":1,"fstate":0,"time":{"day":3,"hour":12,"minute":40}}
In the second example, we used the flag -A bogus. This tells curl to use the "User-Agent" string of bogus. Anything other than the curl default will provide real JSON output.
Setting Values
Now, let's use curl to set a value. To do this, we'll use the -d <data> flag for curl. Whatever data follows after -d will be sent as a POST to the URL listed. Let's look at the API for /tstat/fmode:
[proach@central Radio]$ curl -A bogus http://thermostat/tstat/fmode
{"fmode":0}
This shows that the fan mode is currently set to Auto. Let's turn it on, by setting fmode to 2.
[proach@central Radio]$ curl thermostat/tstat/fmode -A foo -d '{"fmode":2}'
Tstat Command Processed
If we now get the value again, we find:
[proach@central Radio]$ curl -A bogus http://thermostat/tstat/fmode
{"fmode":2}
To turn the fan back off, we would simply send {"fmode":0} via curl.
[proach@central Radio]$ curl thermostat/tstat/fmode -A foo -d '{"fmode":0}'
Tstat Command Processed
[proach@central Radio]$ curl -A bogus http://thermostat/tstat/fmode
{"fmode":0}
Setting values from Windows Command line
For windows, you must escape the double quotes, and the single quotes aren't necessary.
c:curl thermostat/tstat/fmode -A foo -d {\"fmode\":0}
Windows Batch File to convert to comma separated values
Here is a windows batch file which queries the tstat, and outputs values in CSV format. Requires curl.
Usage
tstat2csv.bat ip_addr [-t] [-h] [Parameter1 .. ParameterN]
Where:
ip_addr is the ip address of your tstat
-t : first csv column will be date, second will be time
-h : print out the parameters as a header row
[Parameter] is the string name of the parameter you want output.
Sending no parameters will display all the possible parameters (note that I think these change
depending on what mode (heat/cool) your tstat is in).
Examples with output
tstat2csv.bat 192.168.11.7 temp t_heat
67.00,67.00
tstat2csv.bat 192.168.11.7 -t temp t_heat
01/09/2011,06:49,67.00,67.00
tstat2csv.bat 192.168.11.7 -t -h temp t_heat
date,time,temp,t_heat
01/09/2011,06:49,67.00,67.00
Source Code
Unzip this file and rename it to Tstat2csv.bat File:Tstat2csv.gz
Script to Log Outside and Inside Temps
This script will query the Yahoo Weather API to find the outside temperature and the thermostat for the inside temp and set target temp.
Updates or changes to the script are always welcome.
Usage
Requirements
It can be run on any *NIX system as most requirements are pretty basic:
- curl
- cut
- sed
- awk
Running It
Run the script using cron at given interval(every 15 or 60 minutes) will give you more or less data.
Example Output
In this example it is run every 15 minutes
Time,Outdoor,Indoor,Target Cool,Target Heat 6/8/2011 12:00,90,80,85,0 6/8/2011 12:15,90,80,85,0 6/8/2011 12:30,93,80,85,0 6/8/2011 13:00,93,80,85,0 6/8/2011 13:15,93,80,85,0 6/8/2011 13:30,94,80,85,0 6/8/2011 13:45,94,80,85,0 6/8/2011 14:00,94,80,85,0 6/8/2011 14:15,95,80,85,0 6/8/2011 14:30,95,80,85,0 6/8/2011 14:45,95,80,85,0 6/8/2011 15:00,95,80,85,0
Analysis
The CSV file can be imported into a spreadsheet or other program for analysis or graphing. Google Spreadsheets have the ability to import CSV from a URL.
Source Code
#/bin/sh
#Checks Outside and Inside temps and writes them to a CSV file
#This is for development and use at your own risk.
#By Tom Cook
#Modified by Rdrake. Simplified query to the thermostat and added fstate to tracked variables
#####################
#Variables to Edit
#####################
#Path to store output file
filename="/path/to/file/templog.csv"
#Thermostat IP or hostname
address="hostname.com"
#WOEID location for more check: http://developer.yahoo.com/geo/geoplanet/guide/concepts.html
location="2442047"
#####################
#End Variables
#####################
#check if file exists, if not create
if [ -f $filename ]
then
touch $filename
#echo "Date,Outside,Inside,Heat Target,Cool Target" >> $filename
else
echo "File Exists"
fi
#check current outside temp
o_temp=`curl --silent "http://weather.yahooapis.com/forecastrss?p=$location&u=f" | awk -F'- ' '/<b>Current/{getline; gsub("<.*","",$2); print $1}' | sed 's/ //g' | awk '{gsub(/,/," ");print}' | cut -d' ' -f2 | awk 'BEGIN {FS="<"};{print $1}' | cut -c 1-2`
# You can see http://stackoverflow.com/questions/1955505/parsing-json-with-sed-and-awk for why we shouldn't be doing this with awk
# my recommendation is jsawk for simplicity, but I also wanted to stay as CLI as possible. No special languages or libraries.
# If you're willing to follow me on the road to madness then stay tuned, and hope no variable you care about quotes a comma.
# needs $() or \\n gets translated to spaces
THERMY=$(curl --silent http://$address/tstat | sed -e 's/[{}]/''/g; s/,/\\n/g')
# -e option added to echo. Required on some versions of echo to enable inline interpretation of \n
i_temp=`echo -e $THERMY | grep temp | cut -f2 -d:`
state=`echo -e $THERMY | grep tmode | cut -f2 -d:`
target=`echo -e $THERMY | grep -E '(t_cool|t_heat)' | cut -f2 -d:`
fstate=`echo -e $THERMY | grep fstate | cut -f2 -d:`
# if mode is cool, report cool, else report it as heat and output data to file
if [ $state = "2" ]
then
echo `date "+%x %X"`","$o_temp","$i_temp",0,"$target,$fstate >> $filename
else
echo `date "+%x %X"`","$o_temp","$i_temp","$target",0",$fstate >> $filename
fi
