Deleting old camera recordings

I’m setting up Home Assistant to record video from my Amcrest cameras. These cameras binary sensor for motion detection, so I’m using that as a trigger. When motion is detected, I record 30 seconds of video to the internal SD card, then upload that to S3. It also sends a notification to my phone with a dynamic attachment showing the live video.
To pass the correct filename to the minio.put step, I had to create a helper entity for the filename. This seems a bit clunky but I couldn’t think of a better way. If anyone knows of a way to keep this self-contained within the automation that would be nice.
In AWS, I have configured a lifecycle rule to delete old recordings after 90 days. But I don’t know how to do this locally. Is there a way to delete files on a schedule?

- alias: Outside - front yard motion
  description: Record and upload to S3 when Amcrest cameras detect motion
  - platform: state
    - binary_sensor.front_yard_motion_detected
    to: 'on'
  - condition: state
    entity_id: input_boolean.alarm_set
    state: 'on'
  - service: input_text.set_value
      value: '{{ now().strftime(''%Y%m%d_%H%M%S'') }}_front_yard'
      entity_id: input_text.latest_recording_front_yard
  - service: notify.family_notifications
      message: Front yard {{ now().strftime('%H:%M:%S') }}
      title: Motion Detected
        entity_id: camera.front_yard
        url: /lovelace/security
  - service: camera.record
      filename: /share/recordings/front_yard/{{ states('input_text.latest_recording_front_yard')
      duration: 20 # not accurate, it actually records a little longer
      entity_id: camera.front_yard
  - service: minio.put
      bucket: xxxxxxxxxx
      file_path: /share/recordings/front_yard/{{ states('input_text.latest_recording_front_yard')
      key: recordings/front_yard/{{ states('input_text.latest_recording_front_yard') }}.mp4
  mode: single

Have a look at

You can install it via HACS or manually.

When calling the service delete.files_in_folder it is possible to specify a period of time how old files must be in seconds in order to be deleted.

Instead of the input_text you could use (script) variables