Building a smart thermostat for an old fan coil unit (FCU) with a Raspberry Pi

Abraham Montilla
Voice Tech Podcast
Published in
6 min readAug 21, 2019

The main highlight of a Raspberry Pi microcomputer is how easily you can write some code to control stuff like an LED, read data from a sensor or even just having your very own low-cost dedicated server. Also, once you start working with it you will inevitably want to do more complex projects.

DISCLAIMER: Notice that fan coil unit wiring may involve high voltage manipulation, any handling of this kind is under your own responsibility.

In this project I’ll show you all the elements to build a “SmartCoil”, as I like to call it, by using several components you could find in the Adafruit store or Amazon.

As a plus, this project is Alexa powered, which means you could use your own Amazon Echo to control the device by saying stuff like “Alexa, turn on the AC”. How cool is that? :)

You could find the full source code in the following Github repository https://github.com/amontilla0/smartcoil.

Main components

  • One (1) Raspberry Pi model 3B+ as the central microcomputer. A smaller Raspberry Pi Zero W should do the trick too.
  • One (1) PiTFT 2.8" Capacitive Touchscreen that shows the GUI and takes input from the user.
  • One (1) 4-Channel Relay Module to control the water valve and fan speed (low, medium or high) of the FCU.

https://www.amazon.com/gp/product/B00KTEN3TM

  • One (1) BME680 Temperature+Humidity+Air Quality Sensor to help the app monitor the indoor status and take the corresponding action (cooling, heating or resting).

BME680 configuration

To get information from the environment sensor, I used the provided Python code for this peripheral, which can be found here, as part of the Github repo.

The main modification I had to do was to adjust the temperature offset comparing the readings to a thermometer I had at hand. That way the readings were more accurate for my specific case.

Controlling the 4-Channel Relay Module

This component is easy to control by using GPIO. The need for relays is to isolate the high voltage handling outside of the Raspberry Pi, otherwise we might just fry the brain of our smart thermostat.

I specifically used pins 17, 22, 23 and 27 to turn on/off the water valve, fan low speed, fan mid speed and fan high speed correspondingly. The specific code is found here in the repo.

GUI

For the graphic user interface I used the Kivy Python Library. A very handy tool to build visual interfaces relatively fast (besides hitting your head against the wall to make the kvlang file work the way you want it to).

SmartCoil GUI built with Kivy Python Library

The image above shows the following items:

  • Left: A slider to set target temperature, as well as a label stating the current indoor temperature, both in Fahrenheit.
  • Top right: Buttons to set the fan to low, medium or high speed and another one to turn off the SmartCoil.
  • Center right: Icons reporting indoor humidity and indoor air quality, both in percentages.
  • Bottom right: A label showing outdoor temperature and an icon reporting current weather forecast.

Specifically for weather updates, I used a complete API (Norwegian Meteorological Institute) that comes with a corresponding library in Python:

Build better voice apps. Get more articles & interviews from voice technology experts at voicetechpodcast.com

Internal Database

Although the GUI shows limited but key information, I’m also saving more content into a SQLite database locally in the Raspberry Pi. This data will be used to do some exploration and, in the future, generate some smart schedule based on historic patterns. The items stored in the DB are:

  • Temperature, humidity, air pressure, gas resistance and air quality, coming from the BME680 sensor.
  • Current state of the GUI such as target temperature and fan speed set by the user either via touchscreen taps or voice commands.
  • Latitude, longitude, outdoor temperature, humidity, pressure, forecast condition, wind speed, wind direction and precipitation percentage. All coming from the weather API.

The structure of the database can be found here, and could be analyzed either with the sqlite3 command line tool or with its corresponding Python library under the same name.

Smart Home Alexa skill

For this part of the project, I initially created a regular Alexa skill but that involved saying something like “Alexa, tell SmartCoil to turn on the AC”, which I thought was painfully long to say. To make it more elegant, e.g. “Alexa, turn on the AC” or “Alexa, fan speed to high”, I had to create a smart home skill.

You can easily follow the steps to create a smart home Alexa skill with the official Amazon guide for that. That post has the skeleton to control a power switch (Alexa.PowerController) and it served as base for my own project.

My skill, however, needed to use several controllers instead of just one. In particular:

  • Alexa.ThermostatController, which controls the SmartCoil on/off status as well as target temperature.
  • Alexa.TemperatureSensor, which gets current indoor temperature info.
  • Alexa.RangeController, which controls the SmartCoil’s fan speed to low, medium or high.

To see the structure of my NodeJS methods (used in AWS lambda as part of the skill), see the related code in the repo. Also, to see the corresponding responses that NodeJS is waiting for, see the class for the Flask app in the repo as well.

Notice that I used pagekite as a secure way to make the server publicly available via SSH Tunneling. You can create your own account for free at https://pagekite.net/signup/. The account starts as a trial for a month and then you could renew the subscription for a modest amount of money. If that may not be an option, you could chat with them if you are using the account as a school project in order to get a really nice discount.

Assembling the SmartCoil

The prototype for the smart thremostat went through several phases. Starting by using a protoboard to wire and test functionality.

Protoboard with wiring for BME680 and 4-channel relay module

Once all the components were tested, I used a perma-proto to solder everything together. For reference, find a picture of the real thing and a fritzing layout of the circuit below (also available as a fritzing sketch in the repo).

Notice that for the layout, the PiTFT is not depicted. Just have in mind that this touchscreen is easily attached on top of the Pi and it exposes all 40 pins back again, where you could attach a standard 40-pin ribbon cable.

All components soldered together into a perma-proto plate
Detailed layout of the SmartCoil circuit

Once all the wires were soldered, it was time for the casing. I initially thought of a 3D printed case, but since it would be time consuming to design the model and then find a printing provider, I went for the handcrafted option. Having a couple boxes from a recent Amazon delivery, it was just a matter of cutting, pasting and painting a small case that could hold everything together.

I wanted to expose both the touchscreen for GUI manipulation, and the BME680 so that it could make unobstructed indoor readings. All the steps are shown in the pictures below.

Cutting, pasting and painting the SmartCoil case
Fully-functioning SmartCoil mounted on wall

And that’s it for this project! If you haven’t, don’t forget to watch the video for a demo of the product, including interaction by voice using Amazon Alexa.

--

--