Our Smart Home

Istvan Makary
Wunderman ThompsonBudapest
5 min readNov 28, 2019

Once upon a time, after finishing the renovation of our apartment, I decided to buy a Nest Thermostat and a few Smart Lamps. From the first moment we really enjoyed, that we didn’t have to worry about setting the temperature or remembering to turn off the lamps when we went out. The iOS HomeKit and the Smart Accessories did their job, and controlled everything according to our preferences.

Spying our dogs

One day, my Nest Thermostat died, and after days of googling the possible solutions, I gave up. It was a second generation Nest purchased on ebay, probably an unlucky choice…

In my professional life I’m a Javascript developer, so I decided to create my own Smart Thermostat.

My Smart Thermostat

I decided to purchase a Raspberry PI (55 dollars) a BME 280 temperature sensor (3.2 dollars) and a Bluetooth Relay Switch (9.6 dollars) to build my Smart Heating System. As you can see, the costs are way below of the price of Nest or any alternatives, so I thought it’s gonna be a good experience.

I was planning to implement a Node.js backend which can then be connected to the Relay and the temperature sensor. So, this backend was planned to be the “Thermostat” itself, which collects the temperature information of the temperature sensor and controls the heating through the Relay Switch.

Besides building the backend I also planned to create my own mobile app.

My Smart Home App

Since I have quite deep experience with React Native, I chose this Framework. The whole project relied on a Firebase backend, which was supposed to store the settings from the Customer Application, deliver them to the Node.js backend, which would then in turn send some data, like Current temperature, Heating status, etc… back to the App.

Besides controlling the heating, I engineered this app to be capable of dealing with my smart lamps, customer location and custom automations.

The user interface of my application

My ecosystem was working quite well, but there were serious problems with the Relay’s Bluetooth connection. After some days of running, the Bluetooth connection broke and the server couldn’t connect the Relay any more. In our case, this meant that we couldn’t control the temperature at all. When we were at home, it was “all right”, a simple restart solved this issue, but while we were away on a skiing holiday it didn’t work, and when we arrived it was 8 Celsius in the flat.

It was pretty frustrating watching the temperature diagram in the Application going down continuously… Luckily we didn’t give up :)

Rebuilding my system

After our negative experiences with the Bluetooth switch, I decided to build a much more robust system. To do so I purchased a Raspberry PI Zero W and I decided to control the Relay using its GPIO ports.

I have some background with circuitry, so when I went to buy the necessary accessories to control the relay switch, I was forced to recognize it would not be enough.

Luckily, I have a friend who could help me out with a proper circuit, so I could start building the module shown below:

GPIO Relay controller

It’s a really simple circuit which makes the Relay handling much more efficient than doing it over Bluetooth.

Work in Progress — putting it in a box

After finishing the hardware part, I wrote a small Node.js server on the PI Zero using the rpi-gpio package to control the Relay from the server.

Using Apple HomeKit trough the iOS Home App

There were some other bugs with my server & app, and I didn’t have time for the continuous fixes, so I decided to give up, and rebuild our Smart Home using Apple HomeKit.

You might ask: How was this possible, given that Apple hadn’t opensourced it?
There is a cool npm module called homebridge which is a Node.js (reverse engineered) implementation of HomeKit Accessory Server. Using this module you can easily set up your smart devices, choosing from hundreds of existing plugins which need only to be configured.

I could, find the proper plugins for my Xiaomi Mi Temperature sensor and for the BME 280 sensor, but I was not able to find a solution for my smart thermostat, even if there are multiple similar projects on the internet.
Usually a Smart Thermostat has its own temperature sensors, and uses their temperature to control the heating. This means in the iOS Home app you see the thermostat as one unit displaying the average temperature, while in reality it contains sensors in multiple rooms. My goal was to keep the temperature sensors as individual devices in the Home app, and use their data as an input source in my Smart Thermostat.

I ended up implementing my solution as a Homebridge Platform which is able to create dynamic accessories, so I could mount my temperature sensors and share their reference with the Thermostat.

The documentation of implementing Platforms in Homebridge is not detailed enough to develop a module like mine without some degree of try and error… Luckily after some days of hacking, I could create a stable solution.

Summary

The implementation using the homebridge platform is running without issues since a couple of months, so I’m confident to say our smart thermostat is finally done and stable.

As a developer it was really cool to play around in the word of IoT and build some real hardwares. If you want to impress your family by showing them the power of programming & you have some knowledge in circuits, I would not miss trying it out! ;) The first time when you voice-control your place in front of your family feels awesome ❤

--

--