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 1 – Creating Your Own Sensor

This chapter will perhaps be one of the most interesting in this book as it contains lots of hands-on exercises. In this chapter, you will learn how to create a combined sensor with two different element inputs: a temperature sensor and a motion sensor. I will refer to it as a double measurement sensor. First, I will explain each electronic part that can be integrated with the sensor and teach you how to interconnect the parts using an electronic circuit. I will also show you how to deploy the MQTT software client that’s been customized for the sensor and show you how the MQTT software client works so that you can use not only this sensor but also other devices that you can customize and integrate in the future. Following this, I will provide detailed coverage of how to set up the MQTT software client so that it works with Home Assistant. Finally, you will learn how to enclose and install the sensor in your home.

We will...

Technical requirements

You will understand the content of this chapter better if you are familiar with electronic components and circuits. To integrate and assemble the sensor parts, you will need to be able to follow an electronic diagram and know how to solder electronic components. You will also need to know how to deploy software to electronic devices. If you have already deployed software on Arduino, then this process will be similar. The Tasmota software configuration file, which I deployed in the sensor used in this chapter, can be found at https://github.com/PacktPublishing/Building-Smart-Home-Automation-Solutions-with-Home-Assistant/tree/
main/Chapter%2003. Check out the following video to view the Code in Action: https://bit.ly/47CkINl

Knowing the parts and tools to build your sensor

In this section, we will look at each part you can use to build your double measurement sensor. You will understand the purpose of each so that you can integrate them using a provided electronic circuit, something that we’ll do later in this chapter. We will frequently reference the Sensors section in Chapter 1 and the block diagram shown in Figure 1.9 of that chapter.

Each description isn’t meant to provide deep details about how each part works but just the information required so that you can build a sensor or make some important adjustments or configurations so that the final circuit can work according to its intended use.

To build the double measurement sensor, you will need the following electronic parts and components:

  • HC-SR501 motion sensor
  • BMP280 environmental sensor module
  • ESP8266 Wi-Fi module
  • USB cable (USB Type A to USB Type B micro)
  • USB adapter (IN: AC 100 ~ 240V/OUT: 5V @ 1A)
  • ...

Connecting the electronic parts and cables

The following is a diagram of the double measurement sensor circuit:

Figure 3.5 – Double measurement sensor circuit diagram

Figure 3.5 – Double measurement sensor circuit diagram

The complete bill of materials (BOM) for the sensor is listed in Table 3.1:

Understanding Tasmota and how to install it in our sensor

In this section, we will learn what Tasmota is and how to install it in our sensor.

What is Tasmota?

As this book’s main intention is to build a home automation system using Home Assistant, we will not spend time developing a piece of software to handle the sensor’s data. The key secret to easily building your system is to know how to integrate and configure the different parts of it, including the sensor. I learned this lesson after spending a long time learning how to program the ESP8266 Wi-Fi module. After learning how to make basic software programs using tutorials on the internet, I discovered Tasmota (https://tasmota.github.io/). I found Tasmota to be a very useful software tool with plenty of resources for integrating different kinds of sensors and actuators. It can not just be used with Home Assistant but also with other IoT types of ecosystems. I hope you can also enjoy this software.

Tasmota...

Integrating the sensor data into Home Assistant

The last part of the process of creating our sensor is to integrate it into Home Assistant. We will have to return to our installation of Home Assistant, which we did in Chapter 2, to do so. Our double measurement sensor will be configured in two steps. In the first step, we will configure the temperature part of the sensor; in the second step, we will configure the motion part of the sensor.

Integrating the temperature sensor

If you have been following this book since Chapter 2, you will have Home Assistant 9.3 or above installed in your home automation server. As mentioned previously, in the case of this book, we are using version 9.3 and above so Home Assistant will automatically discover the temperature sensor and help you configure it.

You will need to execute the following steps to be able to get the data from your temperature sensor:

  1. In Home Assistant, click Settings | Devices & Services.
  2. In the Integrations...

Enclosing, calibrating, and installing the sensor

In this section, we will enclose our sensor in a box and calibrate the motion sensor. Once we’ve done this, we will physically install and test our sensor.

Enclosing our sensor

You can enclose your sensor in different ways. All the circuits, including the three boards and harness, can easily fit in an 80 x 80 x 50 mm box. You can purchase or use a pre-fabricated box that has similar dimensions. You can use any material for the box except for metal because it will block or degrade the Wi-Fi signal.

If you have a 3D printer at home or are familiar with rapid prototyping, you can have a more customized enclosure for your sensor. You can make a mechanical design or use some free 3D models available on the internet. On websites such as https://www.yeggi.com/ and https://www.thingiverse.com/, you can search for and find different 3D models for PIR motion sensor cases. These 3D models are available in STL file format, but once...

Summary

In this chapter, we added another component to our home automation system: a sensor. We added this component by building it from scratch using electronic parts available on the market. Each part of the sensor was introduced and information about how to interconnect the parts was provided.

We learned about a popular piece of software called Tasmota, which can be used to manage IoT devices, and looked at how to install and configure it in our sensor. After installing and configuring this software, we switched to Home Assistant and integrated the sensor.

We finished this chapter by providing more details on how to enclose the sensor in a box, calibrate the motion sensor module, and then install it.

In the next chapter, we will look at another type of device called an actuator. By doing this, we will have finished looking at the basic components that can be used for a home automation system. This, in turn, will allow us to cover advanced topics so that we can create automations...

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 €14.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

ID

Quantity

Description

1

1

ESP8266 Wi-Fi module

2

1

HC-SR501 motion sensor

3

1

BMP280 environmental sensor module

4

1

USB cable

5

1

USB power adapter

6

1

Arduino...