PiFace Thermostat Server


I wanted to remotely control the temperature at an off-site facility. I wanted to use a raspberry pi and a piface interface shield.

I found an awesome example program from David Comp:

https://github.com/adcomp/piface-python-websocket-server/blob/master/server.py

I modified the server to add variables for the ambient temperature and the set temperature of the thermostat. I reworked the front-end to include buttons that increment and decrement the thermostat:

Before:


After:


I then wired in the temperature sensor. The unit I chose was sourced from Sparkfun:

https://github.com/adcomp/piface-python-websocket-server/blob/master/server.py

I followed adafruit’s guide to get the one-wire interface working:

https://github.com/adcomp/piface-python-websocket-server/blob/master/server.py

I then added the necessary code to get the server to periodically check the temperature reading from the sensor. I was excited to try multi-threading in Python for the first time, so I added a separate thread to handle the updating of the temperature reading. Coming from a low level background, it was pretty cool to see how Python made this a much easier task.

The thermostat code that I added checks the current ambient temp and compares it to the set temp. If the ambient temp is .7 degrees F below the set temp, the heater output is energized. The heater remains energized until the ambient temp is .7 degrees above the set temp. This included hysteresis algorithm reduces unnecessary cycling of the heater.

The final bit I needed to do was write a launch script to fire off the server on boot/reboot of the pi. Otherwise when I closed out my remote session the server would stop too. Also upon power failure the system comes back on seamlessly. I have had this project working dutifully for over over a year now with no problems!

Here is the server code:

https://github.com/adcomp/piface-python-websocket-server/blob/master/server.py

Leave a Reply