Hi,
I’m trying to setup an automation to email (using stmp) an attachment which is an image that comes from Frigate api (hass integration). Not sure if this is possible or if there is a better way? I found this approach, but seems like an extra step and I don’t see how this would work for frigate? I would love it if I could just get this working… Here is my example automation (urls redacted):
alias: frigate cam person EMAIL
trigger:
- platform: mqtt
topic: frigate/events
condition:
- condition: template
value_template: "{{ trigger.payload_json['after']['label'] == 'person' }}"
action:
- delay:
seconds: 2
- service: notify.email
data:
target: [email protected]
title: >-
{{trigger.payload_json["after"]["camera"]}} camera
{{trigger.payload_json["after"]["label"]}} detected!
message: >
A {{trigger.payload_json["after"]["label"]}} was detected on
{{trigger.payload_json["after"]["camera"]}} camera.
Check out the details here...
snapshot...
https://my-public-ha.domain.com/api/frigate/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/snapshot.jpg
data:
image:
- "https://my-public-ha.domain.com/api/frigate/frigate/notifications/{{trigger.payload_json['after']['id']}}/snapshot.jpg"
- delay:
seconds: 30
mode: single
I even tried just hard coding one url without variables in it, but that didn’t work either…
I also tried “attachment” which it says here should work but I dunno?
Did a bit more troubleshooting, and here is a very basic test that should work but doesn’t (using a publicly available image url) as well as a way that embeds it with html that does work.
service: notify.email_paul
data:
message: test
title: test
data:
image: "https://picsum.photos/200/300.jpg"
this does it inline (not exactly what I wanted)
service: notify.email_paul
data:
message: test
title: test
data:
html: >
<img src="https://picsum.photos/200/300.jpg">
Yea, I guess html with src= is the only way? Technically it isn’t an email attachment, weird that it doesn’t seem to work even though in the docs it says it should.
Thanks!
FWIW I do this by using image.snapshot to save the frigate detected image including the object detection box to a file and then attach the file to the email. This comes in as an attachment and renders nice in various email client apps.
alias: Alert when person at front door
triggers:
- entity_id:
- binary_sensor.ground_person_occupancy
from: "off"
to: "on"
trigger: state
actions:
- delay:
milliseconds: 500
- action: image.snapshot
metadata: {}
data:
filename: /home/homeassistant/.homeassistant/snapshots/ground-person.jpg
target:
entity_id: image.ground_person
- delay:
milliseconds: 500
- metadata: {}
data:
message: Person at front door
title: PERSON
data:
images:
- /home/homeassistant/.homeassistant/snapshots/ground-person.jpg
action: notify.emailer
mode: single
Beyond this automation you just have to make sure the folder the snapshot is saved in is in your allowlist in configuration.yaml: