Book Image

ESP8266 Home Automation Projects

By : Catalin Batrinu, Constantin Tambrea
Book Image

ESP8266 Home Automation Projects

By: Catalin Batrinu, Constantin Tambrea

Overview of this book

The ESP8266 is a low-cost yet powerful Wi-Fi chip that is becoming more popular at an alarming rate, and people have adopted it to create interesting projects. With this book, you will learn to create and program home automation projects using the ESP8266 Wi-Fi chip. You will learn how to build a thermostat to measure and adjust the temperature accordingly and how to build a security system using the ESP8266. Furthermore, you will design a complete home automation system from sensor to your own cloud. You will touch base on data monitoring, controlling appliances, and security aspects. By the end of the book, you will understand how to completely control and monitor your home from the cloud and from a mobile application. You will be familiar with the capabilities of the ESP8266 and will have successfully designed a complete ready-to-sell home automated system.
Table of Contents (16 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback
Building a Home Thermostat with the ESP8266
Using ESP8266 to Build a Security System


Since the first house was built, man has made a conscious effort to improve it, to make it more comfortable and safe. Home automation or domotics has been around since decades in terms of lighting and simple appliance control and only recently has technology caught up for the idea of the interconnected world, allowing full control of your home from anywhere, to become a reality.

ESP8266 is a low-priced chip that allows you to build home automation system effectively. This book will demonstrate a few easy-to-implement home automation projects ranging from controlling a relay, to reading all kinds of parameters such as temperature, humidity, light, or presence. It also allows you to send the values from your ESP8266 modules to your private cloud. More than that, you will design and build a secure cloud and a mobile application that can bring comfort and safety at your fingertips. By the end of this book, you will be capable of building your own interconnected devices for better living.

There are many choices available in the market and you can choose your own ESP8266 module based on your project needs. Some of the widely accepted home automation projects are building a portable environmental monitor, wireless remote LCD, Air Gesture AC Dimmer/Switch, Wi-Fi Smart Garage Door, IoT Air Freshener, and internet-enabled smoke alarm.

Home automation is definitely here to stay as it continues to fill the needs of consumers who are looking for better ways to access information and control the home environment. With home automation, you can control your device the way you want.

What this book covers

Chapter 1, Getting Started with the ESP8266, covers the basics of the ESP8266 Wi-Fi chip, including how to choose a module, and how to configure the ESP8266 chip. You will learn how to configure the ESP8266 board, so it can be used for the rest of the book. You will know how to choose the right ESP8266 module as there are many choices available on the market. After that, you will learn the basics of the ESP8266 Wi-Fi chip, and learn how to read data from a sensor connected to the chip.

Chapter 2, Building and Configuring Your Own MQTT Server, speaks about building and configuring an MQTT server to be used with the ESP8266. The chapter will instruct you on how to get, compile, install, and configure an MQTT server to be used in the chapters as a central MQTT gateway.

Chapter 3, Building a Home Thermostat with the ESP8266, covers how to build a home thermostat using the ESP8266. You will learn how to measure the temperature in your home using a thermostat, how to display this temperature on a screen, and also how to adjust the temperature according to your wishes.

Chapter 4, Control Appliances from the ESP8266, shows how to control home appliances that are often present in a house, such as lamps, LEDs, and other appliances. You will learn how to control several home appliances using only the ESP8266 Wi-Fi chip. Thanks to the Wi-Fi connectivity of the chip, you will be able to control all the appliances remotely.

Chapter 5, Using ESP8266 to Build a Security System, covers how to build a complete security system based on the ESP8266. You will learn how to connect to your ESP8266 module's elements that are necessary to a security system, such as motion detectors, cameras, and alarms. You will then be able to build a complete security system based on these elements.

Chapter 6,Securing Your Data, This chapter is about adding SSL to secure communication between the ESP8266 modules and broker. You will learn to encrypt the packets in order to secure the data and make sure that your communication remains private.

Chapter 7,Real-Time communication, there are some use cases where you need to see data retrieved from the sensors in real time, to log the values in a database or to show them on a nice graph.

Chapter 8, Adding a Mobile Application to Your Smart Home, to complete the journey in the smart home world and have your house in control from your phone, you will create an Android mobile application.

What you need for this book

In order to start working with ESP8266, you will need a series of software and hardware components. The ESP8266 chip and its module, sensors like ADXL345, temperature sensors, PIR sensors, and cables, soldering tools. In every chapter, I've tried to make a good picture and provide the good description.

For the software, we would require PC with Windows and VirtualBox installed. For application Arduino IDE with at least 1.5.3 SDK version for the ESP8266, Lubuntu Linux 16.04 installed in Virtual Box, Docker installed in Virtual Box, InfluxDB and Grafana installed in Virtual Box.

Who this book is for

This book is for people who want to build connections and inexpensive home automation projects using the ESP8266 Wi-Fi chip, and to completely automate their homes. A basic understanding of the board would be an added advantage.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The following is the setup() function to connect to the Wi-Fi network."

A block of code is set as follows:

#include <ESP8266WiFi.h> 
#include <JsonListener.h>
#include "WundergroundClient.h" 

Any command-line input or output is written as follows:

sudo openssl rsa -in ca.crt -out newca.pem

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on Sign in to network."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.