Timelapse with pi camera

I wish to create a time-lapse sequence with images captured from the pi camera on my HA install. I can capture the images but they are always written with the default filename image.jpg. I do not see a way to configure the component to save images with a time-stamped filename, as is required to create a time-lapse video. I could write a shell command to periodically copy image.jpg with a timestamped file name, but imagine there must be a more direct way - can anyone advise?
Cheers

Not sure of your goal here but MotionEye has timelapse.photo feature.
Maybe that can help you

The Pi camera component has time lapse, but each image is saved as image.jpg, and therefore each image is overwritten by the next in the sequence

I use a shell script to do a timelapse at sunset and sunrise out my window. Script is just triggered by HA

# !/bin/bash

counter=0
folder=$(date +"%Y%m%d")

# if folder does not exist, assume sunrise
if [ ! -d "/mnt/synodata/timelapse/${folder}-AM" ] 
then
  folder="${folder}-AM"
else
  folder="${folder}-PM"
fi

mkdir /mnt/synodata/timelapse/$folder

while [ $counter -lt 800 ]; do   
    echo $counter
    # create a filename with date and time portion
    filename=$(date +"%Y%m%d_%H_%M_%S").jpg
    # use wget to download the current image from the webcam
    wget http://user:[email protected]/image.jpg -O /mnt/synodata/timelapse/$folder/$filename
    # wait 3 seconds
    counter=$((counter+1))
    sleep 3;
done;

I’m wget’ing from an IP camera, but just replace with wherever you can get an image from.

1 Like

OK so this link describes what I want to achieve. Conveniently time-lapse can be performed with the raspistill command, which is what the pi camera component uses, so it is just a small tweak to add this functionality (incrementing filenames). Cheers all

Hi, not really an expert here but trying to help anyway.
You are right that images are always written with the same default name image.jpg. If we go to the source code we observe:

CONF_FILE_PATH: config.get(CONF_FILE_PATH,
    os.path.join(os.path.dirname(__file__),
    'image.jpg'))

You asked about saving images with a timespamped file name instead so, if you are comfortable tinkering with your HA installation (and, by looking at your posts activities, I bet you are!), my proposal would be to:
1.- Search for the file rpi_camera.py in the HA directory (it should be inside components/camera folder) and open it.
2.- Replace (around line 82) ‘image.jpg’ with ‘image-’+datetime.now().strftime(’%Y-%m-%d-%H-%M-%S’)+’.jpg’
3.- You’ll have to include the datetime module at the top of the file, so around line 10 just include:

from datetime import datetime

4.- Save it and restart HA

Unfortunately I don’t own a raspi camera so I cannot test. I’m pretty sure this could be performed by creating a custom component and not tinkering with the HA installation but maybe this could be a second step if everything works as expected.
Good luck!

1 Like

Thanks Tim. Once I’m happy with this il submit a PR as the time lapse feature is pretty pointless without this added functionality :slight_smile:

2 Likes