I am trying to figure out how to attach a photo to a persistent notification. I would like to send a notification when my front door camera detects a person with an image attached.
I have it working but for some reason it always sends the same photo. It’s like it is cached somewhere and doesn’t update the image even though a new image has been created.
alias: Send a notification
action: notify.persistent_notification
data:
message: >-
Person Detected<p> 
title: Front Door
I figured out the .jpg name needs to be unique for them to display right in the HA App/Web UI. I couldn’t get the variables to work in an automation from one command to another, so I went with a script which stores the file name in a helper, then call that script in the automation. I have setup a bunch of them and works significantly better than the DVR software alone, given the data I have in HA to work with.
Thanks for the info, here is my code / version of your script / automation. I decided that I’d write the file name to a text help from within the automation. Hopefully that will work.
alias: Doorbell Person or Button Pressed
description: >-
Triggers when a person is detected or the doorbell button is pressed. Takes a
snapshot, announces, and sends a notification.
triggers:
- entity_id: binary_sensor.doorbell_person
to: "on"
trigger: state
- entity_id: binary_sensor.doorbell_visitor
to: "on"
trigger: state
conditions:
- condition: state
entity_id: binary_sensor.doorbell_person
state: "off"
for: "00:02:00"
enabled: true
- condition: state
entity_id: binary_sensor.doorbell_visitor
state: "off"
for: "00:02:00"
enabled: true
actions:
- if:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-00:15:00"
- condition: sun
before: sunrise
before_offset: "00:15:00"
then:
- action: light.turn_on
metadata: {}
data:
brightness_pct: 100
target:
entity_id:
- light.porch_2
- light.porch_led
- wait_for_trigger:
- entity_id:
- binary_sensor.doorbell_person
- binary_sensor.doorbell_visitor
to: "off"
for: "00:05:00"
trigger: state
- target:
entity_id:
- light.porch
- light.porch_led
action: light.turn_off
data: {}
alias: Turn on the porch lights if dark
- alias: Set snapshot filename
action: input_text.set_value
metadata: {}
data:
value: doorbell_{{ now().strftime('%d%m%Y_%H%M%S') }}.jpg
target:
entity_id: input_text.doorbell_snapshot
- alias: Take a snapshot
data:
filename: >-
/config/www/images/front_door/{{
(states("input_text.doorbell_snapshot")) }}
action: camera.snapshot
target:
entity_id: camera.doorbell_fluent
- metadata: {}
data:
announcement: Someone is at the front door
alias: Announce that someone is at the front door
action: script.play_an_announcement_speaker_selection
- delay: "00:00:02"
- data:
title: Front Door Alert
message: Someone is at the front door.
data:
attachment:
content-type: jpeg
url: >-
/local/images/front_door/{{ (states("input_text.doorbell_snapshot"))
}}
action: notify.mobile_app_steves_iphone
alias: Send a notification to Steve's phone
- alias: Turn off the porch lights if dark and they are on
if:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-00:15:00"
- condition: sun
before: sunrise
before_offset: "00:15:00"
- condition: state
entity_id: light.porch_2
state: "on"
- condition: state
entity_id: light.porch_led
state: "on"
then:
- wait_for_trigger:
- entity_id:
- binary_sensor.doorbell_person
- binary_sensor.doorbell_visitor
to: "off"
for: "00:05:00"
trigger: state
timeout:
hours: 0
minutes: 5
seconds: 30
milliseconds: 0
alias: Wait until the doorbell goes clear for 5 minutes
- target:
entity_id:
- light.porch
- light.porch_led
action: light.turn_off
data: {}
- action: shell_command.purge_doorbell_snapshots
metadata: {}
data: {}
alias: Purge old snapshots (> 1 week)
mode: single
The only issue I am having is that I don’t see an image when I click on the notification on my iPhone. I can see an image on my apple watch and when the notification is received but when I click on it, the home assistant app opens but no image is presented. Is there something I am overlooking?
I had the same issue, I couldn’t get the variables to work in an automation, that’s why I moved them to the script.
Using filename: /config/www/tmp/snapshot_uvc_front_door_{{ timestamp }}.jpg Created snapshot_uvc_front_door_.jpg
I do see your URL is double quoted vs single, not sure if that matters: