Weston Bassler
Jul 26 · 9 min read
Hefeweizen One Gallon (24/7/19)

Recently, I have started brewing my own beer. My wife bought me a 1 gallon kit for Father’s Day so I could dive right in and start learning the craft beer brewing process. It is something that I have always been interested in learning but never took the time and space has been limited. The whole beer making process has always intrigued me and is something that is way out of my element.

One important aspect of brewing that I have learned is that the fermentation process requires certain room temperatures (Ales 60–70F or 15–21C). With my love for beer, tech and the need for a new side project, a light bulb went off. Why don’t I build by own room temperature monitoring system?

In this article I’ll explain how I used a spare Raspberry Pi and a spare DHT11 sensor to build a room temperature monitoring system complete with dashboard and alerting using InfluxDB, Grafana and IFTTT. I’ll share my code and explain how it can be reused as well as provide more information on how you can get started creating your own similar project (see Github below).


Getting Started

First, You will need some form of Raspberry Pi with full python support and with GPIO enabled. You will also need a sensor that measures temperature. Luckily, I had a spare Raspberry Pi 3 and a spare Adafruit DHT11 sensor sitting around from my days trying to learn electronics from an Arduino. Yes, a DHT11 is a little old but you can still pick up one of these sensors for really cheap on Amazon or many other places on the the Internet. DHT22 sensor would also work directly with this project.

I would rather spend more time focusing on other aspects of this project and not a ton of time explaining how to setup a Pi and temperature sensor on a Pi. There is a ton of information out there on the that explains how to do these things. Also, as mentioned, you could use many different combinations to achieve this but here is a link to an article that really helped me get started:

Python Setup

Let’s prepare our Python environment on our Pi. It is completely up to you if you would like to use a python virtual environment for this but I typically don’t use them on a Pi. The steps below do not use an environment.

Since I used a DHT11 sensor on a Pi, I found that Adafruit actually provides a convenient Python library that you can easily take advantage of and install into your environment. The docs are really good and they provide several examples for how you can use the library for not only DHT11 sensors but also for DHT22 sensors as well.

From your Pi, you can simply install it via pip:

sudo pip3 install Adafruit_DHT

In this project we are sending the output from the DHT11 sensor to InfluxDB which I learned also has a nice Python library that is very simple to install and comes with very good documentation.

Also from you Pi, install “influxdb-python” library:

sudo pip3 install influxdb

Finally we need the requests library:

sudo pip3 install requests

Our Pi is now ready to run our Code!

InfluxDB and Grafana Setup

If you are unfamiliar with InfluxDB or Grafana, I would highly recommend reading docs before you get started. InfluxDB is going to be the time series DB where we ship the output of the temperature sensor from our Pi and Grafana is going to be what we use to create a dashboard that displays current temperature and also a history of the temperature in the room. Both of these are very popular tools for IoT style projects.

It is very easy to get started with both of these projects and I highly encourage you to use Docker for both. I have a spare “Lab” machine at my house that I use for several home projects where I actually run both Grafana and InfluxDB for multiple things. Even though you could, I would likely not install Grafana and Influx on the same Pi as your sensor as I imagine it would get pretty heavy usage.

With Docker installed, run the following commands to get an InfluxDB and Grafana instance up and running:

# For Influx
sudo docker volume create influxdb
sudo docker run -d --name influxdb -p 8086:8086 -p 8083:8083 -v influxdb:/var/lib/ifluxdb -e INFLUXDB_ADMIN_ENABLED=true -e INFLUXDB_USER=telegraf -e INFLUXDB_USER_PASSWORD=secretpassword influxdb
# For Grafana
sudo docker volume create grafana
sudo docker run -d --link influxdb --name grafana -v grafana:/var/lib/grafana -p 3000:3000 grafana/grafana

For convenience, I also supply a docker compose file in my repo but it is not yet tested. As I stated, I already had an Influx and Grafana setup created prior to this project that I am taking advantage of. The compose file is to provide nothing more than convenience to the reader.

The above exposes Influx on port 8086 with username “telegraf” and password “secretpassword” and exposes Grafana UI on port 3000.

Create a new DB in Influx called “sensor_data”:

curl -i -XPOST http://influx:8086/query --data-urlencode "q=CREATE DATABASE sensor_data"

