Notification when someone comes home or leaves

I am really hoping someone can help me with this as this seems to be pretty common. I am trying to setup a notification with presence. I have setup the presence through my asus router.

I have read several threads and still can’t seem to figure this out…can you guys please help me? Thanks in advance

- id: '1576450548715'
  alias: Presence Notification
  description: ''
  trigger:
  - entity_id: device_tracker.mo_huawei_phone
    platform: state
  - entity_id: device_tracker.tarin_huawei_phone
    platform: state
  condition: []
  action:
  - data:
     message: |
      {% if trigger.entity_id == "device_tracker.mo_huawei_phone" %}
       {% set person = "Mo" %}  
      {% elif trigger.entity_id == "device_tracker.tarin_huawei_phone" %}
       {% set person = "Tarin" %}                                     
      {% endif %} 
      {% if trigger.to_state.state == 'home' %}
       {{ person }} is home
      {% else %} 
       {{ person }} has left home
      {% endif %}
     title: 'Home info {{ states.sensor.time.state }}'
    service: notify.notify

- id: '1576450548715'
  alias: Presence Notification
  description: ''
  trigger:
    - entity_id: device_tracker.mo_huawei_phone
      platform: state
    - entity_id: device_tracker.tarin_huawei_phone
      platform: state
  action:
    data_template:
      message: "{{ 'Mo' if trigger.to_state.entity_id == 'device_tracker.mo_huawei_phone' else 'Tarin' }} is {{ trigger.to_state.state }}" 
    service: notify.notify
2 Likes

wow!! I tried to get to work for about 4 hours and couldn’t get far. Thank you very much!!!

I made a slight modification to the message part but thank you very much!!!

message: "{{ 'Mo' if trigger.to_state.entity_id == 'device_tracker.mo_huawei_phone' else 'Tarin' }} is {{ 'home' if trigger.to_state.state == 'home' else 'away' }}" 
1 Like

Can please someone help me with my automation?


- id: benachrichtigung_kommen_gehen
  alias: Benachrichtigung beim Kommen und Gehen
  description: ''
  trigger:
    platform: state
    entity_id:
      - device_tracker.person_1
      - device_tracker.person_2
      - device_tracker.person_3
  action:
    service: notify.notify
    data_template:
      title: "An- & Abwesenheit {{ states.sensor.time.state }}"
      message: >
          {% if trigger.entity_id == "device_tracker.person_1" %}
            {% set person = "xxxx" %}
          {% elif trigger.entity_id == "device_tracker.person_2" %}
            {% set person = "yyyy" %}
          {% elif trigger.entity_id == "device_tracker.person_3" %}
            {% set person = "zzzz" %}
          {% endif %}
          {% if trigger.to_state.state == 'home' %}
            Herzlich Willkommen Zuhause {{ person }}
          {% elif trigger.to_state.state != 'home' %}
            Auf Wiedersehen {{ person }}
          {% endif %}

I get the notification every time home assistant is refreshing the states.

How do I add a time stamp?

I know you’ve found a solution, but you might be able to simplify even further. Instead of doing the if checking to figure out what name to use, I look up the friendly name of the trigger.entity_id (which is a person.some_person, instead of a device_tracker.some_device) like this:

{{ state_attr(trigger.entity_id, 'friendly_name') }}

It gets the person’s full name, which might not be what you want, but you could probably chain to a filter to pop off and get just the first name.

3 Likes