How to delete files automatically in folder

I want to delete mp4 files every 30 minutes in a folder(snapshots) containing videos saved from my camera. How do I do that?

  • /homeassistant/www/snapshots

Create a shell command to delete the files:

Use a time pattern triggered automation to call the shell command in the automation actions.

Can you help me edit it, thanks?


shell_command:
  remove_all_video_records: 'rm -f /homeassistant/www/snapshots/*.mp4'
  
  
automation:
    alias: 'Hass Clear Video Snaphots'
    description: Dọn dẹp thư mục chứa camera snapshot mỗi tuần
    trigger:
    - platform: time
      at: '02:55:00'
    condition:
    - condition: time
      weekday:
      - saturday 
    action:
    - alias: 'gọi shell_command đã tạo'
      service: shell_command.remove_all_video_records
      data: {}
    mode: single 
    
shell_command:
  remove_all_video_records: 'rm -f /homeassistant/www/snapshots/*.mp4'
  
  
automation:
  - alias: 'Hass Clear Video Snaphots'
    description: Dọn dẹp thư mục chứa camera snapshot mỗi tuần
    trigger:
    - platform: time_pattern
      minutes: '/30'
    action:
    - alias: 'gọi shell_command đã tạo'
      service: shell_command.remove_all_video_records
      data: {}
    mode: single 

i followed but it doesnt delete mp4 video in folder i am newbie please help me

Did you perform a configuration check and restart home assistant after creating that?

Where is the rest of your configuration.yaml file?

There should be a lot more than just that in there.

What errors do you see in Settings → System → Logs?

What if I want to delete more filenames?
for example: mp3 , mp4 , avi

thank you

Change your shell command.

please help me edit this command, i want to delete file in folder more than 30 minutes

shell_command:

  delete_snapshots: >
    find /config/www/snapshots/timed/ -mtime +{{states('input_number.ouder_dan')|int(600)}} -exec rm {} \;

Just post this in the same thread you copied my shell_command from.

Please help keep this community organized and easy to follow…