#!/usr/bin/perl
###################################################################
#
# turnLightsOnbeforeSunset.pl
#
# uses module: install Astro::Sunrise
#
# get Latitude and Longitude from
# http://www.latlong.net/
# 72555, de:
# - latitude: 48.534733
# - longitude: 9.295337
#
# run as cron:
# 1,31 16,17,18,19,20,21,22,23,0 * * * /root/bin/turnLightsOnbeforeSunset.pl >>/var/log/turnLightsOnbeforeSunset.log 2>&1
#
#
###################################################################

use Astro::Sunrise;
use strict;

my $minbefore = 35;
my $cmd_on = '/root/bin/steckdose1on.sh';
my $cmd_off = '/root/bin/steckdose1off.sh';
my $date = `date`;
chomp($date);

my $sunset = sun_set(9.295337,48.534733); #long, lat
$sunset =~ s/://g;

my @curtime = localtime();
my $curtime = join '', @curtime[2,1];
my $curhour = $curtime[2];

print "$date sunset=$sunset, curtime=$curtime, curhour=$curhour\n";

if (( $curtime + $minbefore) > $sunset){
print "$date turn on the light\n";
system($cmd_on);
}
if ($curhour < 1){
print "$date turn off the light\n";
system($cmd_off);
}

computer2know :: thank you for your visit :: have a nice day :: © 2018