One of our readers, Meir, recently suggested a new Pi3D Picture Frame feature on the GitHub forum.
He wanted an automatic filter on specific dates, like birthdays or anniversaries. On these special days, only a hand-made collection of images would be shown without manual interaction.
Never forget another wedding anniversary when you only see photos of your wedding in the morning. Talk about a gentle reminder!
My first thought was that this was going to be challenging.
But it turns out that with some first principles thinking from Paddy, it’s very easy to implement.
Meir and Paddy devised a super simple solution, which they were kind enough to let me share here.
Tested with a Raspberry Pi OS Bookworm on a Raspberry Pi 5 (November 2024).
Here is how it works.
PictureFrame lets you remote control the display via HTTP, MQTT, or SSH.
Using HTTP, you can send a filter to use only a certain directory.
Then, you let crontab check at 0:01 a.m. every day to see if a set date is met. If yes, you send an HTTP command to your frame.
There are three steps:
Prepare your picture collection
Ask yourself the question:
A. Do you want to show photos on these special days, that you wouldn’t show normally? Think greetings cards, a personal message.
B. Or do you want to focus on a set of images to be shown exclusively on a particular day?
A. Show special photos that you don’t normally display
If A is your answer, create a new directory in “Pictures” called “main” and put all the pictures displayed each day in it. Do not leave pictures in the “Pictures” directory.
Then create the special dates subdirectories in the form MMDD (MM for the month and DD for the day (e.g., “0510” for the tenth of May) in the “Pictures” directory.
Move all the photos that you want to show on these dates. If you also want to include them in your normal collection, copy them instead of moving them so there is a picture in both “main” and your special days.
Also, change the default picture directory in configuration.yaml
to “Pictures/main
” like this
pic_dir: "/home/pi/Pictures/main" # default="/home/pi/Pictures", root folder for images
B. Focus on a set of images exclusively
In this scenario, you merely filter on special photos that are part of your normal collection anyway. You just show only those photos on that day.
In that case, you don’t have to create a “main” directory or change anything in the configuration.yaml
.
Just create your subdirectories with the dates you want to make special and move your pictures in there. The format for the subdirectories is the same as above, MMDD (MM for the month and DD for the day (e.g., “0510” for the tenth of May).
Preparing PictureFrame
To activate the HTTP control of your frame, open configuration.yaml and check the following section. The default setting are this:
http:
use_http: False # default=False
path: "/home/pi/picframe_data/html" # path to html files
port: 9000 # port used to serve pages by http server
auth: false # default=False
username: admin # username for basic auth
password: null # password for basic auth
use_ssl: False
keyfile: "path/to/key.pem" # private-key
certfile: "path/to/cert.pem" # server certificate
Unless you have some special security settings, you just need to activate HTTP with
http:
use_http: True # default=False
Leave all other values unchanged. Save and close.
Create the Python script
Log onto your Raspberry Pi.
Go to the picframe_data directory with
cd /home/pi/picframe_data
and create a new Python script with
sudo nano check_date.py
Paste the below content in this file.
#!/usr/bin/python3
import datetime
import os
from urllib import request
ROOT_DIR = "/home/pi/Pictures" # Root directory for picture subdirectories
URL = "http://localhost:9000" # URL for sending requests
# Get current date and format it as MMDD
date_now = datetime.datetime.now()
subdirectory = f"{date_now.month:02}{date_now.day:02}"
full_url = f"{URL}?subdirectory="
# Check if the subdirectory exists within the root directory
if subdirectory in os.listdir(ROOT_DIR): # No error handling here
full_url += subdirectory # Append the subdirectory to the URL
request.urlopen(full_url) # Send a request to the constructed URL
# Log the URL with date and time for debugging purposes
with open("/home/pi/picframe_data/check_date_log.txt", "a") as log_file:
log_file.write(f"{datetime.datetime.now()} - directory:{full_url}\n")
Save and close.
Make executable with
chmod +x /home/pi/picframe_data/check_date.py
Make the crontab settings
Now, all you need to do is instruct crontab
Type
crontab -e
and make the script run each day at zero 0 one by adding these two lines
@reboot sleep 60 && python3 /home/pi/picframe_data/check_date.py
01 00 * * * python3 /home/pi/picframe_data/check_date.py
If this is your first time using crontab, you will be asked which editor to choose. Answer “1” for Nano.
I added the reboot command line with a short sleep delay so that you can test it with the current day. The sleep delay is necessary because sometimes, @reboot jobs run before all system services have fully initialized. If you use a slow Raspberry Pi, you may have to extend the sleep time. 30 seconds seem to be fine on a Pi 5.
You may even want to change the time to more like four o’clock in the morning, so if you have a birthday party in the evening, your frame will not kill the mood by changing back to your general “Pictures” directory while everybody is still dancing.
In that case, enter
00 04 * * * python3 /home/pi/picframe_data/check_date.py
Alternative approach
Instead of using directories, you could alternatively include a tag (“0510” for May 10) in your special occasion photos and filter on the tag. That way, you won’t need to put them in different subdirectories.
However, I would assume that most people are unfamiliar with tagging, so Meir’s solution is much easier to implement.
Conclusion
Thank you to Meir for coming up with such an exciting feature idea and to Paddy for helping him devise a simple solution.
Don’t ever forget your wedding day again with this simple feature!
Was this article helpful?
Thank you for your support and motivation.
Related Articles
- How to automatically remove duplicate images from your Pictures folder (2024 Edition)
- How to only show portrait photos on your Raspberry Pi photo frame
- How I added smooth crossfading image transitions to my Raspberry Pi digital picture frame (OS Buster Edition)
- Personalizing Pi3D PictureFrame: How to localize your photo geodata in any language