Trying to create an automation from webhook to MQTT

Hi, I’m trying to convert a webhook json request to a MQTT call
alias: rest2mqtt
description: rest2mqtt
trigger:

  • platform: webhook
    webhook_id: mqtt
    condition: []
    action:
    service: mqtt.publish
    data_template:
    topic: testar/mqtt
    payload_template: ‘{{ trigger.data }}’

If I send {“message”:“test”} to webhook I’m getting MQTT message <MultiDict(’{“message”:“test”}’: ‘’)>

Have also tried: payload_template: ‘{{ trigger.json}}’ but the it result in empty MQTT message.

Any ideas?

Hi Tony,

ages old question but since there is no answer so far and I just found a solution while having the same problem I’m posting it here. You can access the trigger payload with trigger.data + the parameter/attribute you would like to retrieve. See below yaml example snippet where I get the value for filename

alias: automation_name
description: ""
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
      - GET
      - HEAD
    local_only: true
    webhook_id: "-your_webhook_id"
conditions: []
actions:
  - action: mqtt.publish
    metadata: {}
    data:
      evaluate_payload: true
      qos: 0
      retain: false
      topic: /your/mqtt/topic
      payload: "{{ trigger.data.filename }}"
mode: single