Need help configuring value_template to match json and send notification

The scenario is that an Access Control system sends email to SMTP2MQTT on HA which then MQTT publishes. I’m trying to create automations that will complete based on certain words in the subject or content portion of the email. I trigger the automation based on the MQTT topic, which works, but can’t get the value template in condition to match a value for instance “Door-Unlocked”. I would also like to be able to reuse the matched value for a notification when the automation is triggered. The published json is below:

{
    "uuid": "182b12bb",
    "headers": {
        "date": "Wed, 15 Apr 2026 12:40:57 +0800",
        "from": "[email protected]",
        "to": "[email protected]",
        "subject": "2026-04-14 21:40:58-Default Group-FZAxS-Front Door-Unlocked by card",
        "mime-version": "1.0",
        "content-type": "multipart/mixed; boundary=\"======PRIVATE======\""
    },
    "mime_parts": [
        {
            "best_guess": "message body",
            "headers": {
                "content-type": "text/plain; charset=\"UTF-8\"",
                "content-transfer-encoding": "base64"
            },
            "content": "2026-04-14 21:40:58-Default Group-FZAxS-Front Door-Unlocked by card\n"
        }
    ]
}

If you are using an MQTT trigger, you can reference the payloads by using the trigger variable (from the docs). In your case:
trigger.payload_json.mime_parts[0].content

So that may get me closer as I was missing mime-parts but the problem I’m having is the syntax of the value template and getting it to match if trigger.payload_json.mime_parts[0].content contains value “x”

{{ trigger.payload_json.mime_parts[0].content is search('Door-Unlocked') }}

or

{{ trigger.payload_json.headers.subject is search('Door-Unlocked') }}

Or

{{ 'Door-Unlocked' in trigger.payload_json.mime_parts[0].content }}

I already had this template in but without the mime-parts[0] so decided to give it a try and it worked. Do the other examples you gave differ in functionality from my solution or is just another way to solve it? Thank you by the way!

It’s just a different way… IIRC, using in is probably a little more efficient, so you might as well stick with that. One benefit to using search would be the option to control whether it is case sensitive or not… if that’s something you might need.

Right on thanks! Now to get the matched value into the notification. I’ve only done it with trigger.to_state.name before.

triggers:
  #Your MQTT trigger
variables:
  content: "{{ trigger.payload_json.mime_parts[0].content }}"
  search_terms:
    - "Door-Unlocked"
    - "Door-Locked"
    - "Something Else"
  search_results: |
    {% set ns = namespace(found=[]) %}
    {% for t in search_terms if t in content %}
      {% set ns.found = ns.found + [t] %}
    {% endfor %}
    {{ ns.found }}
conditions:
  - "{{ search_results != [] }}"
actions:
  - action: notify.example
    data:
      title: Message from Access Control
      message: "{{ search_results | join(', ') }}"

I’ll have to try this when I get home. Just saw your name…lol…love it. I’m more of a didgeridon’t! lol Thanks again. Peace!