Remove a specific file from a folder

Hello!

I have a question about removing specific files from a folder.

I have an automation triggered by a motion sensor that calls a script. the script is taking pictures from a IP camera and sends it by pushbullet and mail. After that I want to remove the file. I have found shell commands and how to remove say all pictures from a folder. The problem is that sometimes when the automation is triggered many times after each other the first trigger removes even the pictures from the second trigger before it had time to send it.

The photos is named by the current date and time like YYYY-MM-DD_HH.MM.SS.jpg what I would want is to take the picture, name it as above, send it in an mail and then remove it without removing other photos in the same folder. Does any one know hot to do that?

There’s an easier way.

When you create the camera snapshot call it camera_snapshot.jpg instead of using the date in the file name.

Each subsequent snapshot will overwrite the same file (hopefully after you email it).

If you still really want to delete it this also simplifies the shell command to do that.

1 Like

@tom_l
Hello!

Thanks, yes that’s an easier way. The fact is that i want to take like 5 snapshots and then send all of them in the same email. But then i just could use snap_1, snap_2 etc. But what i want is to be able to take photos quite rapidly and send them.

I would also be able to upload them to google drive. Do you know how to do that?

All i can find is the snapshot backup addon.

This is exactly what I do if my alarm is on and I detect movement in the house.

  action:
  - service: camera.snapshot
    data:
      entity_id: camera.lounge
      filename: '/config/www/snapshots/lounge1.jpg'
  - delay: 00:00:01
  - service: camera.snapshot
    data:
      entity_id: camera.lounge
      filename: '/config/www/snapshots/lounge2.jpg'
  - delay: 00:00:01
  - service: camera.snapshot
    data:
      entity_id: camera.lounge
      filename: '/config/www/snapshots/lounge3.jpg'
  - service: notify.email
    data:
      title: 'Lounge Movement'
      message: 'Lounge movement detected'
      data:
        images:
          - /config/www/snapshots/lounge1.jpg
          - /config/www/snapshots/lounge2.jpg
          - /config/www/snapshots/lounge3.jpg

The email is time stamped so no need to include it in the file names (there’s also the time and date on the camera on screen overlay). I had to introduce the 1 second delays because the snapshots are taken very rapidly and all the images were esentially the same.

Sorry, no I dont.

@tom_l
Okay! You don’t need a delay between the last photo and sending the email? I had to have a couple of seconds otherwise i get an error saying that the file doesn’t exist.

No it doesn’t seem to be a problem for me. I’m running HA on a core i7 4610Y though.