MQTT payload_json: using in automation action separate from trigger

Use case: Have access to jpg and mp4 files via api links. The urls for each require templates based on a mqtt topic’s payload. I’d like to send the jpg file via telegram with an inline keyboard access to the video file. Reason being I don’t always want the video on my phone but could decide based on the jpg file.

Issue: Both the link to the jpg and the mp4 require templated trigger.payload_json in the urls. Works fine for the snapshot automation (that automation has the mqtt topic in the trigger) but not in the telegram callback video automation as the mqtt topic is not in that automation.

Question: is it possible to extract the payload_json info from an mqtt topic without having that mqtt topic as the trigger? Basically can I pull that payload info into the 2nd automation below without using the mqtt topic in the trigger? The first automation below works fine; the second obviously doesn’t. If I replaced the jpg url in the first automation with the mp4 url, the format of the mp4 url is correct.

Lots going on here; I know. Thanks in advance for any thoughts/suggestions.

- id: Presence Snapshot
  alias: Presence Snapshot
  trigger:
    - platform: mqtt
      topic: "frigate/events"
  action:
    - service: notify.home
      data_template:
          message: 'A {{trigger.payload_json["after"]["label"]}} was detected.'
          data:
            photo:
              - url: 'http://X.X.X.X:XXXX/api/events/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg?format=android'
                caption: 'A {{trigger.payload_json["after"]["label"]}} was detected on {{ trigger.payload_json["after"]["camera"] }} camera at {{ now().strftime("%a %m/%d/%y at %I:%M:%S %p")}}'
            inline_keyboard:
              - 'SHOW VIDEO CLIP:/clip'
              
- id: Presence Video
  alias: Presence Video
  trigger: 
    - platform: event
      event_type: telegram_callback
      event_data: 
        data: '/clip'
  action: 
    - service: notify.home
      data:
        video: 
          - url: 'http://X.X.X.X:XXXX/clips/{{trigger.payload_json["after"]["camera"]}}-{{trigger.payload_json["after"]["id"]}}.mp4'

In short, no (not in the way you’re proposing to do it).

The Trigger State Object refers to the information provided by the trigger. Therefore trigger.payload_json refers to whatever was produced by the automation’s MQTT Trigger (and nothing else).

MQTT payloads are published to topics. An MQTT client subscribes to a topic and receives the payload at the moment it is published. In other words, you can’t “query” a topic for its payload. The only exception to this general behavior is if the payload is published as a retained message (i.e. the payload is stored by the MQTT Broker). At the moment an MQTT client subscribes to the topic, it will receive the retained message. That’s still nowhere near the concept of “querying” a topic.

In your case, you could create an MQTT Sensor that subscribes to the second topic and stores the url in its state value. Your automation can retrieve it using states('sensor.my_url'). This will work as long as the url’s length doesn’t exceed 255 characters (maximum permissible string length of a state value).

Thanks for the reply. With the MQTT sensor model, only the last published payload would be captured, correct? Meaning each time the payload updated, the sensor updates accordingly and only the most recent captured video in my use case would be accessible?

Thanks again for your time

That’s correct.