Conditionally Send 1, 2 or 3 files based on Timestamp

I have a few motion sensors and cameras set up. I get notifications based on line crossings, and/or motion. I get a lot of “false Alerts”, well too many alerts sometimes, like maybe kids are playing in the driveway, etc.

I feel like I have done some good logic to reduce false alerts.
Anyway, what I’d like to do, is after the “event(s)” have finished is to send a message to my email archive

this is what I have now

  - service: notify.gmail_house_archive
    data:
      title: 'Driveway Line Crossing from Street'
      message: "{{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} on {{ now().strftime('%d %b %Y') }}" 
      data:
        images:
          - /tmp/driveway1.jpg
          - /tmp/frontdoor.jpg
          - /tmp/driveway2.jpg

I’d like to see if I can only send images with a timestamp that happened in the past 1 minute. Depending on the circumstances it could be 1, 2 or 3 of the images.

I guess the logic would apply to any files. So How would I conditionally send only files within a specific time stamp?

Just looking for thoughts, ideas.

Adding the high level concept for the automation (without having figured out timestamps

- alias: Send Camera Pics to Archive
  trigger:
  - platform: state
    entity_id: timer.camera_action
    to: 'idle'
    for:
      minutes: 1
  - service: notify.gmail_house_archive
    data:
      title: 'Driveway Line Crossing Events'
      message: "{{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} on {{ now().strftime('%d %b %Y') }}" 
      data:
        images:
          - /tmp/driveway1.jpg
          - /tmp/frontdoor.jpg
          - /tmp/driveway2.jpg

Basically when the cameras trigger motion or line crossing, I start a timer, I use the timer as a way of keeping multiple events from triggering. When the timer is done, I’d like to send any “new” pics. It would almost always be at least 2 pics, sometimes 3.

Ok another thought if time stamps is too hard.

Each image would be captured based on a specific automation.

So
automation.cameras_drive_way_1_picture
automation.cameras_drive_way_2_picture
automation.cameras_drive_way_front_door_motion

Maybe a template based on last_triggered. Ultimately only include images as the attachment based on the automation being ran within the last minute (or less)?

Just talking to myself here, but posting for anyone else in the future. Sometimes the simple solution is the best solution. I added a simple shell command at the end of the automation, to delete all images. When the automation fires it sends whichever ones are there, and skips the ones that are not there. Works well.

Problem I see here is having variable number of images.

I think you’d need to make 3 scripts; One with 1 image, 2 images, and 3 images. Example:

script:
  nofiy_1_image:
    sequence:
      - service: notify.gmail_house_archive
        data_template:
          title: "{{ title }}"
          message: "{{ message }}"
          images:
            - "{{ images.split(',')[0] }}"
  nofiy_2_images:
    sequence:
      - service: notify.gmail_house_archive
        data_template:
          title: "{{ title }}"
          message: "{{ message }}"
          images:
            - "{{ images.split(',')[0] }}"
            - "{{ images.split(',')[1] }}"
  nofiy_3_images:
    sequence:
      - service: notify.gmail_house_archive
        data_template:
          title: "{{ title }}"
          message: "{{ message }}"
          images:
            - "{{ images.split(',')[0] }}"
            - "{{ images.split(',')[1] }}"
            - "{{ images.split(',')[2] }}"

Then in your automation:

- alias: Send Camera Pics to Archive
  trigger:
  - platform: state
    entity_id: timer.camera_action
    to: 'idle'
    for:
      minutes: 1
  - service_template: ...
    data:
      title: 'Driveway Line Crossing Events'
      message: "{{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} on {{ now().strftime('%d %b %Y') }}" 
      images: ...

So the reason i left the … for images and service_template is because you’ll need 3 separate timers for each image. Once you have those timers, we can check the time and I can help you write a template for that. Without the timer entity_id’s / syntax, can’t really help.

This is what I ended up doing, and so far it’s working very well. I get 1, 2 and occasionly 3 pics. But I like what you shared, I have a few other automations I might use some of this for. :slight_smile:

- alias: Send Camera Pics to Archive
  trigger:
  - platform: state
    entity_id: timer.camera_action
    to: 'idle'
    for:
      minutes: 1
  action:
  - service: notify.gmail_house_archive
    data:
      title: 'Driveway Line Crossing Events'
      message: "{{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} on {{ now().strftime('%d %b %Y') }}" 
      data:
        images:
          - /tmp/driveway1.jpg
          - /tmp/frontdoor.jpg
          - /tmp/driveway2.jpg
  - delay:
      seconds: 10
- service: shell_command.delete_snapshots

with this as the shell command

shell_command:
delete_snapshots: 'rm -f /tmp/*.jpg'

Ah, if that works, great! Are you getting errors in the logs because images don’t exist?