Well, in the great Northwest, we don't have A/C, but it can still get hot enough to not only be uncomfortable outside, but be uncomfortable inside at night even as it cools off at night.
I use a fan (or two) to pull in air from outside at night and in the morning while it's still cool in an attempt to cool of my place enough that it doesn't get too hot during the day.
Here's where I needed some ioBridge help! I want the fan to run in the morning, even after I leave, while it's still cool outside. But I don't want the fan to run all day, pulling in hot air in the afternoon. So I wrote this little python script to check the temperature inside (measured with a thermistor hooked up with the ioBridge) against the temperature outside (retrieved from the web) to see whether if it's worth running the fan. I use X10 to control the fan based on what I discover. It typically shuts off in the afternoon when the outside temperature rises above the inside temperature.
# "Thermostat" code for a window fan using ioBridge
# written by K-Maub, 8/3/2010
import pywapi
import socket
import urllib
import simplejson
import math
import time
# Thermistor Values
beta = 3907.
r25 = 10000.
pullupR = 10000.
# ioBridge Values
ioKey = 'YOURMODULEKEY' # module key
widgetID = 'YOURX10WIDGETID' # widget ID
zipCode = 'YOURZIPCODE' # zip code of your residence
lowTemp = 65. # don't want to go lower than this temperature
CtoK = 273.15 # unit conversion
nom_temp = 25. # nominal temperature for thermistor
tempChannel = 1 # ioBridge channel for thermistor
fanOn = False # initial state of the fan
pauseTime = 60 # loop time in seconds
socket.setdefaulttimeout(10) # need to not crash if url calls hang
change_state = False
while True:
# Grab weather information from a service
try:
SeattleWeather = pywapi.get_weather_from_yahoo(zipCode, 'english')
except IOError:
print 'Problem reading temperature from Yahoo'
outsideTempF = float(SeattleWeather['condition']['temp'])
# Grab data from ioBridge
moduleURL = 'http://www.iobridge.com/api/feed/key='+ioKey
try:
ioBridgeState = simplejson.load(urllib.urlopen(moduleURL))
except IOError:
print 'Problem reading temperature of the room'
#print ioBridgeState
raw = int(ioBridgeState['module']['channels'][tempChannel-1]['AnalogInputRaw'])
# Calculate the resistance measured by ioBridge
resistance = pullupR * raw / (1023.-raw)
# Calculate temperatures (thermistor equation from Extreme NXT)
temperature = (beta*nom_temp - CtoK*(nom_temp+CtoK)*math.log(resistance/r25)) / \
(beta+(nom_temp+CtoK)*math.log(resistance/r25))
insideTempF = temperature * 9./5. + 32
# Decide if we need to turn the fan on or off
if (insideTempF > outsideTempF) and (insideTempF > lowTemp) and (not fanOn):
widgetURL = 'http://www.iobridge.com/widgets/static/id='+widgetID+'&value=1'
change_state = True
elif ((insideTempF < outsideTempF) or (insideTempF < lowTemp)) and (fanOn):
widgetURL = 'http://www.iobridge.com/widgets/static/id='+widgetID+'&value=0'
change_state = True
# Do it!
if change_state:
try:
trash = urllib.urlopen(widgetURL)
except IOError:
print 'Problem changing X10 state'
else:
change_state = False
fanOn = not fanOn
# Minute by minute display
print 'Time: '+time.strftime('%X %x %Z')
print 'Inside Temp: '+str(insideTempF)+' F'
print 'Outside Temp: '+str(outsideTempF)+' F'
if fanOn: print 'Fan On'
else: print 'Fan Off'
print
# Wait before rinsing, repeating
time.sleep(pauseTime)
Some remarks; I should probably put some buffer in there so that if the outside and inside temperatures are close, it doesn't switch on and off every minute. Also, I have to run the code from my computer that's more or less tethered to the ioBridge. If I had a serial board, I'd try hooking it up with my Arduino, so I could have a more independent setup. But then I would have to rely on the weather-fetching routine through the ioBridge, as opposed to picking my own. Not a big deal, but worth considering.