Blueprint->Mqtt trigger with trigger_variables-> trigger.payload_json HowToUse?

Hello!

I’m trying to create myself a blueprint that will listen to a topic for button-presses on Tasmota Devices with detached buttons (SetOption73 ON).

According to HA Docs I should be able to use trigger.payload_json in trigger_variables:

Yet my atempt (in green) below fails to work. When using red lines my blueprint works, with green lines it does not. What am I missing here?

For copy paste purposes

trigger_variables:
  _device: !input tasmota_device
  _button: !input tasmota_button
  #button: '{{ _button if _button is string else "Button1" }}'
  button: >
    {{
        trigger.payload_json.Button1.Action if (_button|string == "Button1" and trigger.payload_json.Button1 is defined) else
        trigger.payload_json.Button2.Action if (_button|string == "Button2" and trigger.payload_json.Button2 is defined) else
        trigger.payload_json.Button3.Action if (_button|string == "Button3" and trigger.payload_json.Button3 is defined) else
        trigger.payload_json.Button4.Action if (_button|string == "Button4" and trigger.payload_json.Button4 is defined)
    }}
  _topic: !input tasmota_topic
  topic: '{{ _topic if _topic != "." else _device|replace("switch.", "")|replace("-","_") }}'

trigger:
  - platform: mqtt
    id: 'single'
    topic: '{{ topic }}'
    payload: 'SINGLE'
    #value_template: '{{ value_json.Button1.Action if value_json.Button1 is defined}}'
    value_template: '{{ button }}'
1 Like

Did you ever make the Blueprint in the end?

Trigger.payload_json does not exist until there is a trigger.
Therefore adding it to trigger_variables will not work.
I would suspect that the templating may be a bit more than limited templates allows as well.

To make something like this work, trigger in a more general manner and add that templating into condition statements or action statements where the trigger data is known and regular templating is allowed.