I would like to get a notification when a person enters or leaves a zone.
I tried with
alias: Notify on Zone Enter/Exit
description: Send notification when a person enters or exits a zone
triggers:
- event_type: zone
trigger: event
conditions: []
actions:
- device_id: 9921fc3e7d0b46f213a71a6d0a5cfa6d
domain: mobile_app
type: notify
message: |
{% if trigger.event.data.event == "enter" %}
{{ trigger.event.data.person }} has entered {{ trigger.event.data.zone }}
{% elif trigger.event.data.event == "leave" %}
{{ trigger.event.data.person }} has left {{ trigger.event.data.zone }}
{% else %}
{{ trigger.event.data.person }} has changed zones
{% endif %}
title: Cambio zona
But I get
Error rendering message: UndefinedError: 'dict object' has no attribute 'event'
The error is likely being cause by the method you are using to test the automation. The docs explain how to test automations that use the trigger variable.
Device actions are designed for new users and basic uses, they generally do not support templating. You will need to use an entity-based action (formerly known as a service call action).
AFAIK there isnāt a built-in event that match your triggerās requirements. Are you using a custom event? If so, you will need to share the details of the action you are using to raise the event for us to be able to help. Maybe you meant to use a Zone Trigger?
If I trigger a āzoneā event I get the notification (without any parameter as I didnāt specify them). If I change my state to home or not_home nothing happens (no zone event). Tomorrow Iāll try to move out of the zone but I am suspecting that @Didgeridrew was correct about the wrong trigger
If you want to trigger any time any person enters or leaves a specific zone, you would want a state trigger using the zone entity and specifying the persons attribute.
I monitor the personās state and look at the zone they move into or out of. The tricky part about that was that the zone friendly name is what is in the personās state, and I had to generate a list of the zone friendly names to compare against in my blueprint, as the zones are added by the user and I couldnāt code in the friendly names, but in a one-off in your own set-up you know the zone friendly names, so that is easier.
I have set-up a couple of dozen zones so that when one of us are out and about, HA tells us where the other is. At work, at the hospital, at a store, etcā¦ (voice on the google speaker)