Camera Detection Notification with image

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.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

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 }}'
2 Likes

Hello,
I have an issue when i try to use this bp

Do you know what could be the problem ?

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.

Hi, thank you for this blueprint.
Wondering if there is any way to notify a group instead of a device?

Hi, looks having a bug due to my device name.
Therefore the notification is not sent.

“Error: Template rendered invalid service: notify.mobile_app_galaxy_s22_kaï”

The special character “ï” is normally automatically changed to a standard “i” to get:
notify.mobile_app_galaxy_s22_kai

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.

I’m not a Blueprint expert (far to be :sweat_smile:) but isnt possoble to add some if conditions in?

Let say, having a boolean to set if it’s a device or a group.

And then somthing like (don’t know if such things works in blueprints):

  • service: >-
    {% if boolean=‘on’ %}
    notify.{{notify_device}}
    {% else %}
    notify.mobile_app_{{device_attr(notify_device,‘name’).lower()|regex_replace(find=‘’,replace=‘_’,ignorecase=False) }}
    {% endif%}

Is it possible to remove the vehicle_sensor? I won’t use it in my case.

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.

Any idea what might be the issue?

Have you created the directory beforehand?

I do actually need to do that for one of my cameras as well. I’ll try to do that this week.

I’ve made the vehicle sensor optional and I added another optional sensor for pet detection