The "automations" of Home Assistant: what they are and how they are used

5 minutes of reading

One of the most important achievements linked to the realization of prohis personal domotics lies in the possibility of defining it internally of automations. The proprio personale HUB, in fact, rappnot only does it "bridge", but also the automation center can supply conscience and will to profirst home.

Home Assistant it is equipped with a motor very versatile and functional to define these fundamental domotic management tools.

What is an automation

An automation, as the name easily suggests, is an automatic mechanism which "does things" on the basis of the occurrence of certain conditions.

"If you detect a person's presence in a room, turn on the lights in that room"

"If it hasn't rained during the day, irrigate the lawn at 18"

"If we are all out of the house, activate the alarm"

"When we are approaching home, if it's hot at home, turn on the air conditioner"

"At seven in the morning, if we are at home and if it is cold, turn on the bathroom heater"

and so on: all trivial, simple examples of automation.

The main features of an automation Home Assistant they are two: one trigger (ie a trigger) it's a'action (a'action to be performed). Furthermore, an automation can also include one condition (One condition) which has the power to interrupt the execution of the automation where it is not positively verified.

All automations Home Assistant use the event bus (the event bus) of theHUB, or the channel at which all state changes of the entity defined in theHUB are tracked. When for example a type entity "Light"Change state from"off", is "on”, This change is tracked on the event bus: if this state change has been mappact within the trigger of an automation, such automation will therefore be performed.

Nb It is a rather simple and intuitive mechanism, which however cannot be separated from understanding of what is an entity of Home Assistant. An automation, at Home Assistant, it is itself an entity (of type "Automation), which has a profirst state e propri attributes.

How it works

Let's start with an explanatory example.
imagine wanting to automatically turn on the bathroom heater at seven in the morning, but only when we are actually present at home:

(trigger)    alle sette di mattina
(condition)  se siamo in casa e se fa freddo
(action)     accendi il riscaldamento in bagno

La before row describes the trigger, or the priming of the automation. It is based on changing the status of a given entity, specified in the configuration: different modes can be used to describe the change of status from one specific to another, or from any one to a specific one, or from a specific one to any one. There is also the possibility of indicating the duration of a specific state (eg if the state of the entity indicated lasts for more than seconds, minutes, etc.).
When the status change (based on configuration) occurs, automation is triggered, that is performed. To trigger automation can be configured more trigger, but it will be enough that only one occurs so that the automation is triggered.
In the case of the example above the trigger is the achievement of the "7: 00" state of the entity that rappresents the clock.

La second describes the condition, or one or more conditions to be verified at the time of the trigger. It is not to be confused (as often happens) with trigger: while the latter serves to trigger automation based on a change of status of a given entity, the (or the) condition is verified after the trigger it occurred and triggered automation; if such (or such) condition it is true, then automation profollows in probefore execution, finally arriving at the action (or actions) to be performed.
In the case of the example above, the condition they are two: the first verifies an entity responsible for identifying the presence of tenants (usually a grouping of type entities)Device Tracker"); if the condition is true (tenants are at home), check the second one, or that "don't be cold"(Using the status or attribute of a type entity"Sensor”Due to a temperature sensor in the home automation environment).
Nb the conditions are always verified in sequence. Yes proyields toaction only when all of them are true in sequence.

La third finally describes theaction, or one or more actions to be carried out compared to trigger and the subsequent, positive verification of the conditions in the second point.
Again, like the condition, action they can be multiple and are executed in sequence. Every action plans to use component services to which the entity is headed to ensure that the latter changes state.
In the case of the example above, a type entity "Climate"That rappthe heating of the bathroom will be controlled using the service climate.turnon, which allows the ignition of the entity (ignition which will be based on the type of integration at the base of his presence on Home Assistant). If you also want to adjust the target temperature, you could use (as long as the entity expects it) the service climate.set_temperature as an action following the first.

State and attributes

Automation - as itself entity - has a profirst state and gods propri attributes.

The state is binary ("on"/"off") Which indicates whether it is operational or not. An automation in "off" will not be executed even when the trigger. This status when starting Home Assistant, can be adjusted via the configuration parameter "initial_state", Which can be set respectively"on"Or"off"

The attributes are three:

last_triggered(date / time) Indicates the date and time of the last execution of the automation. IS "null”If it has never been executed since the last restart of Home Assistant.
hidden(binary "true"/"false") Indicates whether the entity is viewable (using automatic grouping group.all_automations) at the user interface or not.
friendly_name(string) Indicates the friendly name entity.

The fact that an automation is itself an entity and possesses a state and attributes causes it to be used How trigger, as condition and how action inside other automations (which was not recommended in any case).

How to define an automation

The automations are usually contained within of the sidecar configuration of Home Assistant defined at the file automations.yaml present in the main folder of Home Assisant.

There are two ways to define / administer / modify an automation:

  • via user interface Home Assistant;
  • a mano.
User Interface

It is the method easier: allows, via web interface /app, to define an automation which, once saved, will be added to the file automations.yaml.

By clicking on "Configuration / Automation" at the frontend, in fact, appa web form will be created that allows us to configure the name of the automation, trigger, condition e action:

Home Assisant - New automation - name

Next, the oi trigger:

Home Assisant - New automation - trigger

then the or the condition:

Home Assisant - New automation - condition

finally, the or the action:

Home Assisant - New automation - action

At the end of the configuration, it will be sufficient to save and make the automation so operational.


For lovers of text editors, the alternative is to manually edit the file automations.yaml which, similarly to the other configuration files of Home Assistant, is expressed in yaml notation.

Below is an example of automation:

- alias: "Riscaldamento automatico bagno"
  initial_state: 'on'
    platform: time
    at: '7:00:00'
    - condition: template
      value_template: '{{ states.sensor.temperatura_bagno.state|int < 20 }}'
    - condition: state
      entity_id: group.famiglia
      state: 'home'
    - service: climate.turnon
      entity_id: climate.bagno

In this example, the called automation entity is defined automation.riscaldamento_automatico_bagno which is triggered every day at 7 in the morning, and which is performed only if the temperature is lower than 20 degrees (using the state of the entity as a check) sensor.temperatura_bagno) and if the family is at home (using the state of the entity as a check) group.famiglia which is assumed to be a grouping of "Device Tracker") And finally, as an action, lights up the type entity"Climate"Call climate.bagno.

An example very structured of automation related to climate systems is reported for example in this projet.


Automations, in home automation, they are bread and bread of those who benefit from these incredible modern technologies. The automations Home Assistantthen, they are perhaps among the most powerful available today: the limit is only the imagination and the degree of integration obtained through this miracle HUB personal: the more they are the integrated entities (regardless of the devices or the productors) plus it is possible to define increasingly punctual and ad hoc automations for the proneeds.

Home Assistant Official LogoATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Home Assistant, for any doubt, question, information on the specific merit of these components.


Stay up to date through ours Telegram channel!

The concept of "integration" in personal domotics