Archive | April 2016

Red River Thermostat 2.0

I’ve made enough changes to the thermostat project that I figured it was worth an update. Firstly, I changed the way the web interface interacts with the thermostat daemon. Previously the web interface was hosted on a http server that was built into the webiopi package. This worked ok but it limited things like php scripting and methods for connecting to the database. Now, all of the web stuff is hosted on a separate lighthttpd daemon and it fetches information about the sensors and the state of the thermostat via a socket to the running thermostat daemon. PHP scripts on the http server take care of connecting to either the daemon or the mysql database and pass information to the javascript in a sensible way which makes things…….simpler(?)  It’s easier for me to know what’s going on anyhow, and it’s forcing me to learn alot more about javascript, PHP, and web app development

With the more capable http server I was able to incorporate some more interesting visualizations for the temperature display (gauges came from here).

Screenshot from 2016-04-23 07:05:11


The reasoning behind creating the socket based communications with the thermostat was that it would make creating new control applications simpler. In the long run I might make an android app that’ll be a bit snappier than the web interface. A kodi plugin is another possibility, to allow me to see/change the thermostat from our media pc. Both of these are made easier by having a socket based connection that spits out easy JSON blobs for processing. Here’s an example of what comes from a request for sensor parameters:

{ “Living Room”: { “humidity”: 0, “i2c_address”: “0x77”, “pressure”: 97281.0, “read_successful”: true, “temperature”: 29.4544021645641, “type”: “bmp”, “webiopi_name”: “bmp0” } },
{ “Bedroom”: { “humidity”: 0, “ip”: “”, “pressure”: 0, “read_successful”: true, “temperature”: 29.46, “type”: “tmp”, “webiopi_name”: “bmp0” } },
“webiopi”: 1 }

Here’s an example page showing environmental data for the past few days. The outdoor temp looks a little crazy because the sensor catches some sun in the middle of the day. You can see the inclusion of the Time v Gases in the bottom right graph, that’s data being logged from the gas sensor board, which turns out is pretty boring. I guess that’s a good thing though…


Below is a run time graph for the equipment being controlled. Should give an idea of my energy consumption once the database get’s more filled out.


The next thing I’m planning to add is an electricity monitoring page. I ordered some cheap clip on current transformers that I can stick in the panel to read current draw, they can be used to log  our power consumption to the same db, and hopefully can be used to work towards getting our outrageous hydro bills down…

Code is up as always at






Gas Sensors

Since I’m addicted to cheap ebay electronics, I had to pickup an assortment of these MQ Gas sensor modules. I got an MQ-5, 9, and 135. I initially thought that these would all measure different levels of different types of gasses, but after more reading and experimenting it seems like they all seem to measure the same gasses just with different sensitivities. So my board with three of them on it might be overkill but they’re so cheap!

Anyhow, I made use of an arduino nano to serve as a USB ADC. The super basic sketch running on it simply waits on the serial port for “get_aX” command and returns the value read from X analog input as an integer. The connections to these things are dead simple, just provide VCC and GND and then connect the A0 pins to the Ain pins of the arduino. The only catch I found was that they draw about 100-200mA each, which means that if you feed them and the arduino from the USB 5V it can be too much for the USB port. I’m planning on plugging mine into a raspberry pi that doesn’t have much to spare, so I feed the Vcc of the sensors from a separate 5V supply.



The idea is to hook this up to the Raspberry Pi in my basement, that’s already operating as my thermostat/data logger, and have it start logging what it sees….I’m not sure what that’ll be, but I’m curious to see if it can detect any leakage from the water heater or furnace exhaust. After I get some bulk data I might be able to even set it up with an email notification for higher than normal levels of CO or natural gas detected, not that it’ll ever be a replacement for the real CO alarms that’re installed throughout the house.

It works pretty well so far. Tested on the bench it could definitely detect the gases coming off a little butane torch. We’ll see what it shows after spending a week in the basement, I don’t expect to see many gas leaks but it might be able to tell me when it’s time to change the litter box…


It’ll connect up to my thermostat project board via USB. A small python application will be running on the Pi to pull the values off the arduino and log them to the mysql database. Code’s up at for anyone interested