Camera snapshots

Hi,

Just wondering if anyone knows a way to only take camera snapshots when the camera is available.

I have a script set up to take a series of snapshots from the security cameras when the house alarm is triggered but this fails if any of the cameras are unavailable. Is if possible to have an if statement/condition to only include a camera if it is available or for the snapshot to fail softly? All cameras show as idle in HA even when offline so I can’t use their state as a condition.

you probably ought to post the script as you have it now to make it easier for others to help.

Script as it is below, not very complicated.

sequence:

  • data:
    entity_id: camera.kitchen
    filename: /share/camera/kitchen/kitchen_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
    service: camera.snapshot
  • data:
    entity_id: camera.console
    filename: /share/camera/console/console_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
    service: camera.snapshot

Ok what I have done is set up a ping binary sensor to ping each camera before the snapshot is taken.

So i just need to figure out how to incorporate this into a script

    camera_snapshot_test:
      alias: 'CAMERA: TEST SNAPSHOT SEQUENCE'
      sequence:
      - data: >-
    {% if is_state('binary_sensor.camera_kitchen_online', 'on') %}
      entity_id: camera.kitchen
      filename: /share/camera/kitchen/kitchen_1_{{ now().strftime("%Y%m%d") }}.jpg
    service: camera.snapshot
    {% if is_state('binary_sensor.camera_console_online', 'on') %}
      entity_id: camera.kitchen
      filename: /share/camera/console/console_1_{{ now().strftime("%Y%m%d") }}.jpg
    service: camera.snapshot

I was thinking something like the above but not sure that is valid in a script?

Have just used the last photo as supplied by the camera rather than using the HA snapshot feature, it seems to fail more gracefully without killing the rest of the process.