I have my front yard light connected to a outletbox controlled via a LPT port. And it's hooked up the the rest of the home automation system.
I was just having cron turn on and off the light a specified times. But a little script and a bit of help from a government website, the light turns off at sunrise and back on at sunset.
Here's the little script that does it:
#!/bin/sh
#
# Gets sunset / sunrise tables from aa.usno.navy.mil
# http://ubuntu.online02.com/node/36
# Run with cron after midnight but before sunrise (4am) to get the times for the day
#
YEAR=$(date +%Y)
MONTH=$(date +%m)
DAY=$(date +%d)
STATE="NY"
CITY="omaha"
wget http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data="xxy=$YEAR&xxm=$MONTH&xxd=$DAY&st=$STATE&place=$CITY" -O /tmp/suntable.htm
SUNRISE=$(cat /tmp/suntable.htm | grep Sunrise | sed 's/Sunrise //' | sed 's/\.//g' | sed 's/ //g')
SUNSET=$(cat /tmp/suntable.htm | grep Sunset | sed 's/Sunset //' | sed 's/\.//g' | sed 's/ //g')
echo Sunrise: $SUNRISE
echo Sunset: $SUNSET
# Run commands at sunrise or sunset
at -f /path/to/script.sh $SUNRISE
at -f /path/to/script.sh $SUNSET
Comments
Thanks for this script
Thanks for this script hopefully i'll get it going. i have IP cams that need a setting changed every day at sunrise and sunset.
Do i just put this in a txt file and put it in cron.daily folder? i have another script named day.sh and it uses curl to send html code to the cameras.
Yeah, I just put it into a
Yeah, I just put it into a text file, chmod a+x it to make it executable, and then run it at 3am each day. I don't know when cron.daily runs, but as long as it's before sunrise, you'll be good!
Post new comment