Howto: Notify me when users arrive or depart my Home zone

Hi, All:

I have what is I’m sure a very simple and stupid question, but I am just simple and stupid enough to go ahead and ask it anyway.

I have an automation that fires a notification to my phone saying “someone is arriving” any time a tracked person enters the zone.

What I would like is to have the notification say “personsname is arriving” instead.

alias: arrival departure notification
description: ''
trigger:
  - platform: zone
    entity_id: person.ann
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.tom
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.jim
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.bob
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.tina
    zone: zone.home
    event: enter
condition: []
action:
  - service: notify.mobile_app_pixel_5
    data:
      message: is arriving
mode: single

Is it just a simple matter of knowing what {{ variable.name }} to put in the message tag in there somewhere or am I missing something super obvious? Nothing I have put in as a variable works, they just all return “is arriving” not “personsname is arriving”

Thanks to anyone who reads and comments! -Jim

1 Like

In the message-

action:
  - service: notify.mobile_app_pixel_5
    data:
      message: >-
        {{ trigger.entity_id.split(".")[1] }} is arriving

Edit: wrong suggestion.

That second one won’t work. This will for the friendly name.

action:
  - service: notify.mobile_app_pixel_5
    data:
      message: >-
        {{ state_attr(trigger.entity_id, 'friendly_name') }} is arriving

or (what ardi was originally aiming for)

action:
  - service: notify.mobile_app_pixel_5
    data:
      message: >-
        {{ trigger.to_state.attributes.friendly_name }} is arriving

Here’s a third template that will work

action:
  - service: notify.mobile_app_pixel_5
    data:
      message: "{{ trigger.to_state.name }} is arriving"

Also, @jwhowa you can simplify your automation:

alias: arrival departure notification
description: ''
trigger:
  - platform: zone
    entity_id: 
    - person.ann
    - person.tom
    - person.jim
    - person.bob
    - person.tina
    zone: zone.home
    event: enter
condition: []
action:
  - service: notify.mobile_app_pixel_5
    data:
      message: "{{ trigger.to_state.name }} is arriving"
2 Likes

Thank you so very much for this! I jumped in to HA a seasoned network enginner with very good networking and firewall skills, but not ANY YAML skills lol. Struggling with syntax and what is and isn’t a variable is proving challenging.

I find that each script I view or write, I am learning new things, and I am very appreciative to this community for sharing!

how do you sense that someone is arriving or leaving?

That’s what zone triggers do. They track persons/device_trackers that enter/leave zones.

I understand what zone triggers do…but there are many ways to trigger a zone change. I have tried various ones with little reliable success…so I was interested in what you are using to trigger the zone change. Facial recognition, phone connectivity to the local router, a phone application or something else. How do you know that person A has just entered or left a zone?

I don’t think you do. A person/device_tracker entity has a gps location attached to it. Same with a zone. The zones themselves have a radius. When the device_tracker enters the radial zone, that’s what triggers the enter trigger.

EDIT: I’ll try to find the thread that discusses ways to bolster home detection.

EDIT2: I can’t find it. If I recall correctly, most people used a bluetooth device to sense phones or a beacon combined with router connection & gps device trackers.

In my case, I track their phone using Nabu Casa. Anyone with HA installed on their phone, if they have allowed location awareness, reports their GPS coordinates to HA automagically, so HA knows when they enter/heave zone.home.

Let’s try one more time. What are you using as a tracker? are you running an app on their phone? Are they carrying something on their keychain? I know zones, I know how to set them and change radii…the question is how do you sense when someone enters or leaves a zone…within a minute. All of my users don’t always carry their phone and don’t want to run a special app. What are you using as your device (person) tracker?

He answered your question. He’s running the app, which in turn creates a device_tracker.

Then you have 2 options: BLE keyfob of some sort or facial recognition. And facial recognition typically crosses the privacy line (and is illegal in some areas).

