Reader small image

You're reading from  Building Smart Home Automation Solutions with Home Assistant

Product typeBook
Published inSep 2023
PublisherPackt
ISBN-139781801815291
Edition1st Edition
Right arrow
Author (1)
Marco Carvalho
Marco Carvalho
author image
Marco Carvalho

Marco Carvalho is an experienced home automation hobbyist engineer, electrical engineer, and technician. Pursuing his passion for electronics and embedded systems, he created an embedded home automation task scheduler using X10 Home Automation devices in 2006. Nowadays, he uses wireless electronic devices and the Home Assistant software to build different smart home automation applications. As an MSc in Computer Science, Marco has worked with several well-known companies such as IBM, Jabil, Phillips, and Hexagon where he extended his support in development and manufacturing of electronic products. At the time of this publication, he is the Director of Engineering for Apex Microtechnology, where he is involved in the development of high power, high precision analog components.
Read more about Marco Carvalho

Right arrow

Hands-On Project 3 – Creating a Five-Zone Temperature Logger for Your Home

This hands-on project will guide you to create or integrate five commercial Bluetooth thermometers into an ESP32 Bluetooth and Wi-Fi module. It will show how to hack the thermometers to broadcast its data over Bluetooth, configure the ESP32 to get this data, and then share it with other applications, including Home Assistant. The project aims to expand your home automation capabilities, so the chapter will guide you to use some of the add-on tools installed in Chapter 6, such as Node-RED, InFluxDB, and Grafana, to create a temperature logger for your home.

This chapter will show you how to prepare and assemble material to build a five-zone temperature logger, set up a data parser in Node-RED, create and configure a database to store data using InfluxDB, and configure charts to be presented using Grafana. Also, there will be a section explaining how to configure and handle data in Home Assistant. This...

Technical requirements

Like Chapter 7, you will need to be familiar with databases, queries, and chart tools to better understand the concepts presented in this chapter. Also, I recommend you read Chapters 3 and 4, where I explained how to create and hack some devices used in my home. If you are familiar with JSON and JavaScript, you will understand the flow presented in Node-RED. Code and support material could be found at https://github.com/PacktPublishing/Building-Smart-Home-Automation-Solutions-with-Home-Assistant/tree/main/Chapter%2010. Check out the following video to view the Code in Action: https://bit.ly/45aj7Ni

Understanding the five-zone temperature logger system architecture

The temperature logger was born from two main needs I had. The first need was to try to keep the same temperature throughout the entire house, since it has two HVAC systems and the temperatures in the rooms are not the same. The second need (which came later) arose after some research on how to implement a temperature measurement in the rooms, where I saw the opportunity to learn and use different software tools and hardware devices in my projects. Unfortunately, I didn’t succeed in implementing the feedback control performed by the HVAC controller, due to one of the two installed in my house being too old and a modern controller being incompatible. So, I decided to postpone the HVAC control when replacing the old HVAC. So, the project so far helps me verify and monitor the temperature in six locations in my home. The Kids1 and kids2 bedrooms, the kitchen, and the master bedroom temperatures are indoors. The...

Creating and configuring the five-zone temperature sensors and the ESP32 module-based temperature hub

What we will need to do to create the hardware and software ecosystem presented in the last section, and Figures 10.1 and 10.4, is add the Bluetooth temperature sensors and the temperature hub hardware devices and set up the software on them. The Bluetooth thermometers are battery-powered and come with an adhesive sticker, so you can glue them to any room of your home. I have these sensors spread apart in distances varying from 5 to 13 meters. The ESP32 module will just be connected to the power supply, so you can connect it using a USB type A to micro USB type B cable, connected to a USB power adapter, or follow my approach by connecting it to Raspberry Pi, as shown in Figure 1.8 in Chapter 1.

In the following subsections, I will guide you on how to upload and configure the software for the Mi thermometers and also how to install the Tasmota variant in the ESP32 communication...

Connecting the sensors data to a database using 
Node-RED

In Chapter 7, we briefly delved into Node-RED, where we created an automation flow. This flow involved capturing motion from the double measurement sensor introduced in Chapter 3 and combining it with the sunset condition. As a result, an action was triggered to turn on the lights in my garage. In this section, we will use Node-RED to grab the temperature data from the double measurement sensor and the Bluetooth Mi temperature sensors via the temperature hub, format this data, and store it in the InfluxDB database.

