Frigate notifications with image_proxy based snapshots - working

Hello all,

Ive spent a lot of time trying to get home assistant to send notifications when objects are detected in frigate. I am aware of the great work that has been done in some pretty sophisticated blueprints but i wanted something simple. I also saw other people’s attempt to use the downloader integration to copy an image from a camera snapshot when the detection event happened, and then add that image into the notification itself, but i really didnt want to deal with downloading images.

I started off with a great blueprint for frigate notifications and then started slimming it down.

I discovered the API call for image_proxy, a way of grabbing an image from an image entity (relatively new). The frigate integration also provides image entities for each camera and each type of tracked object showing the last snapshot of a detection event.

It was a lot of screwing around but i wanted to share what i was able to get going.

In my case i have the SNMP notification service and an ios device (my iphone) notification service both working with the image from the image_proxy.

I am also using Nabu Casa for remote access but if you dont use this or have configured your own reverse proxy then just change the URLs pointing to your home assistant instance. Note i obscured my nabu casa URL for security reasons.

One thing i discovered is to get the retrieved image proxy image ot work with the SNMP notification, i had to embed it in an HTML payload for the notification. I could never get it to work just embedding it as an ‘image’. That took a while to figure out :).

I hope some of you find this of use. .you can play around with the HTML template and other things but at least this provides a notification without copying images. Ofcourse if you need more functionality certainly check out some of the other great blueprints.

alias: Frigate NVR Alerts
description: ""
triggers:
  - topic: frigate/events
    id: frigate-event
    value_template: "{{ value_json['after']['camera'] }}"
    variables:
      camera: "{{ trigger.payload_json['after']['camera'] }}"
      id: "{{ trigger.payload_json['after']['id'] }}"
      label: "{{ trigger.payload_json['after']['label'] }}"
      score: "{{ trigger.payload_json['after']['score'] }}"
      time_clip_start: "{{ trigger.payload_json['after']['start_time'] - 10.0 }}"
      image_proxy_entity: "image.{{camera}}_{{label}}"
    trigger: mqtt
conditions:
  - condition: template
    value_template: "{{ trigger.payload_json['type'] == 'new' }}"
actions:
  - data_template:
      title: >-
        FRIGATE: {{camera}} camera {{label}} detected
      message: >-
        A {{label}} on {{camera}} camera was detected.
      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 http-equiv="Content-Type" content="text/html; charset=UTF-8">
                   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css">
               </head>
               <body>
                   <img style="width: 75%;"
                       alt="snapshot1" src="https://r3zf7dcabylsuap.ui.nabu.casa{{state_attr(image_proxy_entity, 'entity_picture')}}" />
               </body>
           </html>
    action: notify.frigate_gmail
    metadata: {}
  - data_template:
      title: >-
        FRIGATE: {{camera}} camera {{label}} detected
      message: A {{label}} on {{camera}} camera was detected.
      data:
        attachment:
          content-type: jpeg
          url: 'https://r3zf7dcabylsuap.ui.nabu.casa{{state_attr(image_proxy_entity, "entity_picture")}}'
    action: notify.mobile_app_thomass_iphone
    metadata: {}
mode: queued