Unless you want your digital picture frame on display 24/7, you will need to decide how you want to control the display power. I will show you a few ways in my articles, but the easiest for beginners is clock-controlled power management.
The way to do this in Linux is through the Cron Daemon, which is a process that runs in the background and triggers defined events at a specified time as described in the crontab file.
In this article, I will explain to you how to set up the crontab and configure wake and sleep commands for your digital picture frame. I will also show a Python script for display power management.
A Clockwork Raspberry
Tested with: Raspberry Pi OS Buster and Raspberry Pi 2, 3 and 4
To turn off a digital picture frame, you deactivate the display. The computer itself, the Raspberry Pi, is never turned off.
Once turned off, there is no way of auto-awakening it as there is no battery that powers a real-time clock (RTC) on the small board. But since its power consumption is only 2-3 Watts, it wouldn’t make much difference on your utility bill anyway.
So when a Raspberry Pi is powered on, it always checks if there is a trigger event, in our case, time. The table with the “wake-up” calls is kept in the crontab file.
To open the crontab, you type in a Terminal window
If you haven’t used crontab -e before, you will be asked which editor you would like to use. I recommend #2, the nano editor.
A typical line in the crontab script to trigger a time-based event will look something like this:
00 07 * * 1-5 vcgencmd display_power 1
This turns on the digital picture frame screen every Monday to Friday at 7h00. The exact time syntax of the crontab is explained very well on the crontab.guru website, so I won’t go into many details here.
Eight days a week
Here is an example of a script that assumes that from Monday to Friday, the digital picture frame should be turned on at 7h, and on weekends at 8h. From Sunday to Thursday, bedtime is at 22h45, and from Friday to Saturday one hour later.
# Turn off display Sunday - Thursday at 22h45 45 22 * * 0-4 vcgencmd display_power 0 # Turn off display Friday - Saturday at 23h45 45 23 * * 5,6 vcgencmd display_power 0 # Turn on screen Monday - Friday at 7h00 00 07 * * 1-5 vcgencmd display_power 1 # Turn on screen Saturday - Sunday at 8h00 00 08 * * 6,0 vcgencmd display_power 1
The command to power off the screen is
sudo vcgencmd display_power 0
, and to power on, you put a 1 instead of the 0, so
sudo vcgencmd display_power 1
Save the file with CTRL+O and exit with CTRL+X. You’re done!
You can add as many time triggers as you like in the crontab.
Powering down the monitor when not needed will save you electricity (about 20 Watts) and may extend the lifespan of your monitor. Others prefer to leave the display on to serve as a deterrent to burglars or out of convenience, but that’s up to your individual preferences.
The Python way to turn the display on and off
If you need to change the display status by invoking a Python script, this is what the code would look like for turning it on:
#!/usr/bin/python3 # coding: utf8 # import subprocess # for command execution def myfunction(): CONTROL = "vcgencmd" # command to turn the screen on CONTROL_UNBLANK = [CONTROL, "display_power", "1"] # command to turn the screen on subprocess.call(CONTROL_UNBLANK) # command to turn the screen on myfunction()
To turn the screen off, just replace the “1” with a “0”.
50 ways to control your display
There are many other methods of automatically controlling the power status of your digital picture frame display.
At home, we have installed a presence detection system where the Raspberry Pi knows when a person is at home based on the wifi presence of his/her iOS device. Or try adding a motion sensor.
You can also geofence your home with your smartphones and trigger action through IFTTT.
While crontab is an easy to write command to turn your screen on/off automatically, there is also a more modern alternative now with systemd timers. If your crontab system works fine, there is no need to change to systemd but if you are experiencing problems, have a look at my systemd timer article.
Was this post helpful?
- How I added smooth crossfading image transitions to my Raspberry Pi digital picture frame
- How to send photos to your Raspberry Pi digital photo frame via email – 2022 Update
- Show the CPU temperature of your Raspberry Pi digital picture frame in Home Assistant via MQTT
- How to start realtime systemd timer services as a crontab replacement on the Raspberry Pi