Notes
![]() ![]() Notes - notes.io |
LOG_FILE="/home/pi/tv_control.log"
VIDEO_FILE="/home/pi/video.mp4"
TEMP_VIDEO="/home/pi/temp_video.mp4"
FILE_ID="1A2B3C4D5E6F7G8H9I" # Change this to your Google Drive file ID
EMAIL_TO="[email protected]" # Change this
GDRIVE_URL="https://drive.google.com/uc?id=$FILE_ID&export=download"
# Function to log messages
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a $LOG_FILE
}
# Function to send email (requires `ssmtp` configured)
send_email() {
echo -e "Subject: TV Control Errornn$1" | ssmtp $EMAIL_TO
}
# Function to check if the TV is on
check_tv_status() {
TV_STATUS=$(echo "pow 0" | cec-client -s -d 1 | grep "power status:")
if [[ "$TV_STATUS" == *"on"* ]]; then
log_message "TV is ON."
return 0 # Success
else
log_message "TV is OFF or did not turn on!"
send_email "Failed to turn ON TV at $(date)"
return 1 # Failure
fi
}
# Function to turn TV on
turn_on_tv() {
echo "on 0" | cec-client -s -d 1
sleep 5 # Wait for TV to turn on
check_tv_status
}
# Function to turn TV off
turn_off_tv() {
echo "standby 0" | cec-client -s -d 1
log_message "TV turned off."
}
# Function to download video
download_video() {
log_message "Checking for updated video..."
wget -O $TEMP_VIDEO $GDRIVE_URL
if [[ $? -eq 0 ]]; then
mv $TEMP_VIDEO $VIDEO_FILE
log_message "Video updated successfully."
else
log_message "Error downloading video."
send_email "Failed to download video from Google Drive."
fi
}
# Function to play video
play_video() {
log_message "Playing video: $VIDEO_FILE"
omxplayer --loop $VIDEO_FILE > /dev/null 2>&1 &
}
# Function to stop video
stop_video() {
pkill omxplayer
log_message "Video stopped."
}
# Schedule tasks with cron
setup_cron_jobs() {
(crontab -l 2>/dev/null; echo "0 6 * * * /home/pi/tv_control.sh play") | crontab -
(crontab -l 2>/dev/null; echo "0 23 * * * /home/pi/tv_control.sh stop") | crontab -
}
# Handle script arguments
case "$1" in
play)
download_video
turn_on_tv
if [[ $? -eq 0 ]]; then
play_video
else
log_message "Skipping video playback since TV did not turn on."
fi
;;
stop)
stop_video
turn_off_tv
;;
setup)
setup_cron_jobs
log_message "Cron jobs set up."
;;
*)
echo "Usage: $0 {play|stop|setup}"
;;
esac
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team