Templateing - UndefinedError: 'trigger' is undefined

Hi,

I’m new to HA and trying to setup my first automation using split config files.

My automations.yaml file looks like this,

- id: device_update
  alias: 'Device update'
  trigger:
    platform: state
    entity_id: group.phones
  action:
    service: notify.slack
    data_template:
      message: '{{ trigger.entity_id }} just changed from {{ trigger.from_state.state }} to {{ trigger.to_state.state }}'

When triggering this automation I get this error,

homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined

I suspect it’s a variable scoping error, and I tried a few variants of this, but can’t figure out how to reference trigger data in the template. Can anyone help?

I’ve been using this docs

1 Like

That’s a symptom of manually triggering the automation.
My guess is that if one of your devices actually changes state, your automation will work just fine.

Yes, it did work like you said, thanks :slight_smile: