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?
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.