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

Creating Automations Using Home Assistant

Now that we have our minimal home automation system created and configured, we will explore one of the main features of Home Assistant, which are automations. We will learn what automations and their components are. We will also create automations based on the system implemented until now. We will cover the following main topics in the chapter:

  • Learning what automations are
  • Components of an automation in the context of Home Assistant
  • Creating your own automations
  • Testing and debugging your automation
  • Expanding the Home Assistant automation capabilities – using and creating pre-formatted automations (blueprints)
  • More examples of automations

By the end of this chapter, you will understand the power of Home Assistant in integrating automation into the devices in your home. You will be inspired by the examples and ideas to create your own automations to make your home automated and smart.

Technical requirements

This chapter will not deal with any hardware or other electronic device installation or physical configuration. Only software skills will be used. If you are familiar with programming development and the use of programming debug tools and methods, you will be able to follow this chapter easily. Some informative videos will be provided on how to create some of the automations, scripts, and scenes. All the .yaml files used in this chapter are available at https://github.com/PacktPublishing/Building-Smart-Home-Automation-Solutions-with-Home-Assistant/tree/main/Chapter%2005. Check out the following video to view the Code in Action: https://bit.ly/3KCPR9O

Learning what automations are

Generally speaking, an automation could be defined as a process that uses some kind of logic or intelligence to produce an action or output automatically depending on an input or event. In the context of the home, automation refers to using the information provided by input devices such as sensors and processing this information by verifying whether the data input meets some decision criteria. If this is the case, the Home Automation Server (or in our system, the Raspberry Pi with Home Assistant installed) sends a command or a data output to the actuators or other devices. Usually, the automation runs in an infinite loop, reading and analyzing the information and making the proper decision. When an automation is configured to operate without feedback or monitoring from the output actuators, it is referred to as having an open-loop configuration. Figure 5.1 shows a flowchart representation of a typical open-loop home automation.

Figure 5.1 – Open-loop automation flowchart
...

Components of an automation in the context of Home Assistant

It is important to understand what are the names assigned by Home Assistant to some components of an automation, which will be helpful when you create your own automation. Before detailing what the components are, let’s first understand what an entity is in Home Assistant.

Understanding entities

Before we can discuss the components of an automation, we will need to know what an entity is. An entity is what Home Assistant calls a data structure that can be associated with a device. An entity basically has three main parts:

  • ID: The identifier for the entity
  • State: The current state of the entity
  • Attributes: Extra information related to the entity or state

A device can have one or more entities, and each one, with its parts, can be included in an automation. As an example, the off-the-shelf plug device, desk_outlet, that we configured in Chapter 4 has the entity structure shown in Table 5...

Creating your own automations

We will create two automations in this section using the Home Assistant automation editor. The first automation will use the two entities we created in Chapter 3 and Chapter 4 and the second automation will be using the off-the-shelf actuator we installed using an application integration in Chapter 4.

The Home Assistant automation editor can be accessed by clicking on Settings | Automations & Scenes. The automations can be created using the Automations tab. In the next subsections, we will detail how to create the two automations.

Automation 1 – convenient light for your garage

The first automation we will create was the first I created in my home. I created it because my street at night is very dark; there is no public light. I wanted my garage lights to turn on when I arrive home at night on the weekend with my family. This would help me to unload everybody from the car safely.

The automation is very basic and can be explained...

Testing and debugging your automation

In the process of creating an automation, many times you will create it and want to test it right away to verify it is working. In other situations, even if you can test the automation immediately, for some reason it won’t work and you will want to know what to fix. Home Assistant provides Developer Tools, which can help you to test and debug your automations. We will explore Developer Tools in the next subsections.

Setting and checking the state of entities

While I’m writing this subsection in my office, I want to test automation 1. One way to do that is to go to my garage, trigger the motion sensor, and see whether the garage lights turn on. Another option is to set the state of the motion sensor entity and check the state of the garage light entity. We can do this by using the STATES tab using the Developer Tools in Home Assistant.

Let’s test our automation 1 by setting and checking the state of the entities. We...

Expanding the Home Assistant automation capabilities

Home Assistant offers more resources to automate your home. If you don’t have many ideas about what to do to automate your home, you can use a pre-formatted automation or import one. You can also create a pre-formatted automation and share it to be used in your home or by the development community. You can use scripts that will help you to execute coordinated actions, increasing the power of your automation. Your automation can be structured by creating scenes that can manage specific areas of your home. We will discuss these options in the next subsections.

Using and creating pre-formatted automations (blueprints)

In the previous sections, we learned how to create our own automations from scratch using the Home Assistant automation editor. You can also use the pre-formatted automations available in Home Assistant or import them. These pre-formatted automations are known as blueprints. If you think your automation can...

More examples of automations

Here are some examples of automations I use in my home:

  • When a door is opened, announce it through a smart speaker.
  • Turn on the lights at the front of the house at sunset and turn them off four hours later.
  • Turn on the lights in the laundry room when the garage door is opened. Keep them turned on for two minutes and then turn them off.

The following are examples I intend to include in my home soon:

  • After midnight, if a movement is detected in the corridor, turn on the corridor lights for two minutes and then turn them off.
  • If there is no one at home, put the AC in eco mode and make sure the lights and some plugs are turned off.
  • When returning home, set the lights at the same status as they were before leaving.

Now that you know what automations are, have an idea of how to create them, and have seen some examples, my suggestion is that you think about what will best suit you and what your needs are. Think about...

Summary

In this chapter, we learned in detail what automations are both in general and in the context of Home Assistant. We also learned about the components associated with an automation and other features used by Home Assistant, such as entities and services.

During the course of this chapter, several practical examples were provided to create automations. Various tools were explained and used to debug and verify their functionality. We were able to expand the capabilities of an automation by learning how to create and use blueprints and doing the same with the scripts and scenes. Finally, some examples of automations used in my home were provided, as well as some others I am planning to create in the near future. Hopefully, they will inspire you to create your own automations and think of ways to smart control your home.

In the next chapter, we will add more devices to our home and include them in the dashboard so you can have visibility and direct control of them using the...

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