The previous builds were smaller but smarter. They actually turned off when nobody was around to see. The RPiPF (RapsberyPi Picture Frame) is not there yet.
A small step forward: turn off when nobody's around to watch and turn on when there may be - on the schedule. Turn on at 7am, turn off 11pm.
To control the TV from RPI - CEC
Install cec-utilssudo apt-get install cec-utils
Turn the TV off:
echo "standby 0" | cec-client -s -d 1
Turn the TV on
echo "on 0" | cec-client -s -d 1
Don't mind the CLI plumbing - these command are like magic: '-s' means execute single command while '-d 1' limits the damage to you eyes by cutting down the logging spewed back at ya. Note that the echo just pipes the actual command to the cec-client - an interactive program by birth.
Flying on a Magic Script
The ph.sh script that was previously used to just start feh. Now it does the scheduling.
The script loops and:
- checks the time
- decides if the slide show should or should not be running
- depending on that decision either
- kills feh and turns off the TV or
- starts feh and turns on the TV
- sleeps for 1 minute and repeats
logger "PF started"
PATH=$HOME/bin:$PATH
while true; do
now=`date +%H%M`
fehpid=`pidof feh`
if [ $now -gt 700 ] && [ $now -lt 2300 ]; then
if [ -z $fehpid ]; then
logger "PF now=$now fehpid=$fehpid ON"
tvon
gofeh &
fi
else
if [ ! -z $fehpid ]; then
logger "PF now=$now fehpid=$fehpid OFF"
skill feh
tvoff
fi
fi
sleep 1m
done
Taking it apart
- The lines with 'logger ...' just put entries in /var/log/user.log so I know what was happening.
- The line "PATH=" just adds /home/pi/bin (user's pi bin directory) to the path. Normally this should be done the .profile.
- Then we loop forever...
- The line 'now=... ' captures current time into the 'now' variable. The time is formatted as hhmm (in 24 hour format) for easier comparing later.
- The 'fehpid=...' captures the process ID of feh, the slide show process. If it is not running, the fehpid is empty string.
- Then in the first 'if' the script compares the $now to fit between 700 and 2300, military style.
- And finally, the nested 'ifs' decide to turn on the show or to stop it. The '-z' checks for empty, while the '! -z' checks for not empty.
- The small command scripts: tvon, tvoff, gofeh got created in ~/bin (and chmod +x them so they can be executed).
- The gofeh is run in the background (with '&') so the script can continue monitoring the time after starting the slide show.