SgtBatten / HA_blueprints

Somewhere to store automation blueprints
191 stars 75 forks source link

[Config Support]: Unable to attach anything to SMTP alerts #105

Open myriad007 opened 1 year ago

myriad007 commented 1 year ago

Describe the problem you are having or the outcome you are trying to achieve.

I have created a Notification Group to send a smtp alert to my email (which works) but there are no links or attachments inserted in the email message:

`notify:

Version

Frigate Notifications (0.12.0.1)

Automation config file

alias: Email Frigate
description: Front Porch
use_blueprint:
  path: SgtBatten/Stable.yaml
  input:
    camera: camera.front_porch
    base_url: https://cctv.xxx.ca
    title: Front Porch Alert
    message: A Person was detected on the Front Porch camera. Email...
    critical: "false"
    alert_once: true
    update_thumbnail: false
    color: red
    icon: >-
      mdi:{{'account-outline' if label == 'Person' else 'dog' if label == 'Dog'
      else 'cat' if label == 'Cat' else 'car' if label == 'Car' else
      'home-assistant'}}
    ios_live_view: true
    labels:
      - person
      - dog
    zone_filter: false
    debug: true
    sound: none
    notify_group: email_notification
    attachment: thumbnail
    zones:
      - porch
    tap_action: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
    cooldown: 60

Frigate Config

mqtt:
  host: 192.168.1.76
  user: homeassistant
  password: hidden

detectors:
  coral_pci:
    type: edgetpu
    device: pci:0

cameras:
  Back_Yard:
    rtmp:
      enabled: false
    ffmpeg:
      inputs:
        - path: rtsp://admin:xxx@192.168.1.8:554/Streaming/Channels/101
          roles:
            - detect
            - record
    detect:
      width: 1920
      height: 1080
    snapshots: # <----- Enable snapshots
      enabled: True
    motion:
      mask:
         - 0,252,70,540,381,510,335,281,455,347,1183,170,1920,171,1920,0,0,0
    zones:
      zone_0:
           coordinates: 770,297,784,391,882,589,961,600,1022,581,1088,625,972,723,1110,792,1208,669,939,482,909,259
      zone_1:
           coordinates: 104,699,240,658,366,953,365,997,1385,975,1139,810,917,682,861,663,745,680,693,696,652,680,499,659,328,647,218,619,88,619
    record:
      enabled: True
      events:
        retain:
          default: 30
  Side_Door:
    rtmp:
      enabled: false
    ffmpeg:
      inputs:
        - path: rtsp://admin:xxx@192.168.1.7:554/Streaming/Channels/101
          roles:
            - detect
            - record
    detect:
      width: 1920
      height: 1080
    snapshots: # <----- Enable snapshots
      enabled: True
    motion:
      mask:
           - 1188,0,1204,124,1422,0,836,984,836,1080,425,1080,259,1080,149,1080,0,1080,0,0
    zones:
      zone_0:
           coordinates: 1383,786,1394,609,1416,354,1422,284,1406,217,1421,155,1416,85,1422,0,1216,0,1074,281,770,880,864,1080,1172,1080,1362,1080,1374,1040,1214,1035,1251,776
    record:
      enabled: True
      events:
        retain:
          default: 30           
  Front_Porch:
    rtmp:
      enabled: false
    ffmpeg:
      inputs:
        - path: rtsp://admin:xxx@192.168.1.10:554/Streaming/Channels/103
          roles:
            - detect
        - path: rtsp://admin:xxx@192.168.1.10:554/Streaming/Channels/101
          roles:
            - record
    detect:
      width: 1280
      height: 720
    snapshots: # <----- Enable snapshots
      enabled: True
    motion:
      mask:
           - 0,399,219,362,378,366,502,326,719,270,856,244,858,159,915,112,995,89,1136,121,1110,161,1154,209,1280,245,1280,0,0,0
    zones:
      zone_0:
           coordinates: 854,157,871,264,1062,615,1205,559,1280,306,1164,215,1148,207,1136,193,1113,178,1106,139,1056,127,1014,118,981,113,951,107,921,112
      zone_1:
           coordinates: 449,366,525,406,713,359,903,346,851,245
      zone_2:
           coordinates: 325,439,185,502,128,516,25,533,0,471,219,372
    record:
      enabled: True
      events:
        retain:
          default: 30

Any other information that may be helpful

I am not sure if your awesome script can even attach anything to SMTP but I would appreciate any input you can offer.

SgtBatten commented 1 year ago

Could you give an example of a working smtp notification please

myriad007 commented 1 year ago

Sure, here is a header: `Return-Path: bounce+509a3a.bb6a2e-xxx=xxx.ca@mg.xxx.com Received: from mail.myriad.ca (LHLO mail.myriad.ca) (10.40.10.42) by mail.xxx.ca with LMTP; Fri, 20 Oct 2023 06:14:49 -0400 (EDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.myriad.ca (Postfix) with ESMTP id C1B2AE2CAC for xxx@xxx.ca; Fri, 20 Oct 2023 06:14:49 -0400 (EDT) X-Virus-Scanned: amavis at mail.xxx.ca X-Spam-Flag: NO X-Spam-Score: -5.107 X-Spam-Level: X-Spam-Status: No, score=-5.107 required=6.6 tests=[BAYES_20=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Authentication-Results: mail.xxx.ca (amavis); dkim=pass (1024-bit key) header.d=mg.xxx.com Received: from mail.myriad.ca ([127.0.0.1]) by localhost (mail.myriad.ca [127.0.0.1]) (amavis, port 10024) with ESMTP id XgwOA-Bh5teY for xxx@xxx.ca; Fri, 20 Oct 2023 06:14:48 -0400 (EDT) Received: from so254-48.mailgun.net (so254-48.mailgun.net [198.61.254.48]) by mail.myriad.ca (Postfix) with ESMTPS id B1887E20AA for xxx@xxx.ca; Fri, 20 Oct 2023 06:14:48 -0400 (EDT) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.xxx.com; q=dns/txt; s=mailo; t=1697796881; x=1697804081; h=Message-Id: Date: From: From: To: To: Subject: Subject: MIME-Version: Content-Type: Sender: Sender; bh=bw94YuWhkmRuKGFz/VYyEoDZOopsMhjernUo87z8/LE=; b=OQr78NxqN5Rj+Ao20TiEl1rSn6DgcIp++jnA9FfgZa5tahMInv2O3+Oyi3M7atlOS874/9EYWkLQk47lf0iOxuRQh64xufiJD5xCJRvxG6LBlXDWuWgilc6SPjAyO1k24meJBrn62/xc+RJPCbnqEGfxRIG0zfmHQyXmuu811DY= X-Mailgun-Sending-Ip: 198.61.254.48 X-Mailgun-Sid: WyI3NTUyMCIsInJpY2hhcmRAbXlyaWFkLmNhIiwiYmI2YTJlIl0= Received: from a0d7b954-ssh.local.hass.io (lnsm5-toronto63-69-157-65-223.internet.virginmobile.ca [69.157.65.223]) by ad4ee74205aa with SMTP id 65325311293dd8a2778ca78b (version=TLS1.3, cipher=TLS_AES_128_GCM_SHA256); Fri, 20 Oct 2023 10:14:41 GMT Sender: noreply@mg.xxx.com Content-Type: multipart/related; boundary="===============5148013488708969329==" MIME-Version: 1.0 Subject: Front Porch Alert To: xxx@xxx.ca From: Home Assistant noreply@mg.xxx.com X-Mailer: Home Assistant Date: Fri, 20 Oct 2023 06:14:40 -0400 Message-Id: 169779688074.67.13877861563578738385@a0d7b954-ssh.local.hass.io

--===============5148013488708969329== Content-Type: multipart/alternative; boundary="===============4963668558929310845==" MIME-Version: 1.0

--===============4963668558929310845== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit

A Person was detected on the Front Porch camera. Email... --===============4963668558929310845== Content-Type: text/html; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit

A Person was detected on the Front Porch camera. Email...


--===============4963668558929310845==-- --===============5148013488708969329==--`
SgtBatten commented 1 year ago

Sorry I mean the yaml syntax for attaching an image or video in a HA notification.

myriad007 commented 1 year ago

Sorry, here you go:

alias: Email Frigate
description: Front Porch
use_blueprint:
  path: SgtBatten/Stable.yaml
  input:
    camera: camera.front_porch
    base_url: https://xxx.ca
    title: Front Porch Alert
    message: A Person was detected on the Front Porch camera. Email...
    critical: "false"
    alert_once: true
    update_thumbnail: false
    color: red
    icon: >-
      mdi:{{'account-outline' if label == 'Person' else 'dog' if label == 'Dog'
      else 'cat' if label == 'Cat' else 'car' if label == 'Car' else
      'home-assistant'}}
    ios_live_view: true
    labels:
      - person
      - dog
    zone_filter: false
    debug: false
    sound: none
    notify_group: email_notification
    attachment: thumbnail
    zones:
      - porch
    tap_action: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
    cooldown: 60
    action:
      - service: notify.mail_1
        data:
          title: "Camera {{trigger.payload_json['after']['camera']}}: Motion!"
          message: >-
            Detected object {{trigger.payload_json['after']['label']}} by camera
            {{trigger.payload_json['after']['camera']}}.<br>

            Link:
            https://xxx.ca/api/frigate/notifications/{{trigger.payload_json['after']['id']}}/snapshot.jpg
          data:
            images:
              - >-
                /media-frigate/clips/{{trigger.payload_json['after']['camera']}}-{{trigger.payload_json['after']['id']}}.jpg
            html: >
              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
                      <head>
                          <meta charset="UTF-8">
                          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                          <meta name="viewport" content="width=device-width, initial-scale=1.0">
                          <title>Intruder alert</title>
                      </head>
                      <body>
                        <div>
                            <div>
                                <h5>Motion detected by camera: <b>{{trigger.payload_json['after']['camera']}}</b></h5>
                            </div>
                            <div>
                              Picture<br><img style="width: 100%; "alt="snapshot1" src="cid:{{trigger.payload_json['after']['camera']}}-{{trigger.payload_json['after']['id']}}.jpg" />
                              <br>
                              Object: {{trigger.payload_json["after"]["label"]}}
                              <br>
                              Time: '{{trigger.payload_json["after"]["start_time"]|int}}'
                            </div>
                            <div>
                              <p>
                                <h5>Links</h5>
                                <ul>
                                  <li><a href="https://xxx.ca/api/frigate/notifications/{{trigger.payload_json['after']['id']}}/snapshot.jpg">Link to Snapshot</a></li>
                                  <li><a href="https://xxx.ca/lovelace/camera">Home Assistant Cameras</a></li>
                                  <li><a href="https://xxx.ca/media-browser">Home Assistant Media Browser</a></li>
                                </ul>  
                              </p>
                            </div>
                        </div>
                      </body>
                  </html>        
drewzh commented 11 months ago

Hi, I was wondering if you're still having the same issue (I assume so). I also just hit this today. It would be great to see this updated to support email body embedded image. I just wish I had time to contribute.

myriad007 commented 11 months ago

Still waiting for some feedback from the SGT.

SgtBatten commented 11 months ago

Thanks, sorry for the delay. So what you provided above doesn't work right? or it does but it's a custom action and you want it to work as part of the group notification?

myriad007 commented 11 months ago

Well, what would work for me is that the Blueprint provided most of the same information to the SMTP client as it now provides to my iPhone (minus the alert notification obviously). I just want to be able to see a thumbnail or video link and be able to launch a link to the home assistant in my Edge browser.

SgtBatten commented 11 months ago

What i was hoping to see was what a working one looked like to compare it to what we have. I've got no experience with setting up email notifications so any pointers appreciated.

myriad007 commented 11 months ago

Here is an example from my old Zoneminder installation: example