Good morning everyone. I’m a Paramedic Refrigerator Repairman, and when I’m dispatched to a call, I get an email with the address. I’m using the IMAP integration, and trying to set HA to send me a notification to my phone when I get dispatched. I’m having a bit of troubling getting it to work.
Here’s an example dispatch email. This is obviously redacted, if you think there’s something I redacted that could have bearing on my automation, let me know and I’ll provide it
Delivered-To: <redacted>
Received: by <redacted> with SMTP id <redacted>;
Wed, 6 Aug 2025 07:21:01 -0700 (PDT)
X-Received: by <redacted> with SMTP id <redacted>.6.1754490061354;
Wed, 06 Aug 2025 07:21:01 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1754490061; cv=none;
d=google.com; s=arc-20240605;
b=<redacted>==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
h=to:subject:message-id:date:from:mime-version:dkim-signature;
<redacted>=;
f<redacted>s=;
b=<redacted>w==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass [email protected] header.s=20230601 header.b="GtoNF/W5";
spf=pass (google.com: domain of <redacted>@gmail.com designates <redacted> as permitted sender) smtp.mailfrom=<redacted>.com;
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com;
dara=pass [email protected]
Return-Path: <<redacted>@gmail.com>
Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
by mx.google.com with SMTPS id 586e51a60fabf-30be4aaa62fsor873072fac.14.2025.08.06.07.21.01
for <[email protected]>
(Google Transport Security);
Wed, 06 Aug 2025 07:21:01 -0700 (PDT)
Received-SPF: pass (google.com: domain of <redacted>@gmail.com designates <redacted> as permitted sender) client-ip=2<redacted>1;
Authentication-Results: mx.google.com;
dkim=pass [email protected] header.s=20230601 header.b="GtoNF/W5";
spf=pass (google.com: domain of <redacted>@gmail.com designates <redacted> as permitted sender) smtp.mailfrom=<redacted>@gmail.com;
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com;
dara=pass [email protected]
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1754490061; x=1755094861; darn=chaveir.im;
h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
:date:message-id:reply-to;
bh=pyj+RVtf5dsnDOowowtfwO4UF9Qz7ui0+gpXEKES2RY=;
b=<redacted>==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1754490061; x=1755094861;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=pyj+RVtf5dsnDOowowtfwO4UF9Qz7ui0+gpXEKES2RY=;
b=<redacted>==
X-Gm-Message-State: <redacted> <redacted>/<redacted>/<redacted> <redacted>+2oeWFOyf+Hl5xK8
X-Gm-Gg: <redacted>/1j3QXvLZB9DUo <redacted>/<redacted>+<redacted>+<redacted> xSx1X9zHAy3/UZxu2oC5g/I8VHGoZD2tjn7pGZti8wjkdofI5xA3Y/AgBCVzIrIfbViuzBePOyj oEeuRw=
X-Google-Smtp-Source: AGHT+IF/<redacted>+<redacted>+<redacted>/FgwoekkTDcURq8w=
X-Received: by 2<redacted> with SMTP id <redacted>-<redacted>.23.1754490060457; Wed, 06 Aug 2025 07:21:00 -0700 (PDT)
MIME-Version: 1.0
From: <redacted> <<redacted>@gmail.com>
Date: Wed, 6 Aug 2025 10:20:49 -0400
X-Gm-Features: <redacted>
Message-ID: <<redacted>[email protected]>
Subject:
To: <redacted>@<redacted>.com
Content-Type: multipart/alternative; boundary="000000000000d0cd24063bb30c87"
--000000000000d0cd24063bb30c87
Content-Type: text/plain; charset="UTF-8"
266B Something Rd -- Between Fake Ave & Another St - Access: First - Call
ID: 1508041230 - <s>Unresponsive</s> Broken Fridge
--000000000000d0cd24063bb30c87
Content-Type: text/html; charset="UTF-8"
<div dir="ltr">
266B Something Rd -- Between Fake Ave & Another St - Access: First - Call ID: 1508041230 - <s>Unresponsive</s> Broken Fridge
<br></div>
--000000000000d0cd24063bb30c87--
Here’s my automation so far. The triggers are working, and my phone notification is getting delivered, but instead of correctly parsing the email, I’m getting the “Unknown” notification.
alias: <s>EMT</s> Repair Dispatch Notification
description: Process <s>EMT</s> Repair dispatch emails and send phone notifications
triggers:
- event_type: imap_content
id: emergency_notifications
event_data:
server: imap.gmail.com
username: [email protected]
trigger: event
conditions:
- condition: template
value_template: >-
{{ trigger.event.data.sender.lower() in ['<s>[email protected]</s>[email protected]',
'[email protected]'] }}
actions:
- variables:
email_subject: "{{ trigger.event.data.subject }}"
email_body: "{{ trigger.event.data.text | replace('\r\n', '\n') | replace('\r', '\n') }}"
address_matches: >-
{{ email_body | regex_findall('(?m)\s*(.*?) -- (.*?) - (?:Access: (.*?)
- )?Call ID: (\d{10}) - (.+)') }}
parsed_address: "{{ address_matches[0][0] if address_matches else 'Unknown Address' }}"
parsed_cross_streets: >-
{{ address_matches[0][1] if address_matches else 'Unknown Cross Streets'
}}
parsed_access_info: >-
{{ address_matches[0][2] if address_matches and address_matches[0][2]
else '' }}
parsed_call_id: "{{ address_matches[0][3] if address_matches else 'Unknown Call ID' }}"
parsed_call_type: "{{ address_matches[0][4] if address_matches else 'Unknown Call Type' }}"
- data:
title: Regex Debug
message: "{{ address_matches }}"
action: persistent_notification.create
- data:
title: >-
{% if parsed_call_type != 'Unknown Call Type' %}{{ parsed_call_type }}{%
else %}🚨 Incoming <s>Emergency</s> Repair Call 🚨{% endif %}
message: >-
📍 {{ parsed_address }} 🛣️ {{ parsed_cross_streets }} {% if
parsed_access_info %}🔑 {{ parsed_access_info }}{% endif %} 🆔 {{
parsed_call_id }} 📞 {{ parsed_call_type }}
data:
channel: <s>EMT</s>Repair_Dispatch
importance: high
priority: high
persistent: true
sticky: true
tag: <s>emt</s>repair_dispatch
actions:
- action: ACKNOWLEDGE
title: Acknowledge
- action: NAVIGATE
title: Navigate
uri: >-
intent://maps.google.com/maps?daddr={{ parsed_address | urlencode
}}#Intent;scheme=https;package=com.google.android.apps.maps;end
action: notify.mobile_app_my_phone
Can someone help me get the regex parsing to work correctly?
Any suggestions on a better system?
Thanks so much
Dovy