mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
Sunrise changes
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@377 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5a686b2a37
commit
7620695004
1
CHANGED
1
CHANGED
@ -498,3 +498,4 @@
|
|||||||
- bugfix: FHT "summer" fix (avoiding a lot of syncnow)
|
- bugfix: FHT "summer" fix (avoiding a lot of syncnow)
|
||||||
- feature: FHEMWEB modules added
|
- feature: FHEMWEB modules added
|
||||||
- feature: holiday module + doc + example + holiday2we attribute
|
- feature: holiday module + doc + example + holiday2we attribute
|
||||||
|
- bugfix: sunrise stuff fixed, doc missing
|
||||||
|
@ -119,7 +119,10 @@ at_Exec($)
|
|||||||
if($count) {
|
if($count) {
|
||||||
$def =~ s/{\d+}/{$count}/ if($def =~ m/^\+?\*{\d+}/); # Replace the count
|
$def =~ s/{\d+}/{$count}/ if($def =~ m/^\+?\*{\d+}/); # Replace the count
|
||||||
Log GetLogLevel($name,5), "redefine at command $name as $def";
|
Log GetLogLevel($name,5), "redefine at command $name as $def";
|
||||||
|
|
||||||
|
$data{AT_RECOMPUTE} = 1; # Tell sunrise compute the next day
|
||||||
CommandDefine(undef, "$name at $def"); # Recompute the next TRIGGERTIME
|
CommandDefine(undef, "$name at $def"); # Recompute the next TRIGGERTIME
|
||||||
|
delete($data{AT_RECOMPUTE});
|
||||||
$attr{$name} = $oldattr;
|
$attr{$name} = $oldattr;
|
||||||
}
|
}
|
||||||
$at_tdiff = undef;
|
$at_tdiff = undef;
|
||||||
|
@ -12,7 +12,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use Math::Trig;
|
use Math::Trig;
|
||||||
|
|
||||||
sub sr($$$$);
|
sub sr($$$$$$);
|
||||||
sub sunrise_rel(@);
|
sub sunrise_rel(@);
|
||||||
sub sunset_rel(@);
|
sub sunset_rel(@);
|
||||||
sub sunrise_abs(@);
|
sub sunrise_abs(@);
|
||||||
@ -38,56 +38,56 @@ SUNRISE_EL_Initialize($)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
# Compute:
|
# Compute the _next_ event
|
||||||
# rise: 1: event is sunrise (else sunset)
|
# rise: 1: event is sunrise (else sunset)
|
||||||
# isrel: 1: _relative_ times until the next event (else absolute for today)
|
# isrel: 1: relative times
|
||||||
# seconds: second offset to event
|
# seconds: second offset to event
|
||||||
# daycheck: if set, then return 1 if the sun is visible, 0 else
|
# daycheck: if set, then return 1 if the sun is visible, 0 else
|
||||||
sub
|
sub
|
||||||
sr($$$$)
|
sr($$$$$$)
|
||||||
{
|
{
|
||||||
my ($rise, $seconds, $isrel, $daycheck) = @_;
|
my ($rise, $seconds, $isrel, $daycheck, $min, $max) = @_;
|
||||||
my $needrise = ($rise || $daycheck) ? 1 : 0;
|
my $needrise = ($rise || $daycheck) ? 1 : 0;
|
||||||
my $needset = (!$rise || $daycheck) ? 1 : 0;
|
my $needset = (!$rise || $daycheck) ? 1 : 0;
|
||||||
|
$seconds = 0 if(!$seconds);
|
||||||
|
|
||||||
my $nt = time;
|
my $nt = time;
|
||||||
my @lt = localtime($nt);
|
my @lt = localtime($nt);
|
||||||
my $gmtoff = _calctz($nt,@lt); # in hour
|
my $gmtoff = _calctz($nt,@lt); # in hour
|
||||||
my ($rt,$st) = _sr($needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff);
|
|
||||||
|
|
||||||
my $nh = $lt[2] + $lt[1]/60 + $lt[0]/3600;
|
my ($rt,$st) = _sr($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) {
|
if($daycheck) {
|
||||||
return 0 if($nh < $rt || $nh > $st);
|
return 0 if($nh < $rt || $nh > $st);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 0 if(!$seconds);
|
|
||||||
my $sst = ($rise ? $rt : $st);
|
|
||||||
if(!$isrel) {
|
|
||||||
$sst += ($seconds/3600);
|
|
||||||
return h2hms_fmt($sst);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sst += ($seconds/3600);
|
|
||||||
|
|
||||||
my $diff = 0;
|
my $diff = 0;
|
||||||
if(int(($nh-$sst)*3600) >= 0) {
|
if($data{AT_RECOMPUTE} || # compute it for tommorow
|
||||||
$nt += 86400; # Tommorow
|
int(($nh-$sst)*3600) >= 0) { # if called a subsec earlier
|
||||||
|
$nt += 86400;
|
||||||
$diff = 24;
|
$diff = 24;
|
||||||
@lt = localtime($nt);
|
@lt = localtime($nt);
|
||||||
$gmtoff = _calctz($nt,@lt); # in hour
|
$gmtoff = _calctz($nt,@lt); # in hour
|
||||||
|
|
||||||
($rt,$st) = _sr($needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff);
|
($rt,$st) = _sr($needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff);
|
||||||
|
$sst = ($rise ? $rt : $st) + ($seconds/3600);
|
||||||
$sst = ($rise ? $rt : $st);
|
|
||||||
$sst += ($seconds/3600);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$diff = $diff + $sst - $nh;
|
$sst = hms2h($min) if(defined($min) && (hms2h($min) > $sst));
|
||||||
return h2hms_fmt($diff);
|
$sst = hms2h($max) if(defined($max) && (hms2h($max) < $sst));
|
||||||
|
|
||||||
|
$sst += $diff if($isrel);
|
||||||
|
$sst -= $nh if($isrel == 1);
|
||||||
|
|
||||||
|
return h2hms_fmt($sst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub
|
sub
|
||||||
_sr($$$$$$)
|
_sr($$$$$$)
|
||||||
{
|
{
|
||||||
@ -304,6 +304,15 @@ _calctz($@)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub
|
||||||
|
hms2h($)
|
||||||
|
{
|
||||||
|
my $in = shift;
|
||||||
|
my @a = split(":", $in);
|
||||||
|
return 0 if(int(@a) < 2 || $in !~ m/^[\d:]*$/);
|
||||||
|
return $a[0]+$a[1]/60 + ($a[2] ? $a[2]/3600 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
h2hms($)
|
h2hms($)
|
||||||
{
|
{
|
||||||
@ -324,11 +333,13 @@ h2hms_fmt($)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub sunrise_rel(@) { return sr(1, shift, 1, 0) }
|
sub sunrise_rel(@) { return sr(1, shift, 1, 0, shift, shift) }
|
||||||
sub sunset_rel(@) { return sr(0, shift, 1, 0) }
|
sub sunset_rel(@) { return sr(0, shift, 1, 0, shift, shift) }
|
||||||
sub sunrise_abs(@) { return sr(1, shift, 0, 0) }
|
sub sunrise_abs(@) { return sr(1, shift, 0, 0, shift, shift) }
|
||||||
sub sunset_abs(@) { return sr(0, shift, 0, 0) }
|
sub sunset_abs(@) { return sr(0, shift, 0, 0, shift, shift) }
|
||||||
sub isday() { return sr(1, 0, 0, 1) }
|
sub sunrise(@) { return sr(1, shift, 2, 0, shift, shift) }
|
||||||
|
sub sunset(@) { return sr(0, shift, 2, 0, shift, shift) }
|
||||||
|
sub isday() { return sr(1, 0, 0, 1, undef, undef) }
|
||||||
sub sunrise_coord($$$) { ($long, $lat, $tz) = @_; return undef; }
|
sub sunrise_coord($$$) { ($long, $lat, $tz) = @_; return undef; }
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
4
HISTORY
4
HISTORY
@ -396,3 +396,7 @@
|
|||||||
- pgm3: bugfix, format table for userdef
|
- pgm3: bugfix, format table for userdef
|
||||||
- pgm3: feature X10_support, taillogorder optional with date
|
- pgm3: feature X10_support, taillogorder optional with date
|
||||||
- pgm3: HMS100CO added, fhem.html relating pgm3 updated
|
- pgm3: HMS100CO added, fhem.html relating pgm3 updated
|
||||||
|
|
||||||
|
- Sat May 30 2009 (Rudi)
|
||||||
|
- 99_SUNRISE_EL: sunrise/sunset called in "at" computes correctly the next
|
||||||
|
event. New "sunrise()/sunset()" calls added, min max optional parameter.
|
||||||
|
@ -2848,10 +2848,14 @@ A line ending with \ will be concatenated with the next one, so long lines
|
|||||||
define a12 at +*{sunset_rel()} { fhem("set lamp on-till 23:00") if($we) }
|
define a12 at +*{sunset_rel()} { fhem("set lamp on-till 23:00") if($we) }
|
||||||
|
|
||||||
# Switch lamp1 and lamp2 on from 7:00 till 10 minutes after sunrise
|
# Switch lamp1 and lamp2 on from 7:00 till 10 minutes after sunrise
|
||||||
define a13 at *07:00 set lamp1,lamp2 on-till {sunrise_abs(+600)}
|
define a13 at *07:00 set lamp1,lamp2 on-till {sunrise(+600)}
|
||||||
|
|
||||||
# Switch the lamp off 2 minutes after sunrise each day
|
# Switch the lamp off 2 minutes after sunrise each day
|
||||||
define a14 at +*{sunrise_rel(+120)} set lamp on
|
define a14 at +{sunrise(+120)} set lamp on
|
||||||
|
|
||||||
|
# Switch lamp1 on at sunset, not before 18:00 and not after 21:00
|
||||||
|
define a15 at *{sunset(0,"18:00","21:00")} set lamp1 on
|
||||||
|
|
||||||
</PRE>
|
</PRE>
|
||||||
|
|
||||||
Notes:<br>
|
Notes:<br>
|
||||||
@ -2864,11 +2868,9 @@ A line ending with \ will be concatenated with the next one, so long lines
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>if the current time is greater than the time specified, then the
|
<li>if the current time is greater than the time specified, then the
|
||||||
command will be executed tomorrow. This is why the relative forms
|
command will be executed tomorrow.</li>
|
||||||
of the sunset/sunrise functions should be used with the relative
|
|
||||||
(+) flag</li>
|
|
||||||
|
|
||||||
<li>In order to use the sunrise_rel()/sunset_rel() functions,
|
<li>In order to use the sunrise()/sunset() functions,
|
||||||
put { sunrise_coord(long, lat, "") } into your
|
put { sunrise_coord(long, lat, "") } into your
|
||||||
<a href="#lastinclude">lastinclude</a> file, as in the above example.
|
<a href="#lastinclude">lastinclude</a> file, as in the above example.
|
||||||
If you are not using sunrise_coord, then the coordinates for
|
If you are not using sunrise_coord, then the coordinates for
|
||||||
@ -3420,25 +3422,32 @@ A line ending with \ will be concatenated with the next one, so long lines
|
|||||||
<h3>SUNRISE_EL</h3>
|
<h3>SUNRISE_EL</h3>
|
||||||
<ul>
|
<ul>
|
||||||
This module is used to define the functions<pre>
|
This module is used to define the functions<pre>
|
||||||
|
sunrise, sunset,
|
||||||
sunrise_rel, sunset_rel
|
sunrise_rel, sunset_rel
|
||||||
sunrise_abs, sunset_abs
|
sunrise_abs, sunset_abs
|
||||||
isday, sunrise_coord</pre>
|
isday, sunrise_coord</pre>
|
||||||
perl functions, to be used in <a href="#at">at</a> or <a
|
perl functions, to be used in <a href="#at">at</a> or FS20 on-till commands.<br>
|
||||||
href="#notify">notify</a> commands.<br>
|
|
||||||
First you should call the sunrise_coord function with your exact longitude
|
First you should call the sunrise_coord function with your exact longitude
|
||||||
and latitude (see e.g. maps.google.com for the exact values, which should be
|
and latitude (see e.g. maps.google.com for the exact values, which should be
|
||||||
in the form of a floating point value). This command should be part of the
|
in the form of a floating point value). This command should be part of the
|
||||||
<a href="#lastinclude">lastinclude</a> file. The default value is Frankfurt
|
<a href="#lastinclude">lastinclude</a> file. The default value is Frankfurt
|
||||||
am Main, Germany.<br><br>
|
am Main, Germany.<br><br>
|
||||||
|
|
||||||
sunrise_rel()/sunset_rel() return the relative time to the next
|
sunrise()/sunset() returns the absolute time of the next sunrise/sunset,
|
||||||
sunrise/sunset. The argument (in seconds) will be added to this time. The
|
adding 24 hours if the next event is tomorrow, to use it in the timespec of
|
||||||
relative values should be used as arguments to the <a href="#at">at</a>, see
|
an at device or for the on-till command for FS20 devices.<br>
|
||||||
the examples there for details.<br><br>
|
|
||||||
|
|
||||||
sunrise_abs()/sunset_abs() return the absolute time to the next
|
sunrise_rel()/sunset_rel() returns the relative time to the next
|
||||||
sunrise/sunset, with the argument added to the time. These are used e.g. in
|
sunrise/sunset. <br>
|
||||||
arguments to the "on-till" FS20 command.<br><br>
|
sunrise_abs()/sunset_abs() return the absolute time of the corresponding
|
||||||
|
event today (no 24 hours added).<br>
|
||||||
|
All functions take up to three arguments:<br>
|
||||||
|
<ul>
|
||||||
|
<li>The first specifies an offset (in seconds), which will be added to the
|
||||||
|
event.
|
||||||
|
<li>The second and third specify min and max values (format: "HH:MM").
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
|
||||||
isday() can be used in some notify or at commands to check if the sun is up or
|
isday() can be used in some notify or at commands to check if the sun is up or
|
||||||
down.
|
down.
|
||||||
|
@ -251,7 +251,7 @@ by fhem.pl?</b>
|
|||||||
receiver or with googleearth. Compute the latitude/longitude as needed, and
|
receiver or with googleearth. Compute the latitude/longitude as needed, and
|
||||||
enter them in your lastinclude file with the command:
|
enter them in your lastinclude file with the command:
|
||||||
<pre>{sunrise_coord("<latitude>", "<longitude>", "") }</pre>
|
<pre>{sunrise_coord("<latitude>", "<longitude>", "") }</pre>
|
||||||
After restart, { sunrise_abs() } will return the time of the sunrise today,
|
After restart, { sunrise() } will return the time of the next sunrise,
|
||||||
in a HH:MM:SS format.<br><br>
|
in a HH:MM:SS format.<br><br>
|
||||||
|
|
||||||
Note: 99_SUNRISE_EL.pm is the ExtraLight version of the original
|
Note: 99_SUNRISE_EL.pm is the ExtraLight version of the original
|
||||||
|
@ -34,11 +34,11 @@ define a11 at +*{sunset_rel()} { fhem("set lamp on-till 23:00") if($we) }
|
|||||||
|
|
||||||
##################################
|
##################################
|
||||||
# Switch lamp1 and lamp2 on from 7:00 till 10 minutes after sunrise
|
# Switch lamp1 and lamp2 on from 7:00 till 10 minutes after sunrise
|
||||||
define a12 at *07:00 set lamp1,lamp2 on-till {sunrise_abs(+600)}
|
define a12 at *07:00 set lamp1,lamp2 on-till {sunrise(+600)}
|
||||||
|
|
||||||
##################################
|
##################################
|
||||||
# Switch lamp1 on at sunrise, but not before 07:00
|
# Switch lamp1 on at sunrise, but not before 07:00 and not after 09:00
|
||||||
define a13 at +*{max(abstime2rel("07:00"),sunrise_rel())} set lamp1 on
|
define a13 at +*{sunrise(0,"07:00","09:00"))} set lamp1 on
|
||||||
|
|
||||||
##################################
|
##################################
|
||||||
# Blink 3 times if the piri sends a command
|
# Blink 3 times if the piri sends a command
|
||||||
|
Loading…
x
Reference in New Issue
Block a user