From f6892c1a0acb4c3c9637061a4d3801e3b4dcdaff Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sun, 8 Nov 2015 19:13:09 +0000 Subject: [PATCH] 99_SUNRISE.pm: further isday min/max enhancements (Forum #43742) git-svn-id: https://svn.fhem.de/fhem/trunk@9831 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/99_SUNRISE_EL.pm | 67 ++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/fhem/FHEM/99_SUNRISE_EL.pm b/fhem/FHEM/99_SUNRISE_EL.pm index 1d0e3101e..45d93e411 100755 --- a/fhem/FHEM/99_SUNRISE_EL.pm +++ b/fhem/FHEM/99_SUNRISE_EL.pm @@ -87,15 +87,24 @@ sr_alt($$$$$$$$$) my @lt = localtime($nt); my $gmtoff = _calctz($nt,@lt); # in hour - my ($rt,$st) = _sr_alt($altit,$needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff); + my ($rt,$st) = _sr_alt($altit,$needrise,$needset, + $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff); my $sst = ($rise ? $rt : $st) + ($seconds/3600); my $nh = $lt[2] + $lt[1]/60 + $lt[0]/3600; # Current hour since midnight if($daycheck) { - return 0 if($nh < $rt || $nh > $st); - return 0 if(defined($min) && $nh < hms2h($min)); - return 0 if(defined($max) && $nh > hms2h($max)); - return 1; + if(defined($min) && defined($max)) { #Forum #43742 + $min = hms2h($min); $max = hms2h($max); + if($min < $max) { + $rt = $min if($rt < $min); + $st = $max if($st > $max); + } else { + $rt = $max if($rt > $max); + $st = $min if($st < $min); + } + } + return 1 if($rt <= $nh && $nh <= $st); + return 0; } $sst = hms2h($min) if(defined($min) && (hms2h($min) > $sst)); @@ -109,7 +118,8 @@ sr_alt($$$$$$$$$) my $ngmtoff = _calctz($nt,@lt); # in hour $diff = 24+$gmtoff-$ngmtoff; - ($rt,$st) = _sr_alt($altit,$needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $ngmtoff); + ($rt,$st) = _sr_alt($altit,$needrise,$needset, + $lt[5]+1900,$lt[4]+1,$lt[3], $ngmtoff); $sst = ($rise ? $rt : $st) + ($seconds/3600); $sst = hms2h($min) if(defined($min) && (hms2h($min) > $sst)); @@ -400,17 +410,18 @@ sunrise, sunset, sunrise_rel, sunset_rel sunrise_abs, sunset_abs isday - perl functions, to be used in at or FS20 on-till commands.
+ perl functions, to be used in at or FS20 on-till commands. +
First you should set the longitude and latitude global attributes to the exact longitude and latitude values (see e.g. maps.google.com for the exact values, which should be in the form of a floating point value). The default value is Frankfurt am Main, Germany.

- The default altitude ($defaultaltit in SUNRISE_EL.pm) defines the sunrise/sunset - for Civil twilight (i.e. one can no longer read outside without artificial - illumination), which differs from sunrise/sunset times found on different - websites. See perldoc "DateTime::Event::Sunrise" for alternatives. -

+ The default altitude ($defaultaltit in SUNRISE_EL.pm) defines the + sunrise/sunset for Civil twilight (i.e. one can no longer read outside + without artificial illumination), which differs from sunrise/sunset times + found on different websites. See perldoc "DateTime::Event::Sunrise" for + alternatives.

sunrise()/sunset() returns the absolute time of the next sunrise/sunset, adding 24 hours if the next event is tomorrow, to use it in the timespec of @@ -420,9 +431,9 @@ isday sunrise/sunset.
sunrise_abs()/sunset_abs() return the absolute time of the corresponding event today (no 24 hours added).
- sunrise_abs_dat()/sunset_abs_dat() return the absolute time of the corresponding - event to a given date(no 24 hours added).
- + sunrise_abs_dat()/sunset_abs_dat() return the absolute time of the + corresponding event to a given date(no 24 hours added).
+ All functions take up to three arguments:

- isday() can be used in some notify or at commands to check if the sun is up or - down.

+ isday() can be used in some notify or at commands to check if the sun is up + or down. isday() ignores the seconds parameter, but respects min and max. + If min < max, than the day starts not before min, and ends not after max. + If min > max, than the day starts not after max, and ends not before min. +

+ + Optionally, for all functions you can set first argument which defines a + horizon value which then is used instead of the $defaultaltit in + SUNRISE_EL.pm.
Possible values are: "REAL", "CIVIL", "NAUTIC", + "ASTRONOMIC" or a positive or negative number preceded by "HORIZON="
REAL + is 0, CIVIL is -6, NATUIC is -12, ASTRONOMIC is -18 degrees above + horizon.

- Optionally, for all functions you can set first argument which defines a horizon value - which then is used instead of the $defaultaltit in SUNRISE_EL.pm.
- Possible values are: "REAL", "CIVIL", "NAUTIC", "ASTRONOMIC" or a - positive or negative number preceded by "HORIZON="
- REAL is 0, CIVIL is -6, NATUIC is -12, ASTRONOMIC is -18 degrees above horizon.

Examples:
- The functions sunrise_abs_dat()/sunset_abs_dat() need as a very first parameter the date(format epoch: time()) for which the events should be calculated. + The functions sunrise_abs_dat()/sunset_abs_dat() need as a very first + parameter the date(format epoch: time()) for which the events should be + calculated.

Examples:
@@ -502,7 +520,6 @@ isday
- =end html