Author Topic: Thermostat without heater/A/C  (Read 518 times)

k-maub

  • Newbie
  • *
  • Posts: 24
Thermostat without heater/A/C
« on: August 04, 2010, 01:53:45 AM »
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.

Code: [Select]
# "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.
« Last Edit: August 04, 2010, 01:55:27 AM by k-maub »

nick

  • Full Member
  • ***
  • Posts: 174
Re: Thermostat without heater/A/C
« Reply #1 on: August 07, 2010, 10:46:26 PM »
I'm doing something very similar with controlling the humidity in my basement, depending on conditions I either run a dehumidifier or a vent fan.  I use X10 to turn them on and off.

I came to the conclusion that I want my control software running on a server in a server room.  Nothing else is going to be reliable.  I have an Arduino use the iobridge serial API to send a GET command which hits my server every five minutes or so. Server side code handles everything from there.

I have been piecing this together for almost a year now. Initially I had A LOT of problems with the serial API with messages being lost or delayed for hours or days, or the IOBridge module locking up.  In the past four weeks or so it seems like the reliability has improved dramatically and now about 99% of my GETS are making it through.   

k-maub

  • Newbie
  • *
  • Posts: 24
Re: Thermostat without heater/A/C
« Reply #2 on: July 31, 2011, 04:36:25 PM »
I'm not sure if your code changed, or the python library got updated, but now when I try to grab the JSON "packet" from ioBridge, I get an error, because there aren't supposed to be trailing commas.  Is it possible for you guys to serve up JSON that follows that restriction?

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Thermostat without heater/A/C
« Reply #3 on: August 02, 2011, 09:30:57 AM »
We are looking into it. Thanks for letting us know.
ioBridge Support
Community Team

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Thermostat without heater/A/C
« Reply #4 on: September 09, 2011, 02:12:20 AM »
This has been fixed in a recent update. Sorry for the late reply. Can you confirm that your error went away?

Thanks!
ioBridge Support
Community Team