Let me start by just ranting about how bad MRTG is. It is unquestionable the worst graphing program I have ever used. No auto scale, can’t to negative numbers, can’t have a y axis that does not start at zero, need I say more. Oh, yah, obtuse and confusing to use.
I’m using a venstar T1900 thermostat (http://venstar.com) along with insteon module from SmartLabs (http://www.smartlabsinc.com) over to a INSTEON controller connected to the Indigo software from http://www.perceptiveautomation.com.The first step is to get the temperature from the thermostat into the database on the system running the Indigo software. I do that with using a “Time/Date Action” in the Indigo software that runs ever 10 minutes and has an action type of “Execute AppleScript”. I use the following embedded script
All the code following in this blog post is license under the simplified BSD license (see http://www.opensource.org/licenses/bsd-license.php) if you want to use it.
set myThermostatName to “MainThermo” # you can find the name to put here in the Device screen in Indigo
tell application “IndigoServer”
set mainThermoDev to device myThermostatName
set myTemp to temperatures of mainThermoDev
set value of variable “mainTemp” to myTemp
set myHumidity to humidities of mainThermoDev
set value of variable “mainHumidity” to myHumidity
end tell
This causes the variables to be updated with the values from the thermostat. Any time they change, they get written to the database.
Next I have a shell script program that reads values out of the databases and puts them in weird format that MRTG wants. This script looks like
#!/bin/csh
setenv VAL ` sqlite3 -csv /Library/Application\ Support/Perceptive\ Automation/Indigo\ 4/IndigoSqlClient/sqlite_db ” SELECT var_value FROM variable_history WHERE var_name=’$1’ ORDER BY ts DESC LIMIT 1 ; ” `
if ( $VAL == false ) then
echo 0
else if ( $VAL == true ) then
echo 100
else
echo $VAL
endif
echo 0
echo 0
echo $1
exit 0
I call this script from the MRTG. My MRTG configuration has an entry that looks like
Target[mHumidity]: `/Library/WebServer/mrtg/scripts/mrtgGetVar.sh mainHumidity`
Options[mHumidity]: nopercent,growright,nobanner,integer,gauge,noo
Title[mHumidity]: Main Humidity
PageTop[mHumidity]: <h1>Main Humidity</h1>
YLegend[mHumidity]: Percent
ShortLegend[mHumidity]: %
LegendI[mHumidity]: Humidity
LegendO[mHumidity]: Humidity Index
MaxBytes[mHumidity]: 100
And the end result is a graph like
I also have some triggers that happen when my office ligth goes on or off and set a variable called COfficeLight to true or false. The MRTG config looks like:
Target[cOffLight]: `/Library/WebServer/mrtg/scripts/mrtgGetVar.sh COfficeLights`
Options[cOffLight]: nopercent,growright,nobanner,integer,gauge,noo
Title[cOffLight]: C Office Lights
PageTop[cOffLight]: <h1>C Office Lights</h1>
YLegend[cOffLight]: TBD1
ShortLegend[cOffLight]: TBD2
LegendI[cOffLight]: TBD3
LegendO[cOffLight]: TBD4
MaxBytes[cOffLight]: 110
Produces a graph like
Finally I have a python program to get weather information. This program requires the wether API for python to be installed (see http://code.google.com/p/python-weather-api/ ). The python program looks like
#!/usr/bin/env python
import pywapi
import string
import optparse
import sys
def main():
global options
optionParser = optparse.OptionParser(version=”%prog 0.1”,
description=”Get weather in format approperate for MRTG”,
usage=”%prog [options] city”)
optionParser.add_option(‘—verbose’,’-v’,action=’store_true’)
optionParser.add_option(‘—metric’,’-m’,
action=’store_true’,
help=”use metric values. Default is imperial”)
optionParser.add_option(‘—humidity’,”,
action=’store_true’,
help=”Return relative humidity instead of temperature.”)
options, arguments = optionParser.parse_args()
if ( len(arguments) != 1 ):
optionParser.error(“Must provide one city name such as ‘Calgary,AB’ “)
if options.verbose:
print “City is ” + arguments[0]
result = pywapi.get_weather_from_google( arguments[0] )
if options.humidity:
humRes = result[‘current_conditions’][‘humidity’]
hum = “%s”%humRes
if options.verbose:
print “Raw humidity string is ” + hum
h = int( float( hum.lstrip(“Humidity: “).rstrip(“%”) ) )
if options.verbose:
print “Parsed humidity is %d”%h
print “%d”%h
print 0
print 0
print “OutsideHumidity”
else:
if options.metric:
print result[‘current_conditions’][‘temp_c’]
print 0
print 0
print “OutsideTempCelcius”
else:
print result[‘current_conditions’][‘temp_f’]
print 0
print 0
print “OutsideTempFahrenheit”
return 0
if __name__ == “__main__”:
sys.exit(main())
and I use a MRTG config like:
Target[outsideHumidity]: `/Library/WebServer/mrtg/scripts/mrtgGetWeather.py —humidity “Calgary,AB” `
Options[outsideHumidity]: nopercent,growright,nobanner,integer,gauge,noo
Title[outsideHumidity]: Outside Humidity
PageTop[outsideHumidity]: <h1>Outside Humidity</h1>
YLegend[outsideHumidity]: Percent
ShortLegend[outsideHumidity]: %
LegendI[outsideHumidity]: Humidity
LegendO[outsideHumidity]: Humidity Index
MaxBytes[outsideHumidity]: 100
To get a graph like


