Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/3/d384894001/htdocs/robertobarbero/blog/wp-includes/post-template.php on line 265

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/3/d384894001/htdocs/robertobarbero/blog/wp-includes/post-template.php on line 265

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/3/d384894001/htdocs/robertobarbero/blog/wp-includes/post-template.php on line 265

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/3/d384894001/htdocs/robertobarbero/blog/wp-includes/post-template.php on line 265


Oct 27

Raising (well, measuring) the Temperature

The Raspberry Pi has lots of amazing things (a great support community, the price, the size, …) but what really made me think about getting one is the GPIO, this is the number of pins available to connect the Raspberry Pi with the world.

Immediately came to my mind the idea of playing with it to build a home automation project. From controlling the lights, the level of the rainwater deposit, a basic alarm system… even the heating!!! A quick search over the internet showed thousands of results… I am not the fist one to think about it, so great news, lots of documentation and experiences available to learn.

I wanted to start with the heating project with the idea of programming and also controlling it over the internet. First of all, I need to know what the current temperature is in the house. I have two thermostats already installed (that I will hack in the near future). One is downstairs, in the living room and the second is upstairs in the main bedroom, so I can control two different zones of the house.

I bought from ModMyPi (excellent customer service, by the way) three temperature sensors, one for each floor plus a third one that I would use to measure outdoor temperatures. As soon as they arrived, following the instructions from the tutorial at ModMyPi I had up and running my own little thermostat. I wanted to know if the three would have any deviation sensing temperature, so I tried to connect the three of them in pararell as suggested in the tutorial. I rewrote the python program and the differences between the three were less than 0.05 Celsius.

RPi + Temp sensor

The next step was to place one sensor on each room I wanted to monitor. There is no way of persuading my partner of having a cable crossing half of the house from the living room to my office to wire one of the sensors there, so here comes another of the great things about the Raspberry Pi: price… and as the Spanish government used to say before the crisis, “why buy one if for twice the price you can have two?”… so I used a second Raspberry Pi in the living room to attach the sensor there (I have planned more tasks for this RPi, I’ll write about it in other post).


Outdoor temp sensor

The RPi upstairs has one sensor directly connected to measure the indoor temperature and also using a cable I have connected the third sensor (which has been placed inside a silicone sealed container to prevent it from becoming wet in the lovely London weather).

Finished the hardware part, the software was easy following the tutorials from ModMyPi as a base. I want the RPi placed at my office to be “the brain” of all the home automation project, so the rest of the RPis will send data (temperature, motion, open doors, …) to the main RPi, which will have UDP servers listening, waiting for events and triggering actions based on that events.

This is the code I use for the “client” side. The Python program reads the temperature from the sensor and sends it to the central RPi using UDP. The client runs every 10 minutes and it’s launched by the cron. The central RPi has the “server” side, listening on port 3000, waiting for the clients to send their temperature measurements. There is a third piece of code that writes in a table of a mysql database the temperatures every 10 minutes. I am a beginner in Python, so I guess the code is far from “pythonian”…

It was easy to write a php piece of code and using Google charts I can now see what is the current temperature and also historic data. The next step will be to hack the thermostats and let the RPi control the heating based on the goal temperature.

Temp graphs

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>