Notify Entering and/or Leaving Zone

Would you mind posting your automation config? I am having the same issue with the home zone. thank you!

I found the official leaving zone blueprint doesn’t work for me. I tracked it down (thanks to the automation tracing) to the fact the state and name do not match case… trigger.from_state.state == home and states[zone.home].name == Home.

So, when the check of the state vs the zone name happen, it never matches as coming from THAT zone. It might only happen with certain device trackers (I’m using nmap for this example) or the default Home zone has some quirks.

2 Likes

The official leaving zone does work for me, but not this one for entering. Can anyone help me?

Edit: I can trigger the automation manually and that results in notifications. So the problem is that the autmation does not get triggered

Hi, it’s December 2022 as I type this. This is an old thread, but still has some value.

What I want:

A notification to my android Home Assistant app that a person arrived at a zone

How I did it:

  • add person in Home Assistant under Settings > People
  • install Android Home Assistant app in those people’s phones, enable notifications, vibrate, pop on screen, etc, enable location (of course)
  • create your target zone(s) in Settings > Area & Zones
  • open File Editor
  • navigate to /config/blueprints/automation/homeassistant
  • open notify_leaving_zone.yaml
  • copy all code from notify_leaving_zone.yaml
  • create a new file, name it notify_entering_zone.yaml
  • paste all code from notify_leaving_zone.yaml into the newly created notify_entering_zone.yaml
  • reverse the logic in line 37, from this

value_template: "{{ trigger.from_state.state == zone_state and trigger.to_state.state != zone_state }}"

to this

value_template: "{{ trigger.from_state.state != zone_state and trigger.to_state.state == zone_state }}"

  • and change the action text:
action:
  - alias: "Notify that a person has left the zone"
    domain: mobile_app
    type: notify
    device_id: !input notify_device
    message: "{{ person_name }} has left {{ zone_state }}"

to this

action:
  - alias: "Notify that a person has entered the zone"
    domain: mobile_app
    type: notify
    device_id: !input notify_device
    message: "{{ person_name }} has arrived at {{ zone_state }}"
  • Save changes
  • Navigate back to Settings > Automations & Scenes > Bluebrints
  • You should see your newly created Zone Entry Notification blueprint
  • Select “create notification” to create a new automation

Just tested (by pressing Run in the automation), it’s working. Crossing fingers that it works when the person actually enters

4 Likes

The quirk is that for all zones EXCEPT zone.home the device will report back the zone name (ie friendly name), while in zone.home the device will report back “home” rather than the friendly name, this poses some challenge to the blueprint as it needs to test for the special case zone.home being supplied as input.

I am (trying to) use this automation too and have the same problems as the posters above. I can run the automation manually and receive notifications. But when devices enter zones (even if they are not the home zone), nothing happens. When checking the logs of the autmation, I did see a trigger where

    trigger.from_state.state: not_home
    trigger.to_state.state: Remote Office

In the graphical Trace Timeline I see that the automation did reach the “send notification” step, but the notification never actually got sent.

Please help us debug this issue, so others also get this working.

I replaced the blueprint with a normal automation from scratch:

alias: Me at the Office
description: ""
trigger:
  - platform: zone
    entity_id: person.rolf
    zone: zone.office
    event: enter
condition: []
action:
  - device_id: f6f1e7XXXXXXXXXX32bf2
    domain: mobile_app
    type: notify
    message: Rolf at Work
mode: single

