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

Oct 17

Let’s get started…

I work as a Solution Architect in a big software company. It’s a great job… but somehow I was missing something… When I studied Computer Science (actually it’s Computing Engineering in my case) I thought I would be doing later a different thing that what I am doing right now…

In the uni we studied the theory behind the computer. And I really enjoyed it, because it was the natural thing to do after playing when I was a child with all different types of electronics (and receiving a couple of electric shocks)…

My father gave me one year for Christmas one of these:

Electro L

And I found it amazing, I don’t know how many hours did I spend building circuits… So the next year I got this:


Soon I started to collect motors, transformers… Combining them with Lego… Serious fun in a sometimes very untidy bedroom that my mum did not like.

And now, it’s time to go back to the origins… I enjoy being a Solution Architect, but I miss playing with electronics. And then I discovered the Raspberry Pi project. A computer the size of a credit card, cheap and most importantly, with a very easy way to extend and connect to the external world.

A few years ago, that was just called automation or control. Today, it’s the Internet of Things, and immediately crossed to my mind to start a home automation project. Why not control the lights, the heating, who gets in, the shopping list, the watering of the garden…

So this blog starts to show how this project goes… and hopefully inspire others to do similar things, as I got inspired by my parents when I was a child… Because kids… we need engineers to build our future… But as important as that, those engineers should have loads of fun while building it 😉