I have successfully tested with NFC tags, but the hardware I used was not ready for prime time, and I would not recommend anyone try it with anything on the market in 2021… Integration was difficult and buggy. :slight_smile:

I am fortunate, because in my case, as @petro says, users are carrying their phones. At least in my area, everyone has their phone on them at all times. Even the kids and teens. They NEVER are far from that phone which is why the Nabu Casa tracker automatically created works perfectly in my case.

Dear Petro,
i use your first template, but when i test the automation, i get in the trace:

" Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'entity_id' " 

Here my full automations-code:

- id: '1642674707400'
  alias: Erreichen der Home-Zone (extended)
  description: ''
  trigger:
  - platform: zone
    entity_id:
    - person.anja
    - person.gerd
    - person.marvin
    - person.pascal
    zone: zone.home_extended
    event: enter
  condition: []
  action:
  - service: notify.mobile_app_iphone_von_gerd
    data:
      message: >-
        {{ state_attr(trigger.entity_id, 'friendly_name') }} erreicht die Home-Zone (extended)
      title: Home-Zone (extended) - Erreichen
  - service: notify.mobile_app_iphone_von_marvin
    data:
      message: >-
        {{ state_attr(trigger.entity_id, 'friendly_name') }} erreicht die Home-Zone (extended)
      title: Home-Zone (extended) - Erreichen
  mode: single

I have also tested it with the other two templates.

Can you help me please
Thanks!
Gerd

It should work. Check out the trace.

Dear Petro,

thank you for your replay!

This is, what the trace show:

Register “Step Details”

Executed: 20. Januar 2022, 13:53:10
Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘entity_id’

Register “Step Config”

service: notify.mobile_app_iphone_von_gerd
data:
message: >-
{{ state_attr(trigger.entity_id, “friendly_name”) }} erreicht die Home-Zone
(extended)
title: Home-Zone (extended) - Erreichen

Register “Changed Variables”

context:
id: 211db0ea4021d67e7b4cba141e97cf43
parent_id: 167a8a1bcda07b767c5fe7e3fe153d91
user_id: null

Register “Related logbook entries”

No Logbook entries found for this step.

Register “Trace timeline”

Triggered manually at 20. Januar 2022, 13:53:10
Call service notify.mobile_app_iphone_von_gerd
Stopped because an error was encountered at 20. Januar 2022, 13:53:10 (runtime: 0.03 seconds)
Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘entity_id’
Not all shown logbook entries might be related to this automation.

Register “Related logbook enries”

Erreichen der Home-Zone (extended) has been triggered
13:53:10 - Vor 5 Minuten
Not all shown logbook entries might be related to this automation.

Register “Automation config”

id: '1642674707400'
alias: Erreichen der Home-Zone (extended)
description: ''
trigger:
  - platform: zone
    entity_id:
      - person.anja
      - person.gerd
      - person.marvin
      - person.pascal
    zone: zone.home_extended
    event: enter
condition: []
action:
  - service: notify.mobile_app_iphone_von_gerd
    data:
      message: >-
        {{ state_attr(trigger.entity_id, "friendly_name") }} erreicht die
        Home-Zone (extended)
      title: Home-Zone (extended) - Erreichen
  - service: notify.mobile_app_iphone_von_marvin
    data:
      message: >-
        {{ state_attr(trigger.entity_id, "friendly_name") }} erreicht die
        Home-Zone (extended)
      title: Home-Zone (extended) - Erreichen
mode: single

If i only use a “stupid” message aka “Somebody enter the home-zone (extended)” the automation work correct.

Can you help me again, please.

Thx
Gerd

Look at the trigger information in the step variables on the trace, verify that the trigger object has the data that’s expected to be passed.

It work’s!

The problem is, you cann’t test this manual because the trigger-Object are not set.
I test it “real” and go out/in my zone and the notify work perfect.

Thank you very much for your support!

Best regards
Gerd