Of course this is easiest with the graphical editor (or paste this script in yaml and then switch back to the UI to get a headstart on what to fill in where.

I’ll post an update here if things start working.

The normal automation seems to work more reliable than the blueprint for some reason. I also note that homeassistant, the browser and the app require some restarts/logins for some changes which to me seem like trivial. That could be an improvement.

I added a custom iPhone sound to the notification in the yaml (this cannot be done in the GUI):

alias: Me at the Office
description: ""
trigger:
  - platform: zone
    entity_id: person.rolf
    zone: zone.office
    event: enter
condition: []
action:
  - device_id: f6f1e7XXXXXXXXXX32bf2
    domain: mobile_app
    type: notify
    message: Rolf at Work
    data:
        push:
           sound: 'shake.caf'
mode: single

I hope this helps others with these intermitting notification problems, although it is a bit frustrating that I did not get to why the blueprint does not work reliably.

I just updated the blueprint, you can now do entering and leaving in the same automation. I have it tested on my end and everything works.

I actually made it slightly simpler since the default one also checks extra for zone.home for some reason, which I found to not be neccesary.

There is only one bug, and that is you have to toggle both booleans, otherwise you’ll get an error when saving the automation. I already made an issue for that: Blueprint selector Boolean needs to be toggled when creating automation · Issue #100658 · home-assistant/core · GitHub

Hi,
Being new to HA, this is my first automation. That said, I need som help, and wonder if someone here can help. I imported the blueprint, and created some automations from, using zones I created and my familys devices. But when I click Run, I get no notification.

I tried once with the built-in blueprint, for leaving zones. That notifications reaches me just fine. Should I make any adjustments for this to work in the same way? Have I misconfigured something? I get no error message, in HA it looks like tha notifications has gone through just fine.

I think that is intended behaviour. When I click run on the automation, I don’t get a notification either.
I do get an warning in the log, since when the automation is run without a trigger, there is no from_state.

When I manually change the state of the person entity in Developer Tools -> States, I do get a notification. Can you try that as well?

That works for me too. I set the state to “away” and got a notification. Today, however, when I had some actual movment between zones, I didn´t. Can I somehow try this in the same way, to trigger a notification both on leaving the current state of “home”, and entering another zone?

Can you see in the history of your person entity if it actually changed stat?

Yes, in history I can see the switched zones. Again this morning, I got a notification on a person entity (my daughter) leaving Home, but I didn´t get a notification for entering a new zone (school). Again, in history it shows, and in the current state, it also shows the correct zone.

Both my kids just came home from school. I got notifications for both entering the Home zone. But nothing for leaving the school zone.
So, for Home everything seems ok, but for no other zones. Thoughts?

I got a notification both when leaving and entering my home zone today. I’ve now created a notification at another zone and will see tomorrow if it works. When I test that zone with the developer tools it gives me notifications as well.

Do you have any entries in the log about the blueprint?

Also, when you change the state of your person from home to other_zone, do you get two notifications? (Assuming you have two automations set up, one for home, and one for other_zone)

I am not exactly sure what you mean by:

But yes, i have entries i the log (looking in History for the person entity) that they arrived in the school zone this morning. And also when they arrived at home in the afternoon.
Looking in the Log book though, I don´t have anything about anyone leaving any zone. Only about entities being “detected at zoneName”.

About changing zones in the dev tools. I can´t get that to work. I looked up the names that the blueprint uses (zone.zone_name) and tried with that, but it only notified about leaving Home, not arriving in another zone. I also tried using the name I gave the zone (omitting the zone. ), but same thing. Am I doing it wrong?
I apologize, I´m at at the beginning of what I´m suspecting will be something of a learning experience.

With log I mean the error logs at config/logs.

When changing the state in developer tools, you just need the last part. So if the zone is zone.school just give the person the state school.

And just to confirm, you have an automation for each person/zone combination that you want notifications for?

I actually don´t have the logs directory in config. I do, however, have the home-assistant.log directly under config. Can´t find anything related there.

I tried changing zones in dev tools with just the last part. No difference. In Overview, the state shows on the person, but not as the zone is named in the UI, but just as I typed it in dev tools, som that doesn´t look quite right either. (underscore instead of space, no capital letter).

Yes, I have one automation, created from your blueprint, per person per zone. With notification for both entering and leaving enabled, and to the same device, which is my Iphone HA app.

Great…. But my hassio does this by default :roll_eyes: sending notifications to whoever enters or leaves a zone…. Annoying as hell!!! And no way to remove those notifications? :face_with_raised_eyebrow: I have seen a post from a hassio dev, that is will be fixed…… 7 years ago!!! So, am I missing something or this still cannot be turned off?