Camera snapshot and additional actions when binary sensor is triggered

Tags: #<Tag:0x00007f32639547b8> #<Tag:0x00007f32639546f0>

This blueprint takes a snapshot of a camera when a binary sensor is triggered/set to ‘on’. You can add additional actions afterward.

For example, you can send a notification to your phone using the variable {{ snapshot_file_path }} as the image URL.

blueprint:
  name: Camera snapshot and actions when binary sensor is triggered
  description: >-
    Creates a snapshot and triggers a subsequent action when a binary sensor is triggered
  domain: automation
  input:
    binary_sensor:
      name: Binary sensor
      description: The sensor wich triggers the snapshot creation
      selector:
        entity:
          domain: binary_sensor
    camera:
      name: Camera
      description: The camera which creates the snapshot
      selector:
        entity:
          domain: camera
    delay:
      name: 'Snapshot Delay (Optional)'
      description: 'Wait before creating camera snapshot'
      default: 0.0
      selector:
        number:
          min: 0.0
          max: 60.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    additional_actions:
      name: 'Additional Actions'
      description: >-
        Actions after taking snapshot. (Optional)
        Example: A notification using {{ snapshot_file_path }} as the image.
      default: []
      selector:
        action:
  source_url: https://community.home-assistant.io/t/camera-snapshot-and-additional-actions-when-binary-sensor-is-triggered/255382
mode: restart
variables:
  binary_sensor: !input 'binary_sensor'
  binary_sensor_name: '{{ states[binary_sensor].name }}'
  camera: !input 'camera'
  delay: !input 'delay'
  snapshot_create_file_path: '/config/www/tmp/snapshot_{{ states[camera].object_id }}.jpg'
  snapshot_file_path: '{{ snapshot_create_file_path | replace(''/config/www'', ''/local'') }}'
trigger:
  platform: state
  entity_id: !input 'binary_sensor'
  from: 'off'
  to: 'on'
action: 
  - delay: '{{ delay }}'
  - service: camera.snapshot
    entity_id: !input 'camera'
    data:
      filename: '{{ snapshot_create_file_path }}'
  - choose:
    default: !input additional_actions

Thanks to this blueprint which this one was based on.

3 Likes

Please let me know if there is a better way to include additional actions to a blueprint than this way:

  - choose:
    default: !input additional_actions

I find it very hacky, but it works for now

Thanks for the blueprint.
COuld you please guide me with how i can email the shapshot ?
In add actions i have selected
Action Type: Call Service
Service: : Notify_Gmail (*gmail notification is configured)
Servcie Data :

What do i need to put in the service data field to pickup the sanphot and attach it in the notification ?

I found a little bug which crashed all my automations. I clicked on additional actions but left it empty. It generated code like below and automations crashed.

      additional_actions:
      - device_id: ''
        domain: ''
        entity_id: ''

Sorry, don’t have full log but this fragment was there:

homeassistant.loader.IntegrationNotFound: Integration '' not found.

What is more, after HA restart even automations in UI disappeared