šŸ“ø Send camera snapshot notification on motion

This blueprint ia awsome!
However, has anyone manage to use a condition in any way?
Iā€™d like to use the automation only in case Iā€™m not home!
Thank you so much!

Send camera snapshot and camera record to telegram using configured telegram bot:

Blueprint
blueprint:
  name: Send a camera snapshot to telegram when motion is detected
  description: 'This automation blueprint creates a camera snapshot if motion is detected  and
    sends a notification via preconfigured Telegram bot 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
          multiple: false
    camera:
      name: Camera
      description: The camera which creates the snapshot
      selector:
        entity:
          domain: camera
          multiple: false
    notification_title:
      name: Notification title (Optional)
      description: 'Default: "{{ motion_sensor_name }} detected movement!"'
      default: '{{ motion_sensor_name }} detected movement!'
  source_url: https://community.home-assistant.io/t/send-camera-snapshot-notification-on-motion/254565
trigger:
  platform: state
  entity_id: !input motion_sensor
  to: 'on'
variables:
  motion_sensor: !input motion_sensor
  motion_sensor_name: '{{ states[motion_sensor].name }}'
  camera: !input camera
  notification_title: !input notification_title
  snapshot_file_name: >-
    {{ now().strftime("%Y%m%d-%H%M%S") }}
  snapshot_create_file_path: >-
    /media/snapshots/{{ states[camera].object_id }}_{{ snapshot_file_name }}.jpg
  record_create_file_path: >-
    /media/records/{{ states[camera].object_id }}_{{ snapshot_file_name }}.mp4
action:
- service: camera.snapshot
  target:
    entity_id: !input camera
  data:
    filename: '{{ snapshot_create_file_path }}'
- service: telegram_bot.send_photo
  data:
    parse_mode: html
    file: '{{ snapshot_create_file_path }}'
    caption: '{{ notification_title }}'
- repeat:
    while:
      - condition: state
        entity_id: !input camera
        state: unavailable
        for:
          hours: 0
          minutes: 0
          seconds: 10
    sequence:
      - delay: '00:00:01'
- service: camera.record
  target:
    entity_id: !input camera
  data:
    duration: 15
    filename: '{{ record_create_file_path }}'
- service: telegram_bot.send_video
  data:
    parse_mode: html
    file: '{{ record_create_file_path }}'
    caption: '{{ notification_title }}'

1 Like

Thanks for the blueprint!
Iā€™m new to blueprints in general and would like to know if thereā€™s a way to edit it so that i can comment out the vehicle sensor requirement?

Also, could someone suggest an automation to remove the saved images on a regular basis?

thanks!

evening, this doesnā€™t work for me. when i push on the alert, Google asks if i want to silent the notifications permanently. it never opens up the snapshot.

maybe iā€™m doing something else wrongā€¦?

Hey @0la1, @usaf_pride, chillhahn,

Not sure if you all figured this out, but I have managed to find a workaround for sending the notification to multiple devices.

You first need to create the notify: group with your devices, then edit the blueprint at

/config/blueprints/automation/vorion/send-camera-snapshot-notification-on-motion.yaml

comment out the notify_device input section

#    notify_device:
#      name: Device to notify
#      description: Device needs to run the official Home Assistant app to receive
#        notifications
#      selector:
#        action:
#          device:
#          integration: mobile_app

then comment out the notify_device variables section

#  notify_device: !input 'notify_device'

and then lastly in the action section at the bottom of the blueprint file, edit as below:

#  - device_id: !input 'notify_device'
#    domain: mobile_app
#    type: notify
#    title: '{{ notification_title }}'
#    message: '{{ notification_message }}'
  - service: notify.all_phones
    data:
      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 }}'

note I have called my notify group ā€˜all_phonesā€™. So change that to suit your naming. If you are feeling confident you could go back and delete all the commented out lines to clean the blueprint up.

Iā€™m sure there must be another way to do this but Iā€™ve not been able to figure it out

Donā€™t know if Iā€™m the only one that noticed, thereā€™s a pretty big concern of privacy in using this blueprint as is.
It stores the screenshot in the www folder, thatā€™s accessible (by design) and not covered by HA authentication. For me itā€™s a pretty big deal as I live in a flat and have my security cameras inside the house, so anyone that has my HA link to that file can access it and privacy is gone.
I guess one step in the right direction is to create a random string of text as a folder to put the files in, so itā€™s harder to brute force the link.

First requirement is to have access to your network, I hope itā€™s not accessible by everyone in your flat, not your cameraā€™s, not your HA.
The same goes for receiving these snapshots: anyone that receives them has access to your network anyway.

Thank you for such a great blueprint!..it save me a lot of work!..

