📸 Send camera snapshot notification on motion

Tags: #<Tag:0x00007f326db8f280>

This blueprint will send a snapshot from a camera to your phone when motion is detected.

Blueprint

Blueprint, which you can import by using this forum topic URL:

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:
    motion_sensor:
      name: Motion 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: "{{ 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
            max: 60
            unit_of_measurement: seconds
            mode: slider

trigger:
  platform: state
  entity_id: !input motion_sensor
  from: "off"
  to: "on"

variables:
  motion_sensor: !input motion_sensor
  motion_sensor_name: "{{ states[motion_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 }}
27 Likes

I get the following error when trying to import:
while scanning an anchor in “”, line 3, column 16: description: > ^ expected alphabetic or numeric character, but found ‘;’ in “”, line 3, column 19: description: > ^

1 Like

This is interesting. I can import it without any issues.
Are you using the latest beta?
This URL works for me: https://community.home-assistant.io/t/send-camera-snapshot-notification-on-motion/254565

Ah no, let me update. But I did import another blueprint tho

Update fixed it thanks

1 Like

Nice workaround for the inconsistency in Android / iOS mobile app notifications, really clever idea!

There’s a problem with line 80, you have a hardcoded camera.demo_camera entity id that was probably mistakenly left over from when you were testing. It should be entity_id: !input camera

2 Likes

Thank you very much!
I don’t have an iOS device, so I couldn’t test it, but according to the documentation it should work :slightly_smiling_face::crossed_fingers:
I did left the camera.demo_camera there accidentally. Now it’s fixed. Thank you again.

1 Like

It would be nice to specify the save path on the snapshot. I currently do this but I store it in the /media/folder/last_motion.jpg so you can use the media viewer. I also store it in a secondary archive folder so you have history (/media/folder/archive/%date%.jpg) but that seems like a different blueprint.

2 Likes

Sadly, I couldn’t select any of my Aeotec motion sensors. They are not binary_sensors, but rather sensors sending a 0, 3, or 8 for no motion, Accel, and Motion respectively.

You could create a template sensor to make it report 1 if the value is different from 0 and then use that sensor in the blueprint

Would this also work for a button? I would like to hook my doorbell to send a snapshot.

Trying to find the best way to do this.

You could edit the blueprint and change the “motion_sensor” part to make it point to a binary sensor or whatever your doorbell shows up as, everything else should be the same if you have a camera device to get the snapshot from

Just remove line 14 (device_class: motion) and it might just work

Thank you for this!

1 Like

Thanks, this indeed showed my button. Unfortunately this doesn’t make the template work. Because my button is changing from ‘off’ to ‘Single’ or ‘Double’ I think it needs an ‘On’ or ‘Off’ at least with a motion sensor it works. But with the button it does not.

I guess your button isn’t a binary_sensor then

You could create a template_sensor for it and that would fix it

Quick mockup:

sensor
  - platform: template
    sensors:
      someone_at_the_door:
        value_template: >
          {% if (is_state('switch.yourbuttonhere', 'single') or is_state('switch.yourbuttonhere', 'double'))  %}
            on
          {% else %}
            off
          {% endif %}

Thank you, I’ve made the template sensor. But I just checked and the Xiaomi states never change. The state is always ‘Off’ . It does however give this :

last_action: double
voltage: 3.02
battery_level: 45
friendly_name: Boven 1

Thanks for all the help already, but it seems I have to dive in a little more. Just started with Home Assistant and getting to understand automations better is something I will try to figure out more during the holidays.

I see the problem, your “single” or “double” value isn’t the status but an attribute
Replace is_state('switch.yourbuttonhere', 'single') with is_state_attr('switch.yourbuttonhere','last_action','single') and do the same for double, it should work the

Also you can test that part in HA by click Developer Tools and then Template, you can paste the value_template part in there and see if it returns what you’re expecting

Waw love this blueprint. (Or is it perhaps blueprint on general that I like???)
Anyway thanks for this one
Some changes I have made to in in my version :
-other devices as trigger - Nest doorbell button push worls sweet
-ios critical alert : so it works even when my phone is silent (which it is 99% of the time - the wonders world of the watch :slight_smile: )
Any way I can contribute to your without polluting the blueprint market woth simular blueprints

2 Likes

can you add a condition? for example i have an input Boolean if the house is in away mode. can you add a condition if i am away send snapshot if motion.

2 Likes

I like this idea, but I think it is a different blueprint. I wanted to keep this simple, and not fill the user’s SD cards with the snapshots, so that is why I rejected my first idea to include the date in the file name. I choose to save the snapshots to the www folder, because it does not require additional configuration. (media_dirs needs to be set up beforehand)