Unable to access zone trigger variables in action

Hi community,

Writing my first automation to send a Telegram message when someone enters or leaves a zone. I want to use variables to avoid duplicating the same automation just to make minor changes. So I started with this simple automation to iterate on.

alias: Notify enter or leave events for zone
description: Notify enter or leave events
trigger:
  - platform: zone
    entity_id: person.myperson
    zone: zone.myzone
    event: enter
condition: []
action:
  - service: telegram_bot.send_message
    metadata: {}
    data:
      message: >-
        Got {{ trigger.event }} event for {{ trigger.entity_id }}
      target: [redacted]
mode: single

However, I am getting the below erros when the automation is executed.

WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'event' when rendering 'Got {{ trigger.event }} event for {{ trigger.entity_id }}'
WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'entity_id' when rendering 'Got {{ trigger.event }} event for {{ trigger.entity_id }}'

According to this page, what I am doing should be possible. Have I missed anything?

What I do when I am starting a new automation to see what is actually provided in the trigger is a persistent notification with just

{{ trigger }}

in it. Then work it out from there to get the data I want.

You mean “when myperson enters or leaves myzone” or “when I manually run the automation”?

If the latter, that is expected behaviour:

1 Like

Hi @Troon, good point. I should have been clearer when explaining. Thanks for the link.

I’ve tried running the automation directly “Automations > Three dots > Run”. Which I now understand will skip the trigger and condition and executes the actions directly. I did however try to test it with “Developer tools > Services” and I get the same result. I’d expect that at least trigger.event would be resolved but it isn’t.

Looking further into the automation service, it looks like testing the end-to-end isn’t currently possible. I could try to create zone with small enough radius at home for testing. Any other way?

You need to include the trigger data in the YAML of the service call, as per the doc:

If needed, additional trigger or other data can be added in the YAML view for testing. The trigger page has more information about data within the trigger.

Are you populating trigger.event in your call?

You could use Developer tools > States.

Set yourself out of that zone then back in. That should trigger it.

1 Like

That’s exactly what I needed, @jeffcrum. Thanks for that. For Zone automations, this is the easiest way to test the end-to-end.