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

4 minutes of reading
AIMS OF THE GUIDE
  • Get notifications before leaving and / or returning home (or other locations) of tenants through home automation Home Assistant
  • Difficulty level: bass
CONCEPTS FACED:
  • Software use and configuration
SOFTWARE COMPONENTS USED:
Prerequisites
PHYSICAL DEVICES USED:
GUIDE more indicated for:

All environments

Notes and disclaimer
  • qualsiasi eventuale modifica agli impianti domestici dev'essere progettata ed realizzata SOLO da personale qualificato;
  • any changes implemented in probefore is a propersonal responsibility as well as a profirst risk and danger (the contents of the present page are purely educational);
  • any changes implemented in proprior to a device it voids the guarantee, quality approvals and certifications.
Driving review: 1.1

Abstract

In addition to enabling users to execute di automatism in the face of abandonment / return of tenants at home (intended as a "family" group), abbinameof the component "Device Tracker"With the component"E-mail Notifications"Of Home Assistant it is particularly convenient for receiving notifications to the front of the exit and / or return of individual tenants.

The field of applished here it's very wide: monitoring of subjects such as children and the elderly, third parties (eg operator / cleaning ice), simple awareness of the presence and absence of family elements and other scenarios. Obviously there is an aspect related to privacy and ethics that every person administrator of the profirst personal home automation will have to face on a case by case basis, informing (but not suggesting solutions) the various subjects involved in this implementation / functionality.

assumptions

As sappIAMO the integration of the presence of the various tenants authorized at Home Assistant occurs through the use of the component "Device Tracker”Declined through land various platforms connected to it (although by now it is universally used alone app official "Home Assistant Companion"). Typically every tenant has the prosmartphone and, when presence / absence is detected at home, Home Assistant he is aware of it. This presence can be detected by implementing one or more of the aforementioned platforms; this is not the subject of this guide, which takes the presence in configuration of the following two type entities "Device Tracker"

  • device_tracker.marco
  • device_tracker.daniela

which rappresent, appanointed, the state of presence of two hypothetical tenants, Marco and Daniela.

Also in terms of "notifications", on Home Assistant there is to indulge. Type entity "E-mail Notifications"In fact, they allow you to send notifications in many different ways based on to the platforms connected to the component used; for this guide we will assume the success integration with Telegram, well-known private messaging system (but it is only an arbitrary choice, absolutely exemplary).
We will assume therefore the presence of the following entities:

  • notify.marco
  • notify.daniela

as well as the presence of a group entity, notify.famiglia, which simultaneously sends any notifications to both notification entities mentioned above.

Obviously the techniques described in this guide regardless of what the chosen technologies are to equip oneself with proprie "Device Tracker"And" Notifications ".

Change of status

What triggers automation that we're going to write will - trivially - the change of state of one or more of the type entities "Device Tracker". The possible states are:

  • home
  • away (sometimes not home)

who need no explanation. In trigger, then,
With regard to the notifies, we will include in the block action such a personalization that, based on the change of state, provides a message rather than another.

Here is the configuration:

automation:
- alias: "Notifica ingressi e uscite"
  trigger:
    platform: state
    entity_id: device_tracker.marco, device_tracker.daniela
  condition:
    condition: template
    value_template: '{{ trigger.to_state.state != trigger.from_state.state }}'
  action:
    service: notify.famiglia
    data_template:
      title: "Domotica"
      message: >
        {% if trigger.to_state.state == 'home' %}
        Rilevato ingresso in casa da parte di {{ trigger.from_state.attributes.friendly_name }}
        {% elif (trigger.to_state.state == 'away' or trigger.to_state.state == 'not_home') and trigger.from_state.state == 'home' %}
        Rilevata uscita da parte di {{ trigger.from_state.attributes.friendly_name }}
        {% endif %}

The explanation is quite simple.

The block trigger uses the change of status of the entities "Device Tracker" any both the change of state, as a trigger. There conditioninstead, it verifies that the change of state is between two different states (and not the repetition of an already consolidated state); the block actionfinally, it evaluates what the change of status is using the function trigger.to_state.state: in case it has become "home", it sends a certain notification message, otherwise it sends another one.

Both messages are enriched with the associated name in the "Friendly" field name”Of the entity (function trigger.from_state.attributes.friendly_name).

Other locations

GPS PinIf the platforms used for the creation of "Device Tracker"Have GPS support is possible (eg Home Assistant Companion, app official of Home Assistant), through the implementation in configuration of the "areas“, To define geographical points of interest. When a "Device Tracker"(With GPS position) located in that area, its state takes its name.

Let's assume we define a zone called "Work" in configuration that rappliving in our place of work: when we find ourselves at home, ours Device Tracker (with GPS position) will have "home" status; going out, he will take "away", but when we get to work he will take "wor".

It goes without saying that the implementation of the aforementioned automation can thus be varied:

automation:
- alias: "Notifica ingressi e uscite"
  trigger:
    platform: state
    entity_id: device_tracker.marco, device_tracker.daniela
  condition:
    condition: template
    value_template: '{{ trigger.to_state.state != trigger.from_state.state }}'
  action:
    service: notify.famiglia
    data_template:
      title: "Domotica"
      message: >
        {% if trigger.to_state.state == 'home' %}
        Rilevato ingresso in casa da parte di {{ trigger.from_state.attributes.friendly_name }}
        {% elif (trigger.to_state.state == 'away' or trigger.to_state.state == 'not_home') and trigger.from_state.state == 'home' %}
        Rilevata uscita da parte di {{ trigger.from_state.attributes.friendly_name }}
        {% else %}
        {{ trigger.from_state.attributes.friendly_name }} ha raggiunto la località {{ trigger.to_state.state }}
        {% endif %}

adding the block else let us ensure that any state of "Device Tracker" different from "home" and "away"(Therefore attributable to the"areas"Defined in configuration" is notified as "reaching that zone". The upper block (thanks to the presence of "and trigger.from_state.state == 'home'") Avoids false communications when returning home when you simply leave a location other than home (eg from"work" to "away")

This type of implementation can be used for example to ascertain - without worries - that children reach school, that an elder has reached a specific location, that la profirst companion has reached the workplace and so on. Always, of course, with respect for the people involved.



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.

inDomus telegram channel