UndefinedError: 'trigger' is undefined

Hi,

I am struggling with templates in my automation. The following automation throws the error below.

HASS log:

2017-06-18 12:19:30 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 101, in async_render
return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/sandbox.py", line 385, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined

Any idea whats causing this error?

1 Like

Loose the dashes:

- alias: 'Device Status'
  trigger:
    platform: state
      entity_id: sensor.robo, sensor.tradfri, sensor.switch
      to: 'off'
      for:
        minutes: 5
  action:
    service: notify.ios_iphones   
      data:   
        title: 'Devices'    
        message: '{{ trigger.to_state.attributes.friendly_name }} is {{ trigger.to_state.state }}'

Thanks for your help. I just tried it without the dashes. But the error remains the same.

Instead of “data:”, you should have “data_template:”

3 Likes

Also, be careful that you don’t have any odd characters in there. No tabs (spaces only)… that kind of thing. Your text editor likely has a setting for this. If you use Notepad++, take a look at

Your indentation is off. platform and entity_id need to be at the same level. Take a look examples here

1 Like

That correction did the trick! Thanks. It works know like expected.

1 Like