Pushbullet Automation Trigger Undefined Error

I am trying to use a template to send a pushbullet notification when a device tracker status has changed. I followed the documentation but I cannot get this automation to run, it keeps giving me a ‘trigger’ is undefined error?

alias: "My Status Changed"
trigger:
  - platform: state
    entity_id: device_tracker.removed_key
action:
  - service: notify.my_pushbullet
    data_template:
      title: "My Status Changed"
      message: >
        I am now {{ trigger.to_state.state }}

Please have a look to https://community.home-assistant.io/t/include-timestamp-in-notify/4192/2
This example is working.
Perhaps by this post you can get inspired to get yours working.

Thanks for the example, it does work but unfortunately it doesn’t help solve my issue as to why the trigger variable is undefined. I based my code on the first example from this page. The only difference I can tell is that the examples service is notify.notify and mine is notify.my_pushbullet.

Can you try removing the " for the alias?
And removing the “title”?

Ok, I’ve update my code to more closely resemble the example. This is how it now looks:

trigger:
    platform: state
    entity_id: device_tracker.removed_key
action:
    service: notify.my_pushbullet
    data_template:
      message: >
        Paulus just changed from {{ trigger.from_state.state }}
        to {{ trigger.to_state.state }}

It still gives the trigger is undefined error. Not sure if it makes a difference but all my automations are separate yaml files in an automation folder referenced from the configurations.yaml file.

According to me you must replace “trigger” by the name of your automation.

For example:

automation.test_notification.to_state.state

In this case the alias is

alias: Test notification

I’ve updated my code but now I get an ‘automation’ is undefined error instead.

My Code:

alias: Test notification
trigger:
  - platform: state
    entity_id: device_tracker.removed_key
action:
    service: notify.my_pushbullet
    data_template:
      message: >
        Paulus just changed from {{ automation.test_notification.from_state.state }}
        to {{ automation.test_notification.to_state.state }}

Error log:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/template.py", line 62, in render
    }).render(kwargs).strip()
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.4/dist-packages/jinja2/sandbox.py", line 329, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'automation' is undefined

Into your-homeassistant-ip:8123/dev-state do you find the automation called “automation.test_notification”?

yes

Apparently it must not like my device tracker entity, because I switched the entity to my kitchen light switch and now it works?

alias: Test notification
trigger:
  - platform: state
#    entity_id: device_tracker.removed_key
    entity_id: switch.kitchen_lights_switch_4
action:
  - service: notify.my_pushbullet
    data_template:
      message: i am now {{ trigger.to_state.state }}

So we should conclude that it’s not working with all kind of entities.
But in the example they use a device_tracker entity…
Strange.

Strange indeed. I’ve tried two different device id’s and I get the same error on both.