MQTT Payload Trigger

Hi Guys

Firstly excuse my lack of knowledge as this is the first time I have used MQTT.

I want to make several automations relating to frigate events and send pics and vids via telegram, I have this working but want to know if its possible to change the trigger to include a payload.

Curently using the following trigger (and nearly everything I read uses this example):

  - platform: mqtt
    topic: frigate/events

Then as a condition I use for example:

  - condition: or
      - condition: template
        value_template: '{{ trigger.payload_json[''after''][''camera''] == ''garden_cam'' }}'
      - condition: template
        value_template: '{{ trigger.payload_json[''before''][''camera''] == ''garden_cam'' }}'

Now this works, however as I plan to add multiple automations for multiple cameras, I end up with these automations constantly being triggered (yes they technically are not triggering as they dont pass the conditions) however it makes debugging them almost impossible as the traces show no actions but 101 triggers as I am technically triggering off every single frigate MQTT event regardless of what that event might be.

In my mind, I am wondering if there is a way to set the automations to trigger based on the camera in the payload, but having spent hours trying to work out if this is even possible and if so how to write it and failed, I am reaching out to see if others can advise.



For the trigger, I have used payload to do this. In other words the trigger had to match both the topic and the payload value. In my case the payload was a simple string.
However the docs seem to say you can use payload along with a template for JSON payloads as well: