Skip to content

Instantly share code, notes, and snippets.

@alexgorbatchev
Last active November 27, 2023 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexgorbatchev/3f21763075a8ecbcdd10bbedbed5882a to your computer and use it in GitHub Desktop.
Save alexgorbatchev/3f21763075a8ecbcdd10bbedbed5882a to your computer and use it in GitHub Desktop.
Short description
blueprint:
name: Send Camera snapshot when if a binary sensor's state turns 'off' to 'on', 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. (v1.01)
domain: automation
input:
condition:
name: Add Condition(s)
description: Add conditions if needed
default: []
selector:
condition: {}
sensor:
name: Motion or Binary Sensor
description: The sensor wich triggers the snapshot creation
selector:
entity:
domain:
- binary_sensor
multiple: false
camera:
name: Camera
description: The camera which will be streamed
selector:
entity:
domain:
- camera
multiple: false
stream_device:
name: Device to stream to
description: Nest Hub, etc...
selector:
device:
integration: media_player
multiple: true
notification_message:
name: Notification message (Optional)
description: 'Default: "{{ sensor_name }} detected"'
default: '{{ sensor_name }} detected'
delay:
name: Timeout (Optional)
description: Maximum time to play the stream
default: ''
selector:
number:
min: 0.0
max: 60.0
unit_of_measurement: seconds
mode: slider
step: 1.0
trigger:
platform: state
entity_id: !input sensor
from: 'off'
to: 'on'
variables:
sensor: !input sensor
sensor_name: '{{ states[sensor].name }}'
camera: !input camera
stream_device: !input stream_device
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'') }}'
condition: !input condition
action:
- if:
- condition: !input condition
then:
- service: tts.speak
data:
cache: true
media_player_entity_id: {{ stream_device }}
message: {{ notification_message }}
target:
entity_id: tts.piper
- service: media_player.play_media
data:
media_content_id: {{ camera }}
media_content_type: video
target:
entity_id: {{ stream_device }}
- wait_for_trigger:
- platform: state
entity_id:
- trigger.entity_id
to: "off"
from: "on"
timeout:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: media_player.turn_off
data: {}
target:
entity_id: {{ stream_device }}
# - delay: '{{ delay }}'
# - service: camera.snapshot
# entity_id: !input camera
# data:
# filename: '{{ snapshot_create_file_path }}'
# - device_id: !input stream_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 }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment