📸 Send camera snapshot notification on motion

This is awesome but I can’t import it for some reason.

mapping values are not allowed here in "<unicode string>", line 76, column 15: conditions: ^

Tweaked it a bit for my own needs with unifi protect integration so I can notify via html5 on my desktop(s). This uses the unifi api url from the camera so it doesn’t need to store a temporary photo.

blueprint:
  name: Send a camera snapshot when motion event type is detected
  description: 'This automation blueprint creates a camera snapshot if general motion or a specific motion event object is detected  and
    sends a notification to your phone with the picture.'
  domain: automation
  input:
    motion_sensor:
      name: Motion sensor
      description: The sensor which triggers the snapshot creation
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    event_object:
      name: Event detection type
      description: Type of object to detect from a motion event
      default: None Identified
      selector:
        select:
          options:
            - None Identified
            - person
            - car
    camera:
      name: Camera
      description: The camera which creates the snapshot
      selector:
        entity:
          domain: camera
    notify_device:
      name: Device to notify
      description: Service used for notifications eg. notify.html5_device_name
      selector:
        text:
    notification_title:
      name: Notification title (Optional)
      description: 'Default: "Motion detected!"'
      default: Motion detected!
    notification_message:
      name: Notification message (Optional)
      description: 'Default: "{{ motion_sensor_name }} detected movement!"'
      default: '{{ motion_sensor_name }} detected movement!'
    delay:
      name: Delay (Optional)
      description: Wait before creating camera snapshot
      default: ''
      selector:
        number:
          min: 0.0
          max: 60.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
  source_url: https://community.home-assistant.io/t/send-camera-snapshot-notification-on-motion/254565
trigger:
  platform: state
  entity_id: !input 'motion_sensor'
  from: 'off'
  to: 'on'
condition:
  - condition: state
    entity_id: !input 'motion_sensor'
    attribute: event_object
    state: !input event_object
variables:
  motion_sensor: !input 'motion_sensor'
  motion_sensor_name: '{{ states[motion_sensor].name }}'
  camera: !input 'camera'
  snapshot_url: '{{ states[camera].attributes.entity_picture}}'
  notify_device: !input 'notify_device'
  notification_title: !input 'notification_title'
  notification_message: !input 'notification_message'
  delay: !input 'delay'
action:
- delay: '{{ delay }}'
- service: '{{ notify_device }}'
  data:
    message: '{{ notification_message }}'
    title: '{{ notification_title }}'
    data:
      tag: alert 
      image: '{{ snapshot_url }}'
      url: '{{ snapshot_url }}'
1 Like

Hi, did you solve this issue? I got the same error

Hi All,

I managed to get it to work (I get the snapshot).
The only issue I have is that the “delay” portion doesn’t work.
I get an error message in the homeassistant.log:
“ERROR (MainThread) [homeassistant.components.homeassistant.triggers.state] Error rendering ‘New Automation’ for template: offset off should be format ‘HH:MM’, ‘HH:MM:SS’ or ‘HH:MM:SS.F’”

I tried to replace the 0.0 to 00:00:00 (in the blueprint yaml file) but no luck.

Any suggestions?

Thanks!

Same error for me. I wish to have zero delay. “… camera snapshot when motion is detected: Error rendering … camera snapshot when motion is detected delay template: offset should be format ‘HH:MM’, ‘HH:MM:SS’ or ‘HH:MM:SS.F’”

Any easy way to put a denounce in the motion trigger? Love this blueprint, just get a lot of notifications.

I solved putting to “1” the value in the Delay slider.
Hope it helps.
SoL

3 Likes

Hi Vorion, Hi everyone,
the BP works nicely, thank you for your work.
I’m running HA Version core-2021.4.6, Home Assistant OS on Proxmox VM.
Sensors and notifications work fine, but I wanted to save the snapshots in media folder (/media/snapshots), so I changed the .yaml into:

snapshot_create_file_path: /media/snapshots/snapshot_{{ states[camera].object_id }}.jpg
snapshot_access_file_path: ‘{{ snapshot_create_file_path | replace(’’/media/snapshots’’,’’/local’’) }}’

The ‘snapshot_create_file_path’ is correct, it saves the picture files in /media/snapshots and I can open the images in HA media browser.
The ‘snapshot_access_file_path’ is NOT correct (I tried different solutions, this is just one of those), I receive correctly the notification but WITHOUT the screenshot.
Can you help in defining ‘snapshot_access_file_path’?
Thank you
SoL

1 Like

Hi.
I just approached blueprints, this is the first one I’m tryng.
I also would need a condition based on a selectable input_boolean.
How can I add it?
Thanks.

In case it helps any other relatively new users to Home Assistant like me - After I added this blueprint and created the automation, I had to restart Core before I was able to access the camera snapshot URL. Until I restarted Core, I was getting a 404 error for the snapshot URL.

