SNMP Heater

SNMP Heater

Introduction – a practical need

I want to automate the task of changing when my house heater turns on or off.  You’re probably thinking, use a thermostat.  That works with conventional forced air heating.  We use radiant floor heating that is from the hot water supply for the home.  There is a wider hysteresis.  It’s more likely the warmth effects will last longer after the conventional thermostat triggers off.  This is also the case when it needs to heat the room.

So I decided to use a sensing network that consists of a SNMP device and several temperature sensors.  I am able to poll the readings from the device and execute commands.  The heater is controlled by a flow pump.  The power supply to the flow pump is controlled by a relay that has a web interface.  I can change the relay state by sending web commands.

This is more of a novelty than a topic I want to formally cover this quarter.  However, I think it is worth making note of since it can lend insight.  Years ago I had done this using Windows and Task Scheduler.  It was messy and very confusing.

Details – how it was possible

Now I do this using Linix and this shell script.


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

# get the reading from the sensor and overwrite it to a file
snmpget -v 1 -c public 192.168.0.200 .1.3.6.1.4.1.17373.2.4.1.5.2 > FrontGable.txt
# gives back iso.3.6.1.4.1.17373.2.4.1.5.2 = INTEGER: 6

# write file contents to a variable
FGRead=$(<FrontGable.txt)

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

# turn over temp relay on or off based on reading of greater than 13
if [ $FGValue -gt 13 ]
then
  # turns on the overtemp relay
  wget http://192.168.0.100/state.xml?relayState=1
else
  # turns off the overtemp relay
  wget http://192.168.0.100/state.xml?relayState=0
fi

# house cleaning 
rm -f FrontGable.txt
rm -f state.xml?relayState=0
rm -f state.xml?relayState=1

I setup the CRON job in Webmin.  It does the trick.  When the temperature outside gets above 54° Fahrenheit, the heat is shut off.  I have other conditions outside of this that control the heat as well.  But I wanted to make mention here.  The parse command is something I found interesting.  I can see this being put to use in later work.

Summary – what just happened

There were a few elements that made this work.  First was the Linux box that ran all the commands centrally.  Next was the SNMP device that gave temperature values when it was polled.  Then were the web enabled relays the changed state based on page requests.  Based on the outside temperature value, the relay is turned on or off.  That’s it.

I found a way to parse values out of a string in shell.  I also used conditional if/else statements to run commands based on the variable.  Enjoy.

 

Comments are closed.