The details about how to create the flow to manage the temperature data capture will be split into three parts:

  • Double measurement sensor data capturing and formatting
  • Temperature hub data capturing and formatting
  • Configuring the data to be stored in the InfluxDB database

I will detail each one of these steps in the following three subsections.

Double measurement sensor data capturing...

Storing data in a database using InfluxDB

We will have to configure two parameters to be able to start storing temperatures in the InfluxDB database:

  • The InfluxDB database
  • A user to access the database

We learned how the InfluxDB database works and how to create it in the Installing and creating databases using InfluxDB subsection in Chapter 7. I recommend you review that subsection, where I showed you how to create the Temperatures InfluxDB database we will use in this project.

Configuring a user to access the database is required to get credentials to store data in the InfluxDB database. We will do this by following these steps:

  1. Open Settings | Add-ons | InfluxDB and click on the OPEN WEB UI button. The Chronograf interface will open.
  2. Select the crown icon titled InfluxDB Admin in the Cronograf sidebar.
  3. Click on the Users tab and then on the + Create User button. In the Create User window, fill the User Name field with your_name, and in the Password...

Presenting the InfluxDB data using Grafana

In this section, we will finalize the temperature logger setup by configuring Grafana, our chart manipulating tool, to get data from the InfluxDB database and present it in charts created in a Dashboard environment. The first thing to do is to configure the database source where we will pull the data from. We will do that by following these steps:

  1. Open Grafana by clicking on the link in the Home Assistant sidebar. Click on the Grafana Configuration menu (the gear icon) and then on Data sources. We will change the configuration we did in Chapter 7 a little. Click on the InFluxDB data source. In the Name field, rename InFluxDB to InFluxDB - Temperatures. Make sure the Database field is filled with Temperatures. Fill in the User and Password fields with your_name and your_password, respectively. Click on the Save & test button. Now, as the database has data, you should get the message datasource is working. 1 measurements found.
  2. ...

Using the five-zone temperature sensor in Home Assistant

When I first created this temperature logger application, I was able to use a configuration in Tasmota to automatically send data to Home Assistant independent of the Tasmota integration. This was done using the setoption19 1 command in the Tasmota console. This option was deprecated, and it is not available in the new Tasmota installations anymore. The alternative solution for this issue is to add the temperature sensors manually in Home Assistant.

Tasmota reports the sensors data using an MQTT JSON message in the following format:

tele/ESP32_TEMPERATURE_HUB/SENSOR = {"Time":"2023-05-15T06:15:49","ATC19f133":{"mac":"a4c13819f133","Temperature":25.7,"Humidity":30.0,"DewPoint":6.8,"Battery":43,"RSSI":-82},"ATC969ab4":{"mac":"a4c138969ab4","Temperature":24.6,"Humidity":41.1...

Summary

In this chapter, we were exposed to different tools besides Home Assistant to create our second hands-on project, the five-zone temperature logger.

We started the chapter by understanding how the system architecture works. We configured the sensor hardware and software and then moved on to the home automation server, where we detailed how to parse the sensor data and send it to be stored in a database. Then, we did a proper configuration of the database so that the information could be stored correctly. Later, we learned how to configure a chart-based tool to create panels to display the temperature and humidity values from the sensors installed in different rooms at my home. We finished the chapter by showing you how to include the sensors information in Home Assistant by editing the configuration file. We had to do that as a workaround due to a deprecated feature in Home Assistant.

The next chapter will be the last of this book. It will introduce the latest trends and...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Building Smart Home Automation Solutions with Home Assistant
Published in: Sep 2023Publisher: PacktISBN-13: 9781801815291
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Marco Carvalho

Marco Carvalho is an experienced home automation hobbyist engineer, electrical engineer, and technician. Pursuing his passion for electronics and embedded systems, he created an embedded home automation task scheduler using X10 Home Automation devices in 2006. Nowadays, he uses wireless electronic devices and the Home Assistant software to build different smart home automation applications. As an MSc in Computer Science, Marco has worked with several well-known companies such as IBM, Jabil, Phillips, and Hexagon where he extended his support in development and manufacturing of electronic products. At the time of this publication, he is the Director of Engineering for Apex Microtechnology, where he is involved in the development of high power, high precision analog components.
Read more about Marco Carvalho