A simple way to automatically turn your digital picture frame on and off at fixed times

By February 12, 2019 March 8, 2019 DIY Instructions, Software

Unless you want your dig­i­tal pic­ture frame on dis­play 24/7, you will need to decide how you want to con­trol the dis­play pow­er. I will show you a few ways in my arti­cles, but the eas­i­est for begin­ners is clock-con­trolled pow­er man­age­ment.

The way to do this in Lin­ux is through the Cron Dae­mon which is a process that runs in the back­ground and trig­gers defined events at a spec­i­fied time as described in the crontab file.

In this arti­cle, I will explain to you how to set up the crontab and con­fig­ure wake and sleep com­mands for your dig­i­tal pic­ture frame. I will also show a Python script for dis­play pow­er man­age­ment.

A Clockwork Raspberry

To turn off a dig­i­tal pic­ture frame, you deac­ti­vate the dis­play. The com­put­er itself, the Rasp­berry Pi, is nev­er turned off.

Once turned off, there is no way of auto-awak­en­ing it as there is no bat­tery that pow­ers a real-time clock (RTC) on the small board. But since its pow­er con­sump­tion is only 2-3 Watts, it wouldn't make much dif­fer­ence on your util­i­ty bill any­way.

So when a Rasp­berry Pi is pow­ered on, it always checks if there is a trig­ger 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 Ter­mi­nal win­dow
crontab -e

If you haven't used crontab -e before, you will be asked which edi­tor you would like to use. I rec­om­mend #2, the nano edi­tor.

A typ­i­cal line in the crontab script to trig­ger a time-based event will look some­thing like this:
00 07 * * 1-5 vcgencmd display_power 1

This turns on the dig­i­tal pic­ture frame screen every Mon­day to Fri­day at 7h00. The exact time syn­tax of the crontab is explained very well on the crontab.guru web­site, so I won't go into many details here.

Eight days a week

Here is an exam­ple of a script which assumes that from Mon­day to Fri­day the dig­i­tal pic­ture frame should be turned on at 7h, and on week­ends at 8h. From Sun­day to Thurs­day bed­time is at 22h45 and from Fri­day to Sat­ur­day one hour lat­er.

# 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 com­mand to pow­er off the screen is
sudo vcgencmd display_power 0

and to pow­er 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 trig­gers as you like in the crontab.

Pow­er­ing down the mon­i­tor when not need­ed will save you elec­tric­i­ty (about 20 Watts) and may extend the lifes­pan of your mon­i­tor. Oth­ers pre­fer to leave the dis­play on to serve as a deter­rent to bur­glars or out of con­ve­nience, but that's up to your indi­vid­ual pref­er­ences.

The Python way to turn the display on and off

If you need to change the dis­play sta­tus by invok­ing a Python script, this is what the code would look like for turn­ing 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 oth­er meth­ods of auto­mat­i­cal­ly con­trol­ling the pow­er sta­tus of your dig­i­tal pic­ture frame dis­play.

At home, we have installed a pres­ence detec­tion sys­tem where the Rasp­berry Pi knows when a per­son is at home based on the wifi pres­ence of his/her iOS device; oth­ers have tin­kered with motion sen­sors which I don't think is so great. You can also geofence your home with your smart­phones and trig­ger an action through IFTTT.

I will write more about oth­er meth­ods in the future.