MQTT automation trigger: How do I access the payload?

Hi,

This automation doesn’t work:

- id: '1592574825562'
  alias: ping
  description: MQTT-Test
  trigger:
  - platform: mqtt
    topic: home/ass/ping/hass
  condition: []
  action:
  - data:
      payload_template: '{{ trigger.payload }}'
      topic: home/ass/ping/hass/reply
    service: mqtt.publish

It complains Error executing script. Error rendering template for call_service at pos 1: UndefinedError: 'trigger' is undefined.
Using a plain “payload” doesn’t work either; while that variable is defined, the content is empty.

Help?

try :

- id: '1592574825562'
  alias: ping
  description: MQTT-Test
  trigger:
  - platform: mqtt
    topic: home/ass/ping/hass
  condition: []
  action:
  - data_template:
      payload: '{{ trigger.payload }}'
      topic: home/ass/ping/hass/reply
    service: mqtt.publish

That, of course, replies with a literal payload of {{ trigger.payload }}.

Unnecessary to say that that’s not what I want.

No it doesn’t. The data_template informs the payload to use jinja.

Ah. Sorry, I missed the replacement of data with data_template. It’s been a too-long day here.

Thank you; that version does work, but (a) I’d very much like to know why the first version doesn’t, (b) now the automation can no longer be edited in the GUI, which I’m somewhat unhappy about.

Any service you call with data that needs to be processed by jinja, you need to use data_template. And unfortunately, the AE does not support data_template yet.