-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCameraSnapshotWhenMotion.yml
128 lines (126 loc) · 4.11 KB
/
CameraSnapshotWhenMotion.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#
# Home Assistant Automation Blueprint
#
# Send Snapshot when Motion Detected, and Turn on Lights
#
# Revision 1.0
# Modified by Johan Schelin, Mar. 2021
#
# TODO IN COMING VERSIONS
# - ADD MULTIPLE CAMERAS IN THE SAME SCRIPT
blueprint:
name: Send a camera snapshot when motion is detected, and trigger script
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_device1:
name: Device to notify
description: Device needs to run the official Home Assistant app to receive
notifications
selector:
device:
integration: mobile_app
notify_device2:
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!'
script:
name: Script to run
description: Select a script to run for actions, like turning on a light
selector:
entity:
domain: script
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://github.com/johanschelin/ha_blueprints/blob/main/CameraSnapshotWhenMotion.yml
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_device1: !input 'notify_device1'
notify_device2: !input 'notify_device2'
is_ios: !input 'is_ios'
notification_title: !input 'notification_title'
notification_message: !input 'notification_message'
delay: !input 'delay'
script: !input 'script'
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'')
}}'
condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.huset
state: armed_away
- condition: state
entity_id: alarm_control_panel.huset
state: armed_home
action:
- delay: '{{ delay }}'
- service: camera.snapshot
entity_id: !input 'camera'
data:
filename: '{{ snapshot_create_file_path }}'
- device_id: !input 'notify_device1'
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 }}'
- device_id: !input 'notify_device2'
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 }}'
- service: !input 'script'