Skip to content

Instantly share code, notes, and snippets.

@wes1993
Last active July 26, 2024 13:25
Show Gist options
  • Save wes1993/00ae2ca29a117964fee338f4e8a24b04 to your computer and use it in GitHub Desktop.
Save wes1993/00ae2ca29a117964fee338f4e8a24b04 to your computer and use it in GitHub Desktop.
Camera - Send Camera snapshot from entity image or camera strea with custom triggers and with Conditions
blueprint:
name: Camera - Send Camera snapshot from entity image or camera strea with custom triggers and with Conditions
description: This automation blueprint creates a camera snapshot if motion is detected,or if a binary sensor's state turns 'off' to 'on', and sends a notification to your phone with the picture. Clicking the notification will navigate to dashboard URL. Based ON :[More Info](https://community.home-assistant.io/t/camera-send-save-snapshot-to-mobile-device-when-motion-is-detected-with-conditions/604156) (v2.2.6) [Automation]
author: TheFalseReality&Wes93
homeassistant:
min_version: 2024.6.0
domain: automation
source_url: https://gist.github.com/wes1993/00ae2ca29a117964fee338f4e8a24b04
input:
trigger_additional:
name: Trigger(s)
description: Add triggers
default: []
selector:
trigger: {}
camera:
name: Camera
description: The camera which creates the snapshot
default: []
selector:
entity:
domain:
- camera
multiple: false
delay:
name: Snapshot Delay
description: Wait before creating camera snapshot.
default:
seconds: 1
selector:
duration: {}
image_entity:
name: Image
description: The Entity Image
default: []
selector:
entity:
domain:
- image
multiple: false
ha_hostname:
name: Insert HA Public Hostname
description: 'EX: "https://dummy.duckdns.org"'
default: https://dummy.duckdns.org
its_camera_entity:
name: Is Camera Entity?
description: When enabled, the camera entity will be used instead of image entity with snapshot
default: False
selector:
boolean: {}
condition:
name: Add Condition(s) to send Snapshot
description: Add conditions if needed to send snapshot to device
default: []
selector:
condition: {}
notify_device:
name: Device to notify
description: 'Select a device to send notifications to. Device needs to run
the official Home Assistant app to receive notifications.
For Google TV devices, try [Notifications for Android TV](https://play.google.com/store/apps/details?id=de.cyberdream.androidtv.notifications.google&pcampaignid=web_share).
To notify multiple devices, create a [Notification Group](https://companion.home-assistant.io/docs/notifications/notifications-basic/#sending-notifications-to-multiple-devices),
and see **Notify a Group or Android TV** below.'
default: false
selector:
device:
integration: mobile_app
multiple: false
notification_title:
name: Notification title
description: 'Default: "Motion detected!"'
default: Motion detected!
notification_message:
name: Notification message
description: 'Default: "{{ sensor_name }} detected movement! Snapshot from {{ camera_name }} at {{ time }}."'
default: '{{ sensor_name }} detected movement! Snapshot from {{ camera_name }} at {{ time }}.'
android_section:
name: Android Specific Options
description: These are Android specific options
icon: mdi:android
collapsed: true
input:
notification_channel:
name: Notification Channel - Android Only
description: Create a new channel for notifications to allow custom notification
sounds, vibration patterns, and override Do Not Disturb mode. Configured
directly on the Android device -> Home Assistant App Setting -> Notifications.
(default = {{ camera_name }} Snapshot)
default: '{{ camera_name }} Snapshot'
notification_sticky:
name: Sticky - Android Only
description: 'When enabled, the notification will stay active on the device
after tapping it and remain unless swiped.
'
default: true
selector:
boolean: {}
notification_color:
name: Notification Color - Android Only
description: 'Set the color of the notification on your Android device,
in HEX. (default = Steelblue - #03a9f4)'
default: '#03a9f4'
selector:
select:
options:
- label: 'Steelblue - #03a9f4'
value: '#03a9f4'
- label: 'Red - #f44336'
value: '#f44336'
- label: 'Pink - #e91e63'
value: '#e91e63'
- label: 'Purple - #926bc7'
value: '#926bc7'
- label: 'Deep Purple - #6e41ab'
value: '#6e41ab'
- label: 'Indigo - #3f51b5'
value: '#3f51b5'
- label: 'Blue - #2196f3'
value: '#2196f3'
- label: 'Light Blue - #03a9f4'
value: '#03a9f4'
- label: 'Cyan - #00bcd4'
value: '#00bcd4'
- label: 'Teal - #009688'
value: '#009688'
- label: 'Green - #4caf50'
value: '#4caf50'
- label: 'Light Green - #8bc34a'
value: '#8bc34a'
- label: 'Lime - #cddc39'
value: '#cddc39'
- label: 'Yellow - #ffeb3b'
value: '#ffeb3b'
- label: 'Amber - #ffc107'
value: '#ffc107'
- label: 'Orange - #ff9800'
value: '#ff9800'
- label: 'Deep Orange - #ff5722'
value: '#ff5722'
- label: 'Brown - #795548'
value: '#795548'
- label: 'Light Grey - #bdbdbd'
value: '#bdbdbd'
- label: 'Grey - #9e9e9e'
value: '#9e9e9e'
- label: 'Dark Grey - #606060'
value: '#606060'
- label: 'Blue Grey - #607d8b'
value: '#607d8b'
- label: 'Black - #000000'
value: '#000000'
- label: White -#ffffff
value: '#ffffff'
custom_value: true
sort: false
multiple: false
notification_icon:
name: Notification Status Bar Icon - Android Only
description: Change the icon that displays in the notification.
default: mdi:cctv
selector:
icon:
placeholder: mdi:cctv
tv_section:
name: Android TV Options
description: These are Android TV options
icon: mdi:youtube-tv
collapsed: true
input:
android_tv:
name: Android TV - LEGACY (EXPERIMENTAL)
description: Check if sending notifications to an Android TV type device.
default: false
selector:
boolean: {}
tv_position:
name: TV Notification Position (EXPERIMENTAL)
description: Set the position of the notification on your TV
default: center
selector:
select:
mode: dropdown
options:
- bottom-right
- bottom-left
- top-right
- top-left
- center
sort: false
custom_value: false
multiple: false
tv_size:
name: TV Notification Size (EXPERIMENTAL)
description: Set the size of the notification on your TV.
default: large
selector:
select:
mode: dropdown
options:
- small
- medium
- large
- max
sort: false
custom_value: false
multiple: false
tv_duration:
name: TV Notification Duration (EXPERIMENTAL)
description: The duration (in seconds) that the notification will display
on your TV.
default: 10
selector:
number:
max: 300.0
min: 0.0
unit_of_measurement: seconds
step: 1.0
mode: slider
tv_transparency:
name: TV notification Transparency (EXPERIMENTAL)
description: Set the transparency of the notification on your TV.
default: 0%
selector:
select:
mode: dropdown
options:
- 0%
- 25%
- 50%
- 75%
- 100%
sort: false
custom_value: false
multiple: false
tv_interrupt:
name: TV Notification Interrupt (EXPERIMENTAL)
description: If set to true the notification is interactive and can be dismissed
or selected to display more details. Depending on the running app (e.g.,
Netflix), this may stop playback.
default: false
selector:
boolean: {}
ios_section:
name: iOS Specific Options
description: These are iOS specific options
icon: mdi:apple-ios
collapsed: true
input:
notification_sound:
name: Notification Sound - iOS Only
description: 'You can specify a sound file on your device that will play
for the notifications. You can import the sound file into Home Assistant
or enter the filename of the [pre-installed notification sound](https://companion.home-assistant.io/docs/notifications/notification-sounds/#pre-installed-notification-sounds)
(example: US-EN-Alexa-Motion-Detected-Generic.wav).'
default: default
selector:
select:
options:
- label: Default
value: default
- label: None
value: none
- label: Alexa Motion Detected
value: US-EN-Alexa-Motion-Detected-Generic.wav
- label: Morgan Freeman Motion Detected
value: US-EN-Morgan-Freeman-Motion-Detected.wav
custom_value: true
sort: false
multiple: false
notification_volume:
name: Volume Sound - iOS Only
description: Specify a sound level %
default: 1
selector:
number:
max: 1.0
min: 0.0
unit_of_measurement: '%'
step: 1.0
mode: slider
notification_critical:
name: Critical Notification - iOS Only
description: Send as a critical notification to the mobile device. This
will ignore silent/vibrate modes.
default: false
selector:
boolean: {}
optional_section:
name: Optional or Experimental Options
description: These are Optional or Experimental options
icon: mdi:apple-keyboard-option
collapsed: true
input:
notify:
name: Notify Device
description: Notify a device?
default: true
selector:
boolean: {}
delay_notification:
name: Notification Delay
description: Wait before sending another notification, in seconds. (ex.
5 minutes = 300 seconds)
default: 0
selector:
number:
min: 0.0
max: 86400.0
unit_of_measurement: seconds
mode: box
step: 1.0
notification_alert_once:
name: Alert Once
description: Only the first notification for each event will play a sound.
Updates will be silent. iOS devices with Critical Notifications enabled
above will still hear default critical sounds for updates.
default: false
selector:
boolean: {}
# notification_video:
# name: Video
# description: You can optionally attach the clip to the notification which
# will replace the thumbnail/snapshot above, if available. (local url, [Documentaion](https://companion.home-assistant.io/docs/notifications/notification-attachments))
# default: ''
notification_group:
name: Group
description: The group name that will determine if notifications are grouped
on your mobile device. (default = {{ camera_name }} Snapshot)
default: '{{ camera_name }} Snapshot'
data_clickaction_url:
name: URL to Navigate
description: The URL to navigate to when clicking on the notification. (default
= /lovelace)
default: /lovelace
notify_group:
name: Notify a Group or Android TV
description: "Enter the name of the group or individual TV for notifications.
(example: all_devices) This will override individual device settings above.
Device needs to run the official Home Assistant app to receive notifications.
To notify multiple devices, create a [Notification Group](https://companion.home-assistant.io/docs/notifications/notifications-basic/#sending-notifications-to-multiple-devices).\n
\n\nImportant: Groups containing both mobile devices and TVs won't display
snapshots on the TV unless 'Android TV' is enabled. However, this setting
prevents Android phones from receiving snapshots"
default: ''
file_path:
name: File Path
description: "The file path to store the most current snapshot. \n\nDO NOT ADD `/local`, the blueprint with do that automaticaly with `/media` -> `/media/local`. \n\nDefaults
to **/media/snapshots/<camera_name>** `/media/snapshots/{{ states[camera].object_id
}}/last_motion.jpg`\n\n Try `/config/www/snapshots/{{ states[camera].object_id
}}/last_motion.jpg` if you are having issues"
default: /media/snapshots/{{ states[camera].object_id }}/last_motion.jpg
save_archive_file:
name: Save Archive Files?
description: Choose to activate saving of old snapshots or not (default
= off).
default: false
selector:
boolean: {}
conditionSave:
name: Add Condition(s) to Archive Snapshot
description: Add conditions if needed to save snapshot history files in
a directory.
default: []
selector:
condition: {}
archive_file_path:
name: Archive File Path
description: The file path to store the snapshot in an archive folder.
DO NOT ADD `/local`, the blueprint with do that automaticaly with `/media` -> `/media/local`.
Defaults
to **/media/snapshots/<camera_name>** - `/media/snapshots/{{ states[camera].object_id
}}/archive/motion_{{ now().strftime("%Y%m%d-%H%M%S")`.
default: /media/snapshots/{{ states[camera].object_id }}/archive/motion_{{
now().strftime("%Y%m%d-%H%M%S") }}.jpg
additional_actions_before:
name: Additional Actions Before
description: Add additional actions to the script. Will execute before everything
else. Useful to turn on a light before the snapshot!
default: []
selector:
action: {}
additional_actions:
name: Additional Actions After
description: Add additional actions to the script. Will execute after everything
else.
default: []
selector:
action: {}
action_type:
name: Action Type (EXPERIMENTAL)
description: 'Set action type, see [Actionable Notifications](https://companion.home-assistant.io/docs/notifications/actionable-notifications/).
default: URI'
default: URI
action_title:
name: Action Title (EXPERIMENTAL)
description: Title of action that will appear with the notification
default: Open Dashboard
action_uri:
name: Action URI (EXPERIMENTAL)
description: 'URI to naviagte to. default: /lovelace'
default: '{{ clickActionURL }}'
trigger: !input trigger_additional
variables:
trigger_additional: !input trigger_additional
camera: !input camera
#camera: "TEST"
image_entity: !input image_entity
its_camera_entity: !input its_camera_entity
camera_name: '{{ states[camera].name }}'
#camera_name: '{{ state_attr(image_entity,"friendly_name") if its_camera_entity == False else state_attr(camera,"camera_name") if states[camera] is defined} else "NONE"}'
ha_hostname: !input ha_hostname
image_entity_url: '{{ ha_hostname }}{{ state_attr(image_entity,"entity_picture") if its_camera_entity == False else "None" }}'
notify_device: !input notify_device
time: '{{ now().strftime("%H:%M") }}'
date: '{{ now().strftime("%Y-%m-%d") }}'
notification_title: !input notification_title
notification_message: !input notification_message
file_path: !input file_path
archive_file_path: !input archive_file_path
delay: !input delay
delay_notification: !input delay_notification
snapshot_create_file_path: !input file_path
snapshot_access_file_path: '{{ snapshot_create_file_path | replace(''/www'', ''/local'') | replace(''/media'', ''/media/local'') }}'
condition: !input condition
conditionSave: !input conditionSave
clickActionURL: !input data_clickaction_url
save_archive_file: !input save_archive_file
additional_actions: !input additional_actions
additional_actions_before: !input additional_actions_before
notify: !input notify
notify_group: !input notify_group
notify_group_target: '{{ notify_group | lower | regex_replace(''^notify\.'', '''')
| replace('' '',''_'') }}'
# notification_video: !input notification_video
notification_channel: !input notification_channel
notification_group: !input notification_group
notification_sticky: !input notification_sticky
notification_color: !input notification_color
notification_critical: !input notification_critical
notification_alert_once: !input notification_alert_once
notification_icon: !input notification_icon
notification_sound: !input notification_sound
notification_volume: !input notification_volume
android_tv: !input android_tv
action_type: !input action_type
action_title: !input action_title
action_uri: !input action_uri
tv_position: !input tv_position
tv_size: !input tv_size
tv_duration: !input tv_duration
tv_transparency: !input tv_transparency
tv_interrupt: !input tv_interrupt
action:
- choose: []
default: !input additional_actions_before
- delay: !input delay
- if:
- condition: template
value_template: !input its_camera_entity
then:
- service: camera.snapshot
entity_id: !input camera
data:
filename: !input file_path
- if:
- condition: template
value_template: !input notify
then:
- if:
- condition: !input condition
then:
- if:
- condition: template
value_template: '{{ not this.attributes.last_triggered or (now() - this.attributes.last_triggered).seconds
> delay_notification }}'
then:
- choose:
- conditions: '{{ android_tv }}'
sequence:
- service: notify.{{ notify_group_target }}
data:
title: !input notification_title
message: !input notification_message
data:
channel: !input notification_channel
group: !input notification_group
color: !input notification_color
clickAction: !input data_clickaction_url
# video: !input notification_video
sticky: !input notification_sticky
notification_icon: !input notification_icon
ttl: 0
priority: high
image:
#path: '{{ snapshot_create_file_path }}'
path: '{{ image_entity_url if its_camera_entity == False else snapshot_access_file_path }}'
fontsize: '{{tv_size}}'
position: '{{tv_position}}'
duration: '{{tv_duration}}'
transparency: '{{tv_transparency}}'
interrupt: '{{tv_interrupt}}'
timeout: 30
- conditions: '{{ not notify_group_target }}'
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
title: !input notification_title
message: !input notification_message
data:
channel: !input notification_channel
group: !input notification_group
color: !input notification_color
#image: '{{ image_entity_url }}'
image: '{{ image_entity_url if its_camera_entity == False else snapshot_access_file_path }}'
clickAction: !input data_clickaction_url
# video: !input notification_video
sticky: !input notification_sticky
alert_once: !input notification_alert_once
notification_icon: !input notification_icon
ttl: 0
priority: high
attachment:
#url: '{{ image_entity_url }}'
url: '{{ image_entity_url if its_camera_entity == False else snapshot_access_file_path }}'
content_type: JPEG
url: !input data_clickaction_url
push:
sound:
name: !input notification_sound
volume: !input notification_volume
critical: '{{ notification_critical }}'
actions:
- action: '{{ action_type }}'
title: '{{ action_title }}'
uri: '{{ action_uri }}'
default:
- service: notify.{{ notify_group_target }}
data:
title: !input notification_title
message: !input notification_message
data:
channel: !input notification_channel
group: !input notification_group
color: !input notification_color
#image: '{{ snapshot_access_file_path }}'
image: '{{ image_entity_url if its_camera_entity == False else snapshot_access_file_path }}'
clickAction: !input data_clickaction_url
# video: !input notification_video
sticky: !input notification_sticky
alert_once: !input notification_alert_once
notification_icon: !input notification_icon
ttl: 0
priority: high
attachment:
#url: '{{ snapshot_access_file_path }}'
url: '{{ image_entity_url if its_camera_entity == False else snapshot_access_file_path }}'
content_type: JPEG
url: !input data_clickaction_url
push:
sound:
name: !input notification_sound
volume: !input notification_volume
critical: '{{ iif(notification_critical, 1, 0) }}'
actions:
- action: '{{ action_type }}'
title: '{{ action_title }}'
uri: '{{ action_uri }}'
- if:
- condition: template
value_template: !input save_archive_file
then:
- if:
- condition: !input conditionSave
then:
- if:
- condition: template
value_template: !input its_camera_entity
then:
- service: camera.snapshot
entity_id: !input camera
data:
filename: !input archive_file_path
- choose: []
default: !input additional_actions
mode: parallel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment