SMTP Notification and Frigate (proxy) Integration

hello guys,
after having read a lot posts and tried many configurations, here I’am to ask for a help.

SETUP:
Home Assitstant Version

  • core-2021.11.3
  • supervisor-2021.12.2
  • Home Assistant OS 6.6

FrigateProxy Version 1.3
Frigate external Docker image: 0.9.4

SCOPE:
Send email notifications with snapshots attachment triggered from frigate object detection

CONFIGURATION
as for now everything seem to be running, except that I don’t see the image/s attached to the email that are sent correctly.

The automation is configured with a MQTT trigger on frigate/events topic to retrieve the event ID triggered from the frigate object detection system.

here is the code:

- id: '1640686723123'
  alias: AUTOMATION-MOTION-DETECTION-EMAIL
  description: ' '
  trigger:
  - platform: mqtt
    topic: frigate/events
    payload: "CAM1 #!input 'camera'
    value_template: '{{ value_json[''after''][''camera''] }}'
  variables:
    frigateid: '{{ trigger.payload_json[''after''][''id''] }}'
    camera: '{{ trigger.payload_json[''after''][''camera''] }}'
    camera_name: '{{ camera | replace(''_'', '' '') | title }}'
    object: '{{ trigger.payload_json[''after''][''label''] }}'
    label: '{{ object | title }}'
    entered_zones: '{{ trigger.payload_json[''after''][''entered_zones''] }}'
    type: '{{ trigger.payload_json[''type''] }}' 
  condition: []
  action:
  - service: notify.NOTIFICATION_EMAIL
    data:
      title: ALERT! 
      message: Alert motion detection
      data:
        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>
                            <h1>Intruder alert at Camera: <b>{{ camera_name }}</b></h1>
                        </div>
                    </div>
                    <div>
                      <div>
                        <div>
                          <img src="http://<frigateIP>:5000/api/events/{{frigateid}}/snapshot.jpg" />
                        </div>
                        <div>
                          <h2 ENd message />
                        </div>
                      </div>
                      <br>
                    </div>
                  </body>
              </html>
  mode: single

I want to add that I configured another notify service that uses the SMTP component and it is configured with a local mail server (and relay) written in JS… and, guess…, the email contains the image attached that I can check from the web GUI; when it relays externally the email, the attachment is not present anymore; believe me, I do not understand when using a public SMTP server the image is not attached, in both cases, or using SMTP Public server or relaying the email through a SMTP Public server.

looking at the Home Assistant SMTP component python code it seems that component needs the image/s to be retrieved from the FS (as described in this topic) other than the HTML code.
Is there a way to load the image form an URL? or a way to attach to the email an image triggered from frigate (external server)?

I do the same with the Telegram Notification and I’m able to receive the notification with the snapshot attached.

any help and/or suggestions will be appreciated and thank you in advance.

edit: disregard I didn’t read the part where you already use telegram :frowning:

hi, but sorry I don’t understand what you mean? Do you need further details?
please let me know.

I’m sorry I originally replied with a similar automation that sends photos via telegram saying you could perhaps adapt it, but that was before I read the bottom of your post where you said you already use telegram like that.

Hi, i was hoping for suggestions, but any way, thank you very much for clarifying :wink: .
looking for some one else that can address me, because I’m getting mad for that…
the only thing I can do at the moment is a tcpdump… :zipper_mouth_face: :sleepy: :pensive:

after further investigations it seems that if I use a local mail server I’m able to see the image attached since the local url is reachable but when I relay and/or send the email through a public mail server the image is not reachable anymore because hosted on a private server not exposed on internet.
having saying that I suppose that I can have 2 options:

  1. Embed the image as text in the html
  2. an Automation or part of the automation trigger that download the the snapshot related to the frigate event locally to Home Assistant and then configure the notification data html as reference to the file hosted locally.

In both case do you have any suggestions about my investigations and/options?

any help and/or suggestions will be appreciated and thank you in advance.

Likewise stuck at this step as well for emailing the Frigate NVR. Too green to Home Assistant to be of help unfortunately.

I had the same problem and solved it.
As I’m using Unraid the way to achive it may be a bit different…

Indeed the problem seems to be that the smtp integration of home assistant cannot find and upload images coming from an url. It only works with local files. So the option “allowlist_external_urls” wont’ work.

This is what I did:

In my Frigate Docker I have mapped the container path “/media/frigate” to my Unraid host path “/mnt/disks/VideoDisk/webcams/frigate/”.
In Unraid it looks like this:

  Type:           path
  Name:           Media Path
  Container Path: /media/frigate
  Host Path:      /mnt/disks/VideoDisk/webcams/frigate/

The docker run command shoud be something like this:

  -v '/mnt/disks/VideoDisk/webcams/frigate/':'/media/frigate' 

The docker compose storage configurations should be something like this (https://docs.frigate.video/installation/):

  volumes:
    - /path/to/your/storage:/media/frigate

So I mapped a new path in my Home Assistant Container to the same host path (I did it “read only”!)
In Unraid it looks like this:

  Type:           path
  Name:           Media Webcam
  Container Path: /media-frigate
  Host Path:      /mnt/disks/VideoDisk/webcams/frigate/
  Mode:           ro,slave

The docker run command shoud be something like this:

  -v '/mnt/disks/VideoDisk/webcams/frigate/':'/media-frigate':'ro,slave'

Now, in Home Assistant configuration.yaml I added this:
Snippet from configuration.yaml:

  allowlist_external_dirs:
    - /media-frigate

In my automations file I added this as an action:
Snippet from automation:

    ### E-MAIL ------------------------------------------------------------------------------------
    - 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>\n\
                  Link: https://redacted.ui.nabu.casa/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://redacted.ui.nabu.casa/api/frigate/notifications/{{trigger.payload_json['after']['id']}}/snapshot.jpg">Link to Snapshot</a></li>
                                  <li><a href="https://redacted.ui.nabu.casa/lovelace/camera">Home Assistant Cameras</a></li>
                                  <li><a href="https://redacted.ui.nabu.casa/media-browser">Home Assistant Media Browser</a></li>
                                </ul>  
                              </p>
                            </div>
                        </div>
                      </body>
                  </html>

So now it works fine for me!
Hope this helps!

Hi Community,

I have also recently switched to frigate (Version 0.12.1 in docker) and have now also activated the email notifications. However, I had to install a delay of 15 seconds so that the image appears in the email, but that does not always work and sometimes the image is empty.

My Automation looks like this:

alias: Frigate Email
description: ""
trigger:
  - platform: mqtt
    topic: frigate/events
    payload: new
    value_template: "{{ value_json.type }}"
    enabled: true
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - service: notify.mailbox
    data:
      title: >-
        {{trigger.payload_json['after']['label']}} detected by
        {{trigger.payload_json['after']['camera']}}
      message: >-
        Detected object {{trigger.payload_json['after']['label']}} by
        {{trigger.payload_json['after']['camera']}}.
      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>
                          <img style="width: 100%; "alt="snapshot1" src="cid:{{trigger.payload_json['after']['camera']}}-{{trigger.payload_json['after']['id']}}.jpg" />
                          <br>
                          Time: '{{trigger.payload_json["after"]["start_time"]| int | timestamp_local}}'
                        </div>
                        <div>
                          <p>
                            <h5>Links</h5>
                            <ul>
                              <li><a href="https://home-assistant.local/api/frigate/notifications/{{trigger.payload_json['after']['id']}}/snapshot.jpg">Link to Snapshot</a></li>
                              <li><a href="https://home-assistant.local/lovelace">WebUI</a></li>
                              <li><a href="homeassistant://">Home Assistant App</a></li>   
                              <li><a href="https://home-assistant.local/media-browser/">Media Browser</a></li> 
                            </ul>  
                          </p>
                        </div>
                    </div>
                  </body>
              </html>
mode: single

I am running Home Assistant Container (2023.7.3) and the share /media/frigate/ is locally mounted, does anybody have an idea or knows how to troubleshoot this case?

Thank you!

Trigger on end not on new and check if has_snapshot is true
Additionally ignore stationary objects.

    condition:
      condition: template
      value_template: >-
        {{ trigger.payload_json['after']['has_snapshot'] 
        and not trigger.payload_json['after']['stationary'] }}