MQTT automation trigger by matching 2 pieces of the payload

Hi.

I want to create an automation that triggers on a topic. However I have to look into the message payload that is delivered and check two pieces of data for my trigger to fire however I can’t see how to do this:

platform: mqtt
topic: frigate/events
payload: front_door
value_template: '{{ value_json[''after''][''camera''] }}'
id: end_event

This works but I also need to check: {{ trigger.payload_json["type"] == "end" }}

I know I could do this with a condition but the automation I want to write has a separate second trigger that is based on a binary sensor which wouldn’t pass the condition (and I want it to).

For those that use Frigate NVR what I’m trying to do is a single automation to send a telegram message with a camera.snapshot as soon as motion is detected (which uses Frigate’s binary sensor) and then when the event has stopped I’d like to send a second telegram message with the video.

I can do this as two automations but that adds clutter that I’d prefer not to have and above doesn’t sound like it should be hard.

platform: mqtt
topic: frigate/events
payload: "on"
value_template: '{{ "on" if value_json["after"]["camera"] == "front_door" and value_json["type"] == "end" else "off"}}'
id: end_event

@koying Thanks for your post :slight_smile:
You helped me solve a problem I’ve been trying to get my head around for the last couple of days: “How to trigger when a json object is present in the trigger payload”

I had the following trigger:

platform: mqtt
topic: zigbee2mqtt/office/opple_one_button_remote
id: button_press

My mqtt message only has the object action in the payload when the button is pressed, but my trigger kept firing every hour. I finally realised that the battery value is reported hourly, but the payload does not contain the action object, so my light was toggling on & off even though I had not pressed the button.

Clarifying the trigger with:

platform: mqtt
topic: zigbee2mqtt/office/opple_one_button_remote
payload: "pressed"
value_template: '{{ "pressed" if value_json.action | is_defined }}'
id: button_press

ensures my trigger only fires when the button is actually pressed.

Without your post I think it would have taken me days to figure that solution out :slight_smile: