2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

59_Twilight.pm: bring back some events at def time, bugfixes; 98_RandomTimer: enhance commandref

git-svn-id: https://svn.fhem.de/fhem/trunk@23030 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2020-10-26 18:21:34 +00:00
parent 7e1698a1d7
commit 799870743c
2 changed files with 27 additions and 24 deletions

View File

@ -168,7 +168,7 @@ sub Twilight_Define {
my $useTimer = looks_like_number($weather) || ( $DEFmayChange && $latitude == AttrVal( 'global', 'latitude', 50.112 ) && $longitude == AttrVal( 'global', 'longitude', 8.686 ) ) ? 1 : 0; my $useTimer = looks_like_number($weather) || ( $DEFmayChange && $latitude == AttrVal( 'global', 'latitude', 50.112 ) && $longitude == AttrVal( 'global', 'longitude', 8.686 ) ) ? 1 : 0;
$hash->{DEFINE} = $weather ? $weather : 1; $hash->{DEFINE} = $weather ? $weather : "none";
InternalTimer(time(), \&Twilight_Change_DEF,$hash,0) if $useTimer; InternalTimer(time(), \&Twilight_Change_DEF,$hash,0) if $useTimer;
return InternalTimer( time()+$useTimer, \&Twilight_Firstrun,$hash,0) if !$init_done || $useTimer; return InternalTimer( time()+$useTimer, \&Twilight_Firstrun,$hash,0) if !$init_done || $useTimer;
@ -381,7 +381,7 @@ sub Twilight_Firstrun {
my $extWeatherVal = 0; my $extWeatherVal = 0;
if ($attrVal) { if ($attrVal && $attrVal ne "none") {
Twilight_init_ExtWeather_usage( $hash, $attrVal ); Twilight_init_ExtWeather_usage( $hash, $attrVal );
$extWeatherVal = ReadingsNum( $name, "cloudCover", ReadingsNum( $hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{Reading}, 0 ) ); $extWeatherVal = ReadingsNum( $name, "cloudCover", ReadingsNum( $hash->{helper}{extWeather}{Device}, $hash->{helper}{extWeather}{Reading}, 0 ) );
readingsSingleUpdate ( $hash, "cloudCover", $extWeatherVal, 0 ) if $extWeatherVal; readingsSingleUpdate ( $hash, "cloudCover", $extWeatherVal, 0 ) if $extWeatherVal;
@ -394,8 +394,9 @@ sub Twilight_Firstrun {
#return Twilight_HandleWeatherData( $hash, 0); #return Twilight_HandleWeatherData( $hash, 0);
my $fnHash = { HASH => $hash }; my $fnHash = { HASH => $hash };
Twilight_sunpos($fnHash) if !$attrVal; Twilight_sunpos($fnHash) if !$attrVal || $attrVal eq "none";
Twilight_Midnight($fnHash, 1); Twilight_Midnight($fnHash, 1);
delete $hash->{DEFINE}; delete $hash->{DEFINE};
return; return;
@ -616,7 +617,7 @@ sub Twilight_TwilightTimes {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $swip = !$firstrun; my $swip = $firstrun;
my $lat = $hash->{helper}{'.LATITUDE'}; my $lat = $hash->{helper}{'.LATITUDE'};
my $long = $hash->{helper}{'.LONGITUDE'}; my $long = $hash->{helper}{'.LONGITUDE'};
@ -644,8 +645,8 @@ sub Twilight_TwilightTimes {
$hash->{TW}{$ss}{LIGHT} = $idx; $hash->{TW}{$ss}{LIGHT} = $idx;
$hash->{TW}{$sr}{STATE} = $idx + 1; $hash->{TW}{$sr}{STATE} = $idx + 1;
$hash->{TW}{$ss}{STATE} = 12 - $idx; $hash->{TW}{$ss}{STATE} = 12 - $idx;
#$hash->{TW}{$sr}{SWIP} = $swip; $hash->{TW}{$sr}{SWIP} = $swip;
#$hash->{TW}{$ss}{SWIP} = $swip; $hash->{TW}{$ss}{SWIP} = $swip;
( $hash->{TW}{$sr}{TIME}, $hash->{TW}{$ss}{TIME} ) = ( $hash->{TW}{$sr}{TIME}, $hash->{TW}{$ss}{TIME} ) =
Twilight_calc( $hash, $deg, $idx ); Twilight_calc( $hash, $deg, $idx );
@ -682,13 +683,13 @@ sub Twilight_TwilightTimes {
my $now = time(); my $now = time();
#my @keyListe = qw "DEG LIGHT STATE SWIP TIME NAMENEXT"; #my @keyListe = qw "DEG LIGHT STATE SWIP TIME NAMENEXT";
my @keyListe = qw "DEG LIGHT STATE TIME NAMENEXT"; #my @keyListe = qw "DEG LIGHT STATE TIME NAMENEXT";
for my $ereignis ( sort keys %{ $hash->{TW} } ) { for my $ereignis ( sort keys %{ $hash->{TW} } ) {
next if ( $whitchTimes eq "weather" && !( $ereignis =~ m/weather/ ) ); next if ( $whitchTimes eq "weather" && !( $ereignis =~ m/weather/ ) );
deleteSingleRegisteredInternalTimer( $ereignis, $hash, \&Twilight_fireEvent ); deleteSingleRegisteredInternalTimer( $ereignis, $hash, \&Twilight_fireEvent );
if ( defined $hash->{TW}{$ereignis}{TIME} && $hash->{TW}{$ereignis}{TIME} > $now ) { # had been > 0 if ( defined $hash->{TW}{$ereignis}{TIME} && ($hash->{TW}{$ereignis}{TIME} > $now || $firstrun) ) { # had been > 0
#my $fnHash = #my $fnHash =
setRegisteredInternalTimer( $ereignis, $hash->{TW}{$ereignis}{TIME}, setRegisteredInternalTimer( $ereignis, $hash->{TW}{$ereignis}{TIME},
\&Twilight_fireEvent, $hash, 0 ); \&Twilight_fireEvent, $hash, 0 );
@ -696,6 +697,7 @@ sub Twilight_TwilightTimes {
} }
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
return 1; return 1;
} }
@ -717,7 +719,7 @@ sub Twilight_fireEvent {
my $deg = $myHash->{DEG}; my $deg = $myHash->{DEG};
my $light = $myHash->{LIGHT}; my $light = $myHash->{LIGHT};
my $state = $myHash->{STATE}; my $state = $myHash->{STATE};
#my $swip = $myHash->{SWIP}; my $swip = $myHash->{SWIP};
my $eventTime = $myHash->{TIME}; my $eventTime = $myHash->{TIME};
my $nextEvent = $myHash->{NAMENEXT}; my $nextEvent = $myHash->{NAMENEXT};
@ -731,8 +733,8 @@ sub Twilight_fireEvent {
: "undefined"; : "undefined";
my $doTrigger = !( defined( $hash->{LOCAL} ) ) my $doTrigger = !( defined( $hash->{LOCAL} ) )
#&& ( abs($delta) < 6 || $swip && $state gt $oldState ); && ( abs($delta) < 6 || $swip && $state gt $oldState );
&& ( abs($delta) < 6 || $state gt $oldState ); #&& ( abs($delta) < 6 || $state gt $oldState );
Log3( Log3(
$hash, 4, $hash, 4,
@ -764,18 +766,19 @@ sub Twilight_Midnight {
#my $hash = Twilight_GetHashIndirekt( $fnHash, ( caller(0) )[3] ); #my $hash = Twilight_GetHashIndirekt( $fnHash, ( caller(0) )[3] );
return if ( !defined($hash) ); return if ( !defined($hash) );
if (!defined $hash->{helper}{extWeather}{Device} || $firstrun) { if (!defined $hash->{helper}{extWeather}{Device}) { # || $firstrun) {
Twilight_TwilightTimes( $hash, "mid", $firstrun); Twilight_TwilightTimes( $hash, "mid", $firstrun);
Twilight_sunposTimerSet($hash); #Twilight_sunposTimerSet($hash);
Twilight_sunpos({HASH => $hash});
} else { } else {
Twilight_HandleWeatherData( $hash, 0); Twilight_HandleWeatherData( $hash, 0);
Twilight_TwilightTimes( $hash, "mid", $firstrun); Twilight_TwilightTimes( $hash, "mid", $firstrun);
} }
my $now = time(); my $now = time();
my $midnight = $now - secondsSinceMidnight( $now ) + DAYSECONDS + 1; my $midnight = $now - secondsSinceMidnight( $now ) + DAYSECONDS + 1;
my $daysavingdelta = (localtime)[2] - ( localtime( time + DAYSECONDS ) )[2]; my $daylightsavingdelta = (localtime ( time - 2 * HOURSECONDS ) )[2] - ( localtime( time + 22 * HOURSECONDS ) )[2];
$midnight -= 19 * HOURSECONDS if $daysavingdelta == 1 && (localtime)[2] < 3; $midnight -= 19 * HOURSECONDS if $daylightsavingdelta == 1 && (localtime)[2] < 2;
$midnight -= 20 * HOURSECONDS if $daysavingdelta == -1 && (localtime)[2] < 3; $midnight -= 20 * HOURSECONDS if $daylightsavingdelta == -1 && (localtime)[2] < 3;
return resetRegisteredInternalTimer( "Midnight", $midnight, \&Twilight_Midnight, $hash, 0 ); return resetRegisteredInternalTimer( "Midnight", $midnight, \&Twilight_Midnight, $hash, 0 );
@ -946,7 +949,7 @@ sub Twilight_sunpos {
int( ( $dElevation - $hash->{WEATHER_HORIZON} + 12.0 ) / 18.0 * int( ( $dElevation - $hash->{WEATHER_HORIZON} + 12.0 ) / 18.0 *
1000 ) / 10; 1000 ) / 10;
Log3( $hash, 3, Log3( $hash, 3,
"[$hashName] No useable cloudCover value available: ${$extWeatherHorizont}, taking existant weather horizon." ); "[$hashName] No useable cloudCover value available: ${extWeatherHorizont}, taking existant weather horizon." );
} }
} }
@ -1106,7 +1109,7 @@ __END__
NOTE 1: using useExtWeather attribute may override settings in DEF. NOTE 1: using useExtWeather attribute may override settings in DEF.
<br> <br>
<br> <br>
NOTE 2: If weatherDevice-type is known, <Reading> is optional (atm only "Weather"-type devices are supported). NOTE 2: If weatherDevice-type is known, <Reading> is optional (atm only "Weather" or "PROPLANTA" type devices are supported).
<br> <br>
A Twilight device periodically calculates the times of different twilight phases throughout the day. A Twilight device periodically calculates the times of different twilight phases throughout the day.
It calculates a virtual "light" element, that gives an indicator about the amount of the current daylight. It calculates a virtual "light" element, that gives an indicator about the amount of the current daylight.
@ -1257,7 +1260,7 @@ Example:
<br><br> <br><br>
Hinweis 1: Eventuelle Angaben im useExtWeather-Attribut &uumlberschreiben die Angaben im define. Hinweis 1: Eventuelle Angaben im useExtWeather-Attribut &uumlberschreiben die Angaben im define.
<br> <br>
Hinweis 2: Bei bekannten Wetter-Device-Typen (im Moment ausschließlich: Weather) ist die Angabe des Readings optional. Hinweis 2: Bei bekannten Wetter-Device-Typen (im Moment ausschließlich: Weather oder PROPLANTA) ist die Angabe des Readings optional.
<br> <br>
<br> <br>
Ein Twilight-Device berechnet periodisch die D&auml;mmerungszeiten und -phasen w&auml;hrend des Tages. Ein Twilight-Device berechnet periodisch die D&auml;mmerungszeiten und -phasen w&auml;hrend des Tages.
@ -1289,7 +1292,7 @@ Wissenswert dazu ist, dass die Sonne, abh&auml;gnig vom Breitengrad, bestimmte E
Beispiel: Beispiel:
<pre> <pre>
define myTwilight Twilight 49.962529 10.324845 4.5 MeinWetter_cloudCover define myTwilight Twilight 49.962529 10.324845 4.5 MeinWetter:cloudCover
</pre> </pre>
</ul> </ul>
<br> <br>

View File

@ -760,7 +760,7 @@ __END__
<b>Define</b> <b>Define</b>
<ul> <ul>
<code> <code>
define &lt;name&gt; RandomTimer &lt;timespec_start&gt; &lt;device&gt; &lt;timespec_stop&gt; &lt;timeToSwitch&gt; define &lt;name&gt; RandomTimer &lt;timespec_start&gt; &lt;device&gt; &lt;timespec_stop&gt; &lt;timeToSwitch&gt; [&lt;[VAR_DURATION][:VAR_START]&gt;]
</code> </code>
<br> <br>
Defines a device, that imitates the random switch functionality of a timer clock, like a <b>FS20 ZSU</b>. The idea to create it, came from the problem, that is was always a little bit tricky to install a timer clock before holiday: finding the manual, testing it the days before and three different timer clocks with three different manuals - a horror.<br> Defines a device, that imitates the random switch functionality of a timer clock, like a <b>FS20 ZSU</b>. The idea to create it, came from the problem, that is was always a little bit tricky to install a timer clock before holiday: finding the manual, testing it the days before and three different timer clocks with three different manuals - a horror.<br>
@ -796,11 +796,11 @@ __END__
The optional parameters <b>variations</b> will modify <i>timeToSwitch</i> and/or <i>timespec_start</i>, syntax is [VAR_DURATION][:VAR_START].<br> The optional parameters <b>variations</b> will modify <i>timeToSwitch</i> and/or <i>timespec_start</i>, syntax is [VAR_DURATION][:VAR_START].<br>
<ul> <ul>
<li>VAR_DURATION will turn <i>timeToSwitch</i> to a minimum value with some random seconds between zero and VAR_DURATION will be added.</li> <li>VAR_DURATION will turn <i>timeToSwitch</i> to a minimum value with some random seconds between zero and VAR_DURATION will be added.</li>
<li>VAR_START will modify <i>timespec_start</i> by adding some random seconds between zero and VAR_START.</li> <li>VAR_START will modify <i>timespec_start</i> by adding some random number of seconds (between zero and VAR_START).</li>
<b>Examples:</b><br> <b>Examples:</b><br>
Add something between 0 and 10 minutes to <i>timeToSwitch</i>:<br> Add something between 0 and 10 minutes to <i>timeToSwitch</i>:<br>
<code>defmod Zufall1 RandomTimer *06:00 MYSENSOR_98 22:00:00 3600 600</code><br> <code>defmod Zufall1 RandomTimer *06:00 MYSENSOR_98 22:00:00 3600 600</code><br>
Randomize day's first check by half an hour:<br> Randomize day's first check by up to half an hour:<br>
<code>defmod Zufall1 RandomTimer *06:00 MYSENSOR_98 22:00:00 3600 :1800</code><br> <code>defmod Zufall1 RandomTimer *06:00 MYSENSOR_98 22:00:00 3600 :1800</code><br>
Do both:<br> Do both:<br>
<code>defmod Zufall1 RandomTimer *06:00 MYSENSOR_98 22:00:00 3600 600:1800</code><br> <code>defmod Zufall1 RandomTimer *06:00 MYSENSOR_98 22:00:00 3600 600:1800</code><br>
@ -814,7 +814,7 @@ __END__
<code> <code>
define ZufallsTimerTisch RandomTimer *{sunset_abs()} StehlampeTisch +03:00:00 500 define ZufallsTimerTisch RandomTimer *{sunset_abs()} StehlampeTisch +03:00:00 500
</code><br> </code><br>
defines a timer that starts at sunset an ends 3 hous later. The timer trys to switch every 500 seconds(+-10%). defines a timer that starts at sunset an ends 3 hous later. Every 500 seconds(+-10%), the timer will perform an evaluation of the parameters to decide whether the device has to be switched or not.
</li><br> </li><br>
<li> <li>
<code> <code>