ā€¦now I facing ā€œhow to access the pictures from outside you networkā€¦ā€, I know, I know, it was already discuss on the thread, but I read all those old comments and I donā€™t have a clear idea of what to check or what need to be done differently with the current state of the bleuprintā€¦so sorry if is repeated, just point me in the right directionā€¦

So, notifications are working and I can get the pictures as part of the message in all devices in my networkā€¦from outside I only get the notification without the snapshot attachedā€¦

Reading the thread I try to add:
homeassistant:
allowlist_external_dirs: /config/www/tmp #also try with /config/www

I change the integration code to save snapshots inside www instead www/tmp ā€¦and I check the picture was actually thereā€¦reboot everything several times, but still no pictures from outside my networkā€¦

What Iā€™m missing?..I know there are concerns about security but I want to make it work first and fix that later, so any suggestion will be wellcomeā€¦

can be realted to how I access HA remotely?, I use cloudflare so my url is something like https://mycloudflareurl.tk/lovelace/default_view , so as a test, should the image be accesible doing something like:

wget https://mycloudflareurl.tk/snapshot_camerasomething.jpg

? ( assuming picture is stored in www folder) ā€¦if so, the is not accesible like that and no idea how to enable something like that with cloudflareā€¦

What Iā€™m missing or missreading?

Thanks!

Home Assistant 2023.8.1
Supervisor 2023.08.1
Frontend 20230802.0 - latest

ā€¦btw, I note that when I click in the saved snapshot inside www/tmp I get a long weird url for the image
http://localip:8123/api/hassio_ingress/tIYmL62o23vA6NLEFBuDRrPpW_IV5IoAvRU28wi1Quw/api/file?filename=/config/www/tmp/snapshot_backyard_2.jpg

Iā€™m talking about outside-access. Iā€™m using a cloudflare tunnel so nothing of my network is exposed directly, so no, itā€™s not accessible by anyone if not the people with passwords, and yes, the www folder via the correct link is visible from outside, so yes, itā€™s a privacy problem especially for security camera snapshots (i donā€™t mind having for example a wifi qr code for the guest wifi, which is obviously separated from the main one)

First of all, thank you for such a great blueprint.

I have a very strange behaviour. At first glance it was kind of working fine but afterwards I realize that itā€™s serving me always the first snapshot. When I check under www/tmp, I saw the snapshot and is being updated each time I run the automatization but the picture I see at https://my.home.assistant/local/tmp/snapshot.jpg is the very first one that was taken. I have even removed the file from tmp folder, tried in private tab of different internet browsers, etcā€¦ No matter what I do, I keep seeing the very first snapshot. Some kind of strange cache issue? Anyone has faced this?

I have found the solution on the issue in my previous post.

The problem was cloudflare caching. Enabling ā€œDevelopment Modeā€ helpedā€¦

2 Likes

Cloudflareā€™s developer mode is only active for 4 hours. After that you have the same problem again. Is there another solution for this?

Edit:

I have now solved it like this:
I add date, hour and minute to the filename:

  • service: camera.snapshot
    data:
    filename: /config/www/tmp/Terrasse_{{ now().strftime(ā€œ%Y%m%d-%H%Mā€) }}.jpg
    target:
    entity_id: camera.terrasse

And specify the same in the notification:

  • service: notify.mobile_app_
    data:
    data:
    image: >-
    https://XXXX/local/tmp/Terrasse_{{ now().strftime(ā€œ%Y%m%d-%H%Mā€)
    }}.jpg
    entity_id: camera.terrasse

so that a new file is created each time and the current one is sent.

Iā€™m having this exact problem on my Android. Did you ever figure it out? I see an old picture in that www folder and thatā€™s the one I keep receiving on the phoneā€¦

Hello, how could I set it to capture using the cameraā€™s own motion sensor?

1 Like

two problems here

image is late in agent dvr if you see the notification i can see the person but in ha image the person has already gone out of the view.

android phones all Samsung note series receiving notification late. yeah battery optimization for HA is off

cant i send from webhook image and then this module can process it
so far i send from actions in agent dvr to ha and in automation ha gets grab0.jpg i think but i am not able to go further what to do with it

hi, is it possible to have the formatted code or better yet a blueprint of this solution. sorry but i am at the beginning

hi, is it possible to have the formatted code or better yet a blueprint of this solution. sorry but i am at the beginning

This is quite cool, however did not come out very useful for me. The phone sends a partial screenshot in the push where I canā€™t see all of the picture, and when I click it Home Assistant opens, Screenshot is gone, canā€™t find it anywhereā€¦

I just used the blueprint and when I trace the automation it does not run, but give the following error.

Executed: November 7, 2023 at 5:30:25 PM

Error: offset should be format ā€˜HH:MMā€™, ā€˜HH:MM:SSā€™ or ā€˜HH:MM:SS.Fā€™