Computer Control – Physical Input and Output

Computer Control – Physical Input and Output

I’ve briefly posted about my home heating control system.  The reason I’m revisitnig it is I’d like to gather all the pieces together and show how they work.  My heating system uses a hot water pump that circulates through pex tubing underneath the flooring, commonly known as radient floor heating.  Controlling when the pump turns on or off is the focus of this discussion.

tacopump

The rating of the pump, a Taco 006-B4 Bronze Circulator Pump 3/4-Inch Sweat, is 115VAC at .52A.  This rating is needed in order to choose the correct relay to turn the pump on or off.

I used a product named WebRelay (http://www.controlbyweb.com/webrelay/) that is made by Xytronix Research & Design based out of Utah.  The device has a thermostat input to turn the relay on or off.  The relay is rated for 240VAC or 30VDC at 12A, which is more than enough.  I initially used a thermostat in my living room to turn the pump on or off, however this proved to be inefficient.

webrelay

The nice thing about the WebRelay is that the relay state can be controlled by sending web requests to it.  The device will change the relay state depending on the xml web page requested from it.  The exact url for each state is as follows.

Turn On

http://ip address of webrelay>/state.xml?relayState=1

Turn Off

http://<ip address of webrelay>/state.xml?relayState=0

It’s important to point out that there is absolutely no security in the design.  The url is non secure and there is no authentication required to change the relay state.  I would recommend not placing these devices on internet facing networks.  These are meant to be used out of band.

Since the relays can be controlled with web requests, I decided to have a computer issue wget commands to change the state of the relays.  However, I needed a condition that would merit changing the condition, much like a thermostat.

supergoose_ii_no_bg

I chose to use an environment monitoring product called Watchdog that is made by ITWatchDogs based out of Nebraska.  The product I use is no longer available, but they do offer a similar product called a Watchdog 100.  The device connects to a variety of sensor devices and can represent the readings on a web page.  It can also provide the readings when polled with SNMP.  I used the SNMP feature to read temperature values, this was my thermostat alternative.

snmpget -v 1 -c public <ip address of watchdog> .1.3.6.1.4.1.17373.2.4.1.5.2

The last piece of the puzzle is the control computer.  I use a Linux based system that runs a bash script every 15 minutes.  It gathers the temperature value from the Watchdog with a snmp poll and enters that reading into a variable.  It then creates a variable based on the current time.  Based on the conditions I defined, it will either turn on the relay or turn it off by issueing a wget command to the WebRelay.

Here is the code I use for that bash script.

#!/bin/bash
# this runs every 15 minutes

# Get variable values

# Read Time
date=$(date +'%Y-%m-%d %H:%M:%S')
read Y M D h m s <<< ${date//[-: ]/ }

# get the reading from the sensor and overwrite it to a file
# gives back iso.3.6.1.4.1.17373.2.4.1.5.2 = INTEGER: 6
FGRead=$(snmpget -v 1 -c public <ip address of watchdog> .1.3.6.1.4.1.17373.2.4.1.5.2)

# parse out everything after the colon character :
FGValue=${FGRead#*:}

# Process conditions
# Default condition is OFF

# First Nested condition - First Turn ON if Gable Temp goes below 15 degrees C.
if [ "$FGValue" -lt "15" ]
then
# Second Nested condition - Only Turn ON if Hour is between 2am and 10pm
if [ "$h" -gt "1" ] && [ "$h" -lt "22" ]
then
# Turn ON Heat Pump    
wget http://<ip address of webrelay1>/state.xml?relayState=0
wget http://<ip address of webrelay2>/state.xml?relayState=1
rm -f state.xml?relayState=0
rm -f state.xml?relayState=1
else
# Third Nested condition - Only Turn ON if Temp goes below 6 C.
if [ "$FGValue" -lt "5" ]
then
# Turn ON Heat Pump    
wget http://<ip address of webrelay1>/state.xml?relayState=0
wget http://<ip address of webrelay2>/state.xml?relayState=1
rm -f state.xml?relayState=0
rm -f state.xml?relayState=1
else
# Turn OFF Heat Pump    
wget http://<ip address of webrelay2>/state.xml?relayState=1
wget http://<ip address of webrelay2>/state.xml?relayState=0
rm -f state.xml?relayState=1
rm -f state.xml?relayState=0 
fi 
# Default OFF 
echo "" 
fi 
else 
# Turn OFF Heat Pump 
wget http://<ip address of webrelay1>/state.xml?relayState=1 
wget http://<ip address of webrelay2>/state.xml?relayState=0 
rm -f state.xml?relayState=1 
rm -f state.xml?relayState=0 
fi

I’ve done some extra things as well.  Since the Watchdog supports snmp, I poll it with Cacti and graph the readings.  This gives me some history and is a great way to tweek the control for better results.

frontgabletemp

At some point, I’ll do a writeup about replacing the relay unit and environment monitor with a raspberry pi.  In the meanwhile, I hope this post has given you a warm and fuzzy feeling.  Enjoy.

Comments are closed.