Thanks for sharing.

If we want to add more possible entities as a trigger to take the snapshot and send the notification, then should be like this:

(In my case doesn’t work. It happens the same, only motion sensors are available to select within drop-down entity list. What am I doing wrong? - Thanks )

blueprint:
  name: Send a camera snapshot when motion is detected
  description: 'This automation blueprint creates a camera snapshot if motion is detected  and
    sends a notification to your phone with the picture.

    '
  domain: automation
  input:
    binary_sensor:
      name: Binary sensor
      description: The sensor wich triggers the snapshot creation
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    camera:
      name: Camera
      description: The camera which creates the snapshot
      selector:
        entity:
          domain: camera
    notify_device:
      name: Device to notify
      description: Device needs to run the official Home Assistant app to receive
        notifications
      selector:
        device:
          integration: mobile_app
    is_ios:
      name: Is it an iOS device?
      description: Toggle if your selected device runs iOS, default is Android
      selector:
        boolean: {}
      default: false
    notification_title:
      name: Notification title (Optional)
      description: 'Default: "Motion detected!"'
      default: Motion detected!
    notification_message:
      name: Notification message (Optional)
      description: 'Default: "{{ binary_sensor_name }} detected movement!"'
      default: '{{ binary_sensor_name }} detected movement!'
    delay:
      name: Delay (Optional)
      description: Wait before creating camera snapshot
      default: ''
      selector:
        number:
          min: 0.0
          max: 60.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
  source_url: https://community.home-assistant.io/t/send-camera-snapshot-notification-on-motion/254565
trigger:
  platform: state
  entity_id: !input 'binary_sensor'
  from: 'off'
  to: 'on'
variables:
  binary_sensor: !input 'binary_sensor'
  binary_sensor_name: '{{ states[binary_sensor].name }}'
  camera: !input 'camera'
  notify_device: !input 'notify_device'
  is_ios: !input 'is_ios'
  notification_title: !input 'notification_title'
  notification_message: !input 'notification_message'
  delay: !input 'delay'
  snapshot_create_file_path: /config/www/tmp/snapshot_{{ states[camera].object_id
    }}.jpg
  snapshot_access_file_path: '{{ snapshot_create_file_path | replace(''/config/www'',''/local'')
    }}'
action:
- delay: '{{ delay }}'
- service: camera.snapshot
  entity_id: !input 'camera'
  data:
    filename: '{{ snapshot_create_file_path }}'
- device_id: !input 'notify_device'
  domain: mobile_app
  type: notify
  title: '{{ notification_title }}'
  message: '{{ notification_message }}'
  data: '{% set android_data = {"image": "%s"} | format(snapshot_access_file_path)
    %} {% set ios_data = {"attachment": {"url": "%s", "content_type": "JPEG"}} | format(snapshot_access_file_path)
    %} {{ ios_data if is_ios else android_data }}'

would there be a way to set a timer in between notifications? id like one when my kid goes outside, but not every 2 seconds like im getting now because it’s still seeing movement

Hi.

Is there a way to edit this blueprint, so you can use persistent.create ?

1 Like

I’m trying to do the same, did you find any solution?

1 Like

How can I modify the blueprint to save all the snapshots without rewriting the old ones?

In the BP i added date and time to the file name. Maybe that helps.

snapshot_create_file_path: /home/homeassistant/.homeassistant/www/tmp/snapshot_{{ states[camera].object_id }}_{{ now().strftime("%d-%m-%Y_%H-%M-%S") }}.jpg
1 Like

and to prevent file flood after x time. i have delete custom integration scheduled for house keeping

alias: Delete camera shots na 24 uur
description: ''
trigger:
  - platform: time
    at: '01:00'
condition: []
action:
  - service: delete.files_in_folder
    data:
      folder: /config/www/shots
      time: 604800
mode: single
1 Like

Dont think it work like that. The ‘local’ in URL that is exposed from webserver is mapped to www directory. So just placing snaps outside www dir, make it unaccessible through /local.
what is your need to have it in media dir?

In (Home assistant core) configuration.yaml i created a shell_command to delete old snapshots. Everyday on midnight i call this shell_command in a automation to delete snapshots older then 1 day.

configuration.yaml

shell_command:
  delete_old_snapshots: "find /home/homeassistant/.homeassistant/www/tmp/* -type f -mmin +1440 -name snapshot* -exec rm {} -f \\;"

automations.yaml

  alias: Verwijder oude snapshots.
  description: ''
  trigger:
  - platform: time
    at: 0:00
  condition: []
  action:
  - service: shell_command.delete_old_snapshots
  mode: single
1 Like

Hi this works great, but is there any way to send to telegram (I have telegram notify set up and working in ha already). The reason being if I happen to click on the notification it just goes away and I can’t see the picture again. If it sent to my telegram ha bot I would’ve had a history of snapshots.

1 Like