Understanding automations
All automationsAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more] are made up of a triggerA trigger is a set of values or conditions of a platform that are defined to cause an automation to run. [Learn more] and an actionActions are used in several places in Home Assistant. As part of a script or automation, actions define what is going to happen once a trigger is activated. In scripts, an action is called sequence. [Learn more]. Optionally combined with a conditionConditions are an optional part of an automation that will prevent an action from firing if they are not met. [Learn more]. Take for example the automation:
When Paulus arrives home and it is after sunset: Turn the lights on in the living room.
We can break up this automation into the following three parts:
(trigger) When Paulus arrives home
(condition) and it is after sunset:
(action) Turn the lights on in the living room
The first part is the trigger of the automation rule. Triggers describe eventsEvery time something happens in Home Assistant, an event is fired. There are different types of events, such as state change events, when an action was triggered, or the time changed. All entities produce state change events. Every time a state changes, a state change event is produced. Events can be used to trigger automations or scripts. For example, you can trigger an automation when a light is turned on, then a speaker turns on in that room. Events can also be used to trigger actions in the frontend. For example, you can trigger an action when a button is pressed. [Learn more] that should trigger the automation rule. In this case, it is a person arriving home, which can be observed in Home Assistant using devicesA device is a model representing a physical or logical unit that contains entities./sensorsSensors return information about a thing, for instance the level of water in a tank. [Learn more] by observing the state of Paulus changing from not_home
to home
.
The second part is the condition. Conditions are optional tests that can limit an automation rule to only work in your specific use cases. A condition will test against the current state of the system. This includes the current time, devices, people and other things like the sun. In this case, we only want to act when the sun has set.
The third part is the action, which will be performed when a rule is triggered and all conditions are met. For example, it can turn a light on, set the temperature on your thermostat or activate a scene.
The difference between a condition and a trigger can be confusing as they are very similar. Triggers look at the actions, while conditions look at the current state: turning a light on versus a light being on.
Exploring the internal state
Automation rules interact directly with the internal state of Home Assistant, so you’ll need to familiarize yourself with it. Home Assistant exposes its current state via the developer tools. These are available at the bottom of the sidebar in the frontend. Developer Tools > States will show all currently available states. An entity can be anything. A light, a switch, a person and even the sun. A state consists of the following parts:
Name | Description | Example |
---|---|---|
Entity ID | Unique identifier for the entity. | light.kitchen |
State | The current state of the device. | home |
Attributes | Extra data related to the device and/or current state. | brightness |
State changes can be used as the source of triggers and the current state can be used in conditions.
To explore the available actions open the Developer tools > Actions. Actions allow changing anything. For example, turn on a light, run a script, or enable a scene. Each action has a domain and a name. For example, the action light.turn_on
is capable of turning on any light in your system. Parameters can be passed to an action to indicate, for example, which device to activate or which color to use.
Creating automations
Now that you’ve got a sneak peek of what is possible, it’s time to get your feet wet and create your first automation.