Skip to content

DHT11 Temperature and Humidity Sensor with Rasperberry Pi, Influx, Grafana, IFTTT and Python

Notifications You must be signed in to change notification settings

geekbass/dht11-sensor-iot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temperature and Humidity Monitor

Monitor the temperature and humidity of a room using the DHT11 sensor on a raspberry pi with InfluxDB, Grafana, IFTTT and Python. This project uses a simple python script to send output from the DHT11 sensor to InfluxDB based on an internal value that you provide in a settings.conf file (a sample has been provided). This script will also alert you via custom created IFTTT applet using IFTTT webhooks and set values for temperature_threshold_low and temperature_threshold_high in the settings.conf file.

PLEASE NOTE: This project is a WIP and still under construction. Will likely change and be updated at some point. There are no default values or any real error handling currently.

Prerequisites

  • Raspberry Pi
  • DHT11 Sensor
  • Influx (If not using Docker)
  • Grafana (If not using Docker)
  • Docker (Optional)
  • Python3

Setting up the Pi

There are far too many resources available online to explain or discuss Raspberry Pi setup. To each his/her own. Raspbian was used in the current project.

As good reference for Raspberry Pi and DHT11 setup, please see this doc.

Setting up Python

We will be using a few Libraries that need installed either via pip. Run from your Pi to prepare Python.

pip3 install -y requests Adafruit_DHT influxdb

For more information about these libraries see their docs:

Setting Up Influx and Grafana

For convenience, we are using Docker. You can simply use the provided docker-compose.yml file or issue the following commands steps:

# 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

OR via compose:

sudo docker volume create influxdb
sudo docker volume create grafana
docker-compose up -d

Create the DB using the following:

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

Login into Grafana and setup your connection with the following:

Grafana

Setting up IFTTT

This project uses IFTTT Web hooks to alert you based on the temperature_threshold_low and temperature_threshold_high values in your settings.conf file. You will need to create your own applet based on what kind of alert you would like to receive. Please see the IFTTT site for more information.

You can use the instructions at the Medium Blog post location here.

Running the Script

Once you have completed all steps above, please fill in the settings.conf and put it in the same directory as the script.

Execute in the background:

sudo python3 sensor-iot.py &

If there are any errors, the script will exit. As mentioned currently there is not error handling.

Tests

You may use the following scripts as tests to ensure each indvidual components work as expected.

Testing the Pi and Sensor

Testing Influx

Testing IFTTT

About

DHT11 Temperature and Humidity Sensor with Rasperberry Pi, Influx, Grafana, IFTTT and Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages