Last active
May 15, 2021 19:11
-
-
Save emericklaw/4386e797daf5ee0f4381cb30ceb31a65 to your computer and use it in GitHub Desktop.
Send camera snapshot notification on motion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_blocker: | |
| name: Notification Blocker (Optional) | |
| description: Only send notification if this boolean is in desired state (see next input) | |
| default: | |
| selector: | |
| entity: {} | |
| notification_blocker_boolean: | |
| name: Notification Blocker Chooser (Optional) | |
| description: Desired state of notification blocker, choose on for True and off for False | |
| default: false | |
| selector: | |
| boolean: {} | |
| 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!" | |
| notification_url: | |
| name: Notification URL | |
| description: 'Default: "/"' | |
| default: / | |
| 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://gist.github.com/emericklaw/4386e797daf5ee0f4381cb30ceb31a65 | |
| 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_blocker: !input "notification_blocker" | |
| notification_blocker_boolean: !input "notification_blocker_boolean" | |
| notification_title: !input "notification_title" | |
| notification_message: !input "notification_message" | |
| notification_url: !input "notification_url" | |
| 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') | |
| }}" | |
| condition: | |
| - condition: or | |
| conditions: | |
| - "{{ notification_blocker == none }}" | |
| - "{{ notification_blocker_boolean and states[notification_blocker].state == 'True' }}" | |
| - "{{ not notification_blocker_boolean and states[notification_blocker].state == 'False' }}" | |
| 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", "clickAction": "%s", "entity_id": "%s"} | format(snapshot_access_file_path, notification_url, camera) %} | |
| {% set ios_data = {"attachment": {"url": "%s", "content_type": "JPEG", }, "url": "%s", "entity_id": "%s"} | format(snapshot_access_file_path, notification_url, camera) %} | |
| {{ ios_data if is_ios else android_data }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment