Camera snapshot with auto delete and send

Hi, I have today an automation that sends me an email with a pic of the alarm is on and someone triggers the binary sensor couple with my camera. This is working ok, but, there is a delay between the binary sensor trigger and the snapshot moment, so the incident that triggers the snapshot is usually lost when that snapshot happens.

My solution for this issue would be simple:

Condition:

  1. When alarm is on,

Action:
2) Take snap shot every 1 sec
3) Store 5 snapshots and remove the old ones as new comes in

Condition:
4) when binary sensor is triggered

Action:
5)send the 5 snapshots in a message a time lapse.

Now the issue, could someone help me write this scrip or even improve it, maybe someone already has something similar to this running?