Requires a camera and two binary sensors for person and vehicle detection. Will send a notification to the selected device that has the Home Assistant app installed and that notification will include a snapshot from the camera at the time of detection. You may need to add the folder ‘doorbell’ to your ‘www’ folder for the snapshots to be stored.
Optionally you can configure a timeout between notifications to avoid spamming. And you can optionally set a binary sensor to prevent notifications while at home, asleep or whatever.
Updated: Added option for specifying the directory for storing the camera snapshot
Updated (2023/01/15): Fixed issue with notification device name containing spaces
Updates (2024/04/06): Made vehicle sensor optional and added an optional pet sensor
blueprint:
name: Camera Detection
description: ''
domain: automation
input:
notify_device:
name: Device to notify
description: Device needs to run the official Home Assistant app to receive
notifications
selector:
device:
integration: mobile_app
camera:
name: Camera
description: Camera for which this detection is running
selector:
entity:
domain: camera
person_sensor:
name: Person detection sensor
description: Binary sensor which is on when a person is detected
selector:
entity:
domain: binary_sensor
vehicle_sensor:
name: (OPTIONAL) Vehicle detection sensor
description: Binary sensor which is on when a vehicle is detected
default:
selector:
entity:
domain: binary_sensor
pet_sensor:
name: (OPTIONAL) Pet detection sensor
description: Binary sensor which is on when a pet is detected
default:
selector:
entity:
domain: binary_sensor
store_location:
name: Folder to store snapshots in
description: Folder within your www folder where snapshots should be stored. Do not include www directory.
default: 'doorbell'
selector:
text:
no_motion_wait:
name: Time between notifications (seconds)
description: Time in seconds to wait before sending another notification of motion (to avoid spamming).
default: 0
selector:
number:
min: 0
max: 300
unit_of_measurement: seconds
blocker_entity:
name: (OPTIONAL) Blocking entity
description: If this entity's state is on, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity:
domain: binary_sensor
source_url: https://github.com/apollo1220/blueprints/blob/main/camera_detection_notification.yaml
mode: single
max_exceeded: silent
variables:
notify_device: !input 'notify_device'
camera: !input 'camera'
blocker_entity: !input 'blocker_entity'
no_motion_wait: !input 'no_motion_wait'
store_location: !input 'store_location'
trigger_variables:
vehicle_sensor: !input 'vehicle_sensor'
pet_sensor: !input 'pet_sensor'
trigger:
- platform: state
entity_id: !input 'person_sensor'
from: 'off'
to: 'on'
id: 'person'
- platform: template
value_template: "{{ is_state ( vehicle_sensor , 'on' ) }}"
id: 'vehicle'
- platform: template
value_template: "{{ is_state ( pet_sensor , 'on' ) }}"
id: 'pet'
condition:
- condition: template
value_template: '{{ (blocker_entity == none) or (states[blocker_entity].state == ''off'') }}'
action:
- service: camera.snapshot
data:
filename: /config/www/{{store_location}}/{{ trigger.to_state.last_changed | as_timestamp | timestamp_custom("%Y-%m-%d_%H-%M-%S") }}.jpg
target:
entity_id: !input 'camera'
- service: notify.mobile_app_{{ device_attr(notify_device, 'name').lower() |regex_replace(find=' ', replace='_', ignorecase=False) }}
data:
title: Camera Detection
message: "{{ state_attr(camera, 'friendly_name') }} has detected a {{trigger.id}}"
data:
image: /local/{{store_location}}/{{ trigger.to_state.last_changed | as_timestamp | timestamp_custom("%Y-%m-%d_%H-%M-%S") }}.jpg
channel: Motion
importance: high
ttl: 0
priority: high
notification_icon: mdi:cctv
- condition: template
value_template: '{{ no_motion_wait != none }}'
- delay:
seconds: '{{ no_motion_wait | int }}'
Yeah because of how bp’s work I have to generate the service name based on the mobile device. Looks like there is a character I’m not accounting for. Could you post what the correct service name looks like and I’ll fix this.
Can’t notify a group due to how I’m even figuring out the service to call in the first place at least with how it is currently configured. Maybe it would make sense to just have a text string that can be configured and use that for the service to call as then it wouldn’t need to depend on having character conversions as well.
Camera Detect: Error executing script. Error for call_service at pos 1: Cannot write /config/www/media/2024-02-18_14-15-31.jpg, no access to path; allowlist_external_dirs may need to be adjusted in configuration.yaml
How does this work?
I have been struggeling for hours trying to get this to work, but no matter what the automation seems not to be able to write the images to the folder i set it too.
I’ve tried adding your automation to be used with a Tapo C310, but I get no notification (running the automation manually ends up the same way) at all on my mobile.
Device looks correct so maybe the sensor is not working somehow?
Automation:
alias: Persona rilevata
description: Rilevamento persone Tapo C310 (Avanti)
use_blueprint:
path: apollo1220/camera_detection_notification.yaml
input:
notify_device: 573babd5445619779f6e7cc282a8b0e9
camera: camera.tapo_c310_avanti_hd_stream
person_sensor: select.tapo_c310_avanti_person_detection
store_location: avanti
no_motion_wait: 10
Thanks for the blueprint. I had it working for about the last year, but recently had to rebuild my HA and reinstall everything (long story). I’m getting the notification, but with a 404, ‘Failed to load attachment’ in place of the image. The jpg IS located in the www folder in the appropriate subdirectory. Nothing in the logs. Any ideas?
Thank you for this script. I use it with my Reolink caméras and it works well.
On my side, I was wondering if it would be possible to chose 2 or more devices to notify ?
This is very cool, thanks! I am experimenting with a clickAction to bring me directly to a lovelace view with the snapshot and the livefeed, not sure if it will work yet, would love to hear thoughts
That should be pretty straightforward with directing to a particular Lovelace page. The difficulty is going to be having the snapshot displayed on the page. Maybe you can setup the page to show the “most recent” snapshot, but that wouldn’t necessarily always be the one from the notification you interacted with.
Hi.
Can I choose a longer wait time than 300 seconds?
Why can’t I choose a persons state to the blocking entity?
Would be nice to block automation when I’m home so if I pop outside I won’t receive notifications of myself.
Besides those this works perfect.