Exit and return home: home automation via automation Home Assistant

6 minutes of reading

Without issues, one of the things more pussies was originally the personal home automation is the see the probefore making home, as if by magic, automatic actions when leaving and when returning.

We leave home (tutti), e acqua e gas si chiudono da soli, l’allarme si attiva, tutte e luci si spengono, le spine non essenziali si disattivano, eventuali notifiche di rilevamento (allagamento, fumo ecc.) entrano in modalità di armo, le tapparelle are lowered. Even just one of the family back home, and the utilities are reactivated, at the opening of the entrance door ours smart speaker greets us by giving us the reading of the telemetric data of the house (average temperature, duration of the absence, any minor events detected). The limit is fantasy, never like this.

Home Assistant it is of great help to us in implementing these automatic scenarios thanks to probases its configuration flexibility automations.

Abstract

Understanding the logic of an exit and / or entry automation is very easy: just have it clear in your head the concept of change of state of an entity Home Assistant.

As sappLet us, every entity (of any type) owns un profirst state that qualifies, appanointed, the instant condition. A classic example is that of switches: usually an entity of this type has a status "on"Or"off". When the status changes, this change is recorded by the "state bus" of theHUB and, if configured within a trigger of one or more automations, provvede to innescala / e.

[Nb If you don't know what we're talking about, first it's the case you read and understand this card.]

It goes without saying that it is possible to easily define two automations that, when the state changes "in house” a “outside the home"(And vice versa) of tenants"do things"Automatically for us.

The entities to monitor to implement these automations they are typically those of type "Device Tracker“, Which rappresent - in the profirst state - the presence of each tenant.

Device Tracker

The first step, therefore, is to acquire so many type entities "Device Tracker” how many tenants of the domotic environment. In essence, each of the tenants will use the proyour smartphone to communicate to the home automation system proposition.

N.b. La domotica personal based on Home Assistant non viola la privacy dei suoi utenti: all information relating to the states (including that of the component “Device Tracker") Are collected LOCALLY and are not transmitted a nessuna realtà esterna. For the more skeptical: Home Assistant it's a projet Open Source, which means that the source code is open, hence its behavior - comprovato - is verificabile by anyone. Obviously any external services used to collect the position are responsible for managing that specific information.

To define entities "Device Tracker”Linked to prothe smartphone techniques they are the most disparate: the implementation of one or more daughter platforms of this component makes it possible to reach the goal; although the component-related integration platformsDevice Tracker”Are many, even simply by installing on the profirst smartphone theapp native "Home Assistant Companion"The users indirectly equip themselves with a profirst GPS tracker. This is the path we usually take and we recommend it.

Group

Obtained the "Device Tracker"What we need we need to create a type entity"Group" which rappthe family unit is present.
Let's assume that the family is rappgiven by the following three entities "Device Tracker"

  • device_tracker.marco
  • device_tracker.daniela
  • device.tracker.giorgia

Creating a "family" group is easy, just add in configuration:

group:
  famiglia:
    entities:
      - device_tracker.marco
      - device.tracker.daniela
      - device.tracker.giorgia

which will generate the entity "group.famiglia"

The groups of "Device Tracker"They have only two possible states"home" and "not_home". The state becomes "home"When even one of the device tracker is at home, as it becomesnot_home"When everyone is away from home.

Yes, but where is "home"?

Location

It is important to define in configuration the absolute position of the prohome. If we use presence detection platforms which use GPS (others use other methods, such as the NMAP) as pivotal information, it is obvious that this information should be compared with an absolute geographical position.

To indicate the "home" position, simply go to "Settings">"General”Of the menu Home Assistant and place the cursor on the correct point of the mappand finally click on "salvo"

automations

Bene: we have our "Device Tracker", We have grouped them together, we have indicated the position of" Home ". We are pronti to define the two automations that will manage the abandonment or the return home.

OUTPUT
automation:
- alias: "USCITA"
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: group.famiglia
    from: 'home'
  condition: []
  action: []
IN ENTRY
- alias: "RIENTRO"
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: group.famiglia
    to: 'home'
  condition: []
  action: []

Nb As you can see, the first automation triggers with the change of passage “from state home a any other state"While the second"when the state becomes home". It would be more intuitive to configure the first "da home a not_home"And the second"da not_home a home", But the configuration promail is more effective for curbing potential proproblems of "spurious" states that can sometimes happen. Proto believe.

Now, all you need to do is indicate in the blocks "action"What to do in the two cases.

Action

Obviously it all depends on what you have available and what you want to do. In the block action, as in all automations, the execution is performed in sequence, therefore it will be necessary list of services and entities to be evoked upon execution.

LUCI

Let's say we want to turn off all the lights. The block action to add to automation "automation.uscita"Above defined is simple:

  action:
    - service: light.turn_off
      entity_id: group.all_light

We do not indicate one by one all the lights: we exploit the preferred group "group.all_lights"Associated with the service"light.turn_off"

Let's say instead that you want to turn on a specific return: The block action to add to automation "automation.rientro"Above defined is simple:

  action:
    - service: light.turn_on
      entity_id: light.ingresso

and so on.

SUMMON A SCENE

A good practice is that of using predefined scenes, so as to divide the code in a cleaner way.
Let's imagine defining two scenes, one for the exit and one for the return:

scene:
- name: Uscita
  entities:
    alarm_control_panel.allarme:
      state: armed_away
      code: 1234
    group.all_lights: off
    switch.acqua: on
    switch.gas: on
    switch.utenze: off
    media_player.tv: off
    script.vacuum_on: on
    script.uscita_sequence: on
- name: Rientro
  entities:
    alarm_control_panel.allarme:
      state: disarmed
      code: 1234
    switch.acqua: on
    switch.gas: on
    switch.utenze: on
    script.vacuum_to_dock: on
    script.rientro_sequence: on

These two scenes ("scene.uscita" and "scene.ritorno") Set a whole series of states:

  • (the first) turns off all the lights;
  • set the alarm domotizzato su Home Assistant (entity "alarm_control_panel.allame");
  • set water and gas (entity "switch.acqua" and "switch.gas");
  • set utilities ("switch.utenze")
  • turn off the TV at the exit (if it remained on .. entity "media_player.tv");
  • start the robot vacuum cleaner at the exit and stop it on the way back, if it hasn't finished turning yet (summoning one script);
  • start two different ones script for any conditional sequences (various things, maybe not manageable simply by setting a status via scene).

The respective automations therefore become:

OUTPUT
automation:
- alias: "USCITA"
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: group.famiglia
    from: 'home'
  condition: []
  action:
    - service: scene.turn_on
      entity_id: scene.uscita
IN ENTRY
- alias: "RIENTRO"
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: group.famiglia
    to: 'home'
  condition: []
  action:
    - service: scene.turn_on
      entity_id: scene.rientro

Notifications

Let's say we have "E-mail Notifications”And want to be notified when one or both automations are activated. It will be enough to add in action the typical block used in other automations, for example:

    - service: notify.mio_telefono
      data:
        data:
          push:
            badge: 1
        title: Domotica
        message: "Allarme DISARMATO. Bentornato a casa."

Smart Speaker

Let's assume we have:

We want (but it is just an example to make people understand the ample possibilities in these scenarios) that, upon returning home, Home Assistant wait for the entrance door to open to do proannounce both a greeting message (random, between three presets) and a statistical one (temperature and air quality) to the smart speaker Alexa.

The sequence to be inserted in the block action it could be:

      - wait_template: "{{ is_state('binary_sensor.contatto_ingresso', 'on') }}"
        timeout: '00:30:00'
        continue_on_timeout: 'false'
      - delay:
          seconds: 5
      - service: notify.alexa_media
        data:
          target:
            - media_player.alexa
          data:
            type: announce
            method: speak
          message: >
             {{ [
             "Bentornato a casa!",
             "Guarda chi si vede!",
             "Casa dolce casa."] | random }} La temperatura media è di {{ ((states("sensor.temperatura_sala")|float + states("sensor.temperatura_camera")|float )/2)|float|round(1)}} gradi, la qualità dell'aria è {{ states.sensor.air_quality.state }}.

First, the sequence waits for thirty minutes opening the entrance door (time to park, climb etc.); once the door is open, watch a few seconds (five) and then do proannounce the message to Alexa.

Exit and return home (or other places): notifications from home automation Home Assistant


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.


Please comment below