|
|
|
|
Temperature Sensors and Environment Conrol
The first part of this is sensing the temperature. The hardware I use for this are some home built sensors based on the DS1820 sensor. You can generally find these sensors on ebay pretty cheaply (about $5.00 each including shipping). Below are a picture of the module I built along with a schematic. I had most of the parts laying around from other projects. A small perf board, a couple of RJ11 plugs normally used for keystone wall plates and some small guage wire to hook it all up. These are hooked, in series, by four wire phone wires, to a 1-wire serial adapter, which enables the sensor to be read on the serial port. This adapter is called a DS9097U-A which, compared to the sensors, are not that cheap: about $30. I have four of these sensors, one outdoors, one in my living room, one in my server room, and one in my crawlspace which has a tendency to get overly cold and freeze the pipes. Details of how they are built can be found at the digitemp website.
Now, to read the sensors, I set up a simple cronjob that runs every minute to query the sensors and write the temperatures to a file. It's a two liner shell script that looks like this:
#!/bin/ksh
pkill digitemp
/usr/bin/digitemp_DS9097U -a -q -c /etc/digitemp.conf \
> /data/temps
sleep 10
php /gdata/www/html/dtgraph/admin/logger.php
The pkill is because sometimes the digitemp process hangs up, so, it will kill whatever hung digitemp processes might be running. The last line is for historal temperature tracking. I use dtgraph for this. So, now, we have a data file containing the temperatures read off the sensors that is updated every minute. Hurray! Halfway there!
Now, to have the furnace automatically respond to those temps. First is the business of recording the desired temperature. I do this with a webpage which you can see at my thermostat page. Please be kind. That really is my thermostat, so, if you screw around with it, please set it back to the temp you found it at. If you view the source for that page, you can see all the javascript I used for the sliders and stuff. The back end script that writes the desired temp to a file and creates the webpage is thermostat3.cgi. So, now we have a method for setting the desired temperature. Now the trick is to get the furnace to know about it. I use X10 for this. I use the CM17 serial module, although, I've also used the CM11 (and prefer it). Every minute, I have a perl script that reads the desired temp and the current temp, and then sends the appropriate X10 signal to the CM17. Once the X10 signal is on the power lines, I use the X10 module UM506 at the furnace. This takes the X10 signal off the power lines and trips a relay accordingly. This relay is wired into my furnace in place of a conventional thermostat. So, when the thermo.pl script runs out of cron and detects that the temperature is lower than the desired temperature based on the values in the text file, it sends an X10 signal to the UM506 via the CM17. That signal goes out over the power lines where the UM506 picks it up and trips the relay on, which tells the furnace to fire up. Alot of this could be consolidated so that the thermo.pl reads the current temp directly from the sensors, but, I use the temperature values in several other places on my website, so, I want a single query process running. So, that's it! Thermostat in a Perl Script!
Have a comment or suggestion?
|
|
|
|