Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mcinnes01/921cbb14efc9c5c7a933beb903603f8c to your computer and use it in GitHub Desktop.
Save mcinnes01/921cbb14efc9c5c7a933beb903603f8c to your computer and use it in GitHub Desktop.
Send a camera snapshot when motion event type is detected
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
override_sensor:
name: Override sensor
description: Binary sensor to override detection
selector:
entity:
domain: binary_sensor
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.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: and
conditions:
- condition: state
entity_id: !input 'override_sensor'
state: off
- 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'
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 }}'
@j2chulo
Copy link

j2chulo commented Apr 3, 2023

I am getting error when trying to save it. Message malformed: expected str for dictionary value @ data['condition'][0]['conditions'][0]['state']
using my ring doorbell motion detected

@Saulus92
Copy link

Saulus92 commented May 21, 2023

Blueprint works fine as long as the app sees my phone in the home network, as soon as im no longer in the internal connection URL i recieve a outdated picture.
In the filepath i cant find the outdated .jpg as like the file in the notification would be from the phone disk.
I run home assistant on Proxmox as VM, probably the filepath should be changed from
'{{ snapshot_create_file_path | replace(''/config/www'',''/local'') }}'
the an appropriate path. Any recomandations? Help would be appreciated, thanks.

@adirburke
Copy link

I had to update line 78 with "off" for it to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment