trying my hand at my first automation and received a trigger is undefined error: Error rendering template for call_service at pos 1: UndefinedError: ‘trigger’ is undefined
I checked my config multiple times but obviously I am missing something.
- id: '1581610932185'
alias: Arrive At Work
trigger:
platform: zone
entity_id: device_tracker.life360_ken
zone: zone.dc3
event: enter
condition: []
action:
service: notify.gmail
data:
message: '{ trigger.entity_id.attributes.friendly_name }} has entered {{ trigger.zone
}}'
that seems correct. It’ll give you the error as there is no actual trigger yet and this is a template.
you’ll need check triggering the actual automation.
I would also double-check your config.yaml . (better safe than sorry). Typically any “undefined” errors points to some sort of incomplete setup in your configuration.yaml file (from my experience).
you can’t manually trigger a automation that uses a trigger object in the template because if you trigger it manually there was never any trigger since the automation ignores the trigger and conditions when you trigger it like that.
you have to actually leave the zone and re-enter to trigger it properly so the action knows what to do with the template.
If it’s some other reason for the error then you need to give more information.
ok, so I arrived at work this morning, and the automation shows as trigger, BUT I did not get any email notification…
Got this error: Error rendering data template: UndefinedError: ‘str object’ has no attribute ‘attributes’
I am going to strip back the message to something simple like “ken has arrived at work” and see if I can get the automation to complete by sending the email.
If we choose trigger.to_state that will provide us with the new State object. We can now refer to the State object’s properties (listed here). We need this one:
state.name
Name of the entity. Based on friendly_name attribute with fall back to object ID. Example: Kitchen Ceiling .
So the correct reference is: trigger.to_state.name