Go to your Grafana UI (http://grafana:3000) and create your initial login credentials.

Now go and create the data source to Influx with the following:

Remember the password is “secretpassword”. Click “Save and Test” when done.

This creates our initial connection between Grafana and Influx. The Dashboard feature of this project is really to whatever the user wants and has no dependency on the actual code. I will briefly describe what I did to create my Dashboard and show a screenshot of the outcome but this can and should be modified to fit user needs.

If you have any further questions or are lost, please check out this article as a good reference guide:

IFTTT

In my opinion this is the most interesting feature of this project and can be used in other projects as well. We will be using IFTTT Webhooks for alerting based on temperature thresholds. If you are unfamiliar with what IFTTT is and what it provides, please go over and read more about this awesome free service. Great Android App too!

First, you will need to create an account and register.

Once your account is created, head over and read the documentation for how webhooks work. Go to https://ifttt.com/maker_webhooks and click on “Documentation”. This gives you an opportunity to see how it works. You are provided a key and with your “event” (name of IFTTT applet) and you can make a POST or GET to the URL to trigger your alert.

https://maker.ifttt.com/trigger/{EVENT}/with/key/{IFTTT_KEY}

The “{EVENT}” will be the applet name that we create and the “{IFTTT_KEY}” will be the key that we use. Please take note of this key!

As you will soon find out, IFTTT integrates with basically everything under the sun. For time saving purposes, let’s create a simple applet that will send us an SMS message alerting us that our temperature threshold has been breached along with the current temperature.

Go to “Create” under your account and then Click on the “+” to get started:

Then search for and click on “webhooks”:

Then click on “Receive a web request”:

Let’s call our Event Name, “temperature_alert:

“Create Trigger” and then click on “+” for “That”:

Search for “Android SMS”:

Enter your phone number with the following message:

NOTE: Ensure that you include ingredient {{Value1}} this will be the temperature value that we get from our sensor and send along with our Webhook.

Click “Create Action” and you are done.

The Code

In order to keep from having to touch the actual code itself, we provide our variables inside of a settings.conf file. In this file we specify the settings for Influx, our sensor, IFTTT and for what we would like to set as our low and high temperature thresholds. Copy both the settings.conf and the sensor-iot.py from the Github Repo to your Pi.

Example settings.conf:

[influxdb_settings]
host = "192.168.1.99"
port = 8086
user = "telegraf"
password = "secretpassword"
dbname = "sensor_data"
interval = 60
[sensor_settings]
sensor = "DHT11"
sensor_gpio_pin = 4
measurement = "dht11"
location = "office"
[alerting_settings]
ifttt_event_name = "temperature_alert"
ifttt_key = "thisISnotARealKEY1837"
temperature_threshold_low = 70.0
temperature_threshold_high = 60.0
threshold_count = 5

The above example settings will send output to from our sensor every 60 seconds to influx and has the temperature thresholds no higher than 70F but no lower than 60F. If these thresholds are met 5 times, it will trigger our temperature_alert applet via webhook that we created above and we will receive an SMS message from IFTTT.

We will execute this script in the background to keep it running even after we logout:

sudo python3 sensor-iot.py &

The Dashboard

For my Dashboard I decided to create a gauge visualization for current humidity, 2 bar gauges for current temperature and a graph for a historical view of the room over the last 24 hours. As mentioned, this Dashboard should be fit to your needs. My goal was something simple and compact for all the measurements.

Also to note, I decided to use a Phone call from IFTTT instead of an SMS. I get far too many notifications on my phone to notice an SMS message right away. Please feel free to use any of the many offerings by IFTTT!


I have been running this project for almost 2 weeks now and it has alerted me every time the room has gone over 70F! During the summer, even in the basement, we aren’t going to see the room under 60F. On the days that we hit over 100F temperatures I was notified quite a few times. I was able to safely get my brew into a cooler space for the time being to allow for it to ferment at the desired temperatures. Hopefully this will make for a very delicious outcome!

Overall I have been very happy with this little project with the very little time I have had to work on it so far. It has been fun to work on something that fulfills two of my favorite hobbies. I hope to add several more features to this in the future as well as spruce up my code.

Happy coding and brewing!

Weston Bassler

Written by

Husband. Father. Friend. Developer. Engineer. Tech. Equality. (SRE @ D2iQ)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade