mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: Implament IsWe (Forum #98583)
git-svn-id: https://svn.fhem.de/fhem/trunk@18922 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4810493c2a
commit
52cfc75496
@ -1818,8 +1818,10 @@ The following local attributes are used by a wider range of devices:
|
||||
fhem "set light on" } }<br>
|
||||
define roll_en *07:45:00 { fhem "trigger SwitchAllRoll on" if(!$we) }<br>
|
||||
define roll_en *08:30:00 { fhem "trigger SwitchAllRoll on" if($we) }<br>
|
||||
|
||||
</ul>
|
||||
$we is equivalent to calling IsWe(), which optionally takes the arguments
|
||||
"today", "yesterday" and "tomorrow". Note: for everything else "today" is
|
||||
assumed without an error message.<br>
|
||||
<br>
|
||||
|
||||
<li>
|
||||
|
@ -1950,19 +1950,20 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
aktuellen Datum in YYYY-MM-DD Format.
|
||||
<br>
|
||||
|
||||
Die Variabe <var>$we</var> hat den Wert 1 wenn der abgefragte Tag auf ein Wochenende
|
||||
fällt (Z.B. <var>$wday</var> == 0 [Sonntag] oder <var>$wday</var> == 6 [Samstag]), und 0
|
||||
für die anderen Wochentage. Wenn man das global <a
|
||||
href="#holiday2we">holiday2we</a> Attribut setzt, dann ist <var>$we</var> ebenfalls 1
|
||||
bei Urlaubstagen.<br>
|
||||
|
||||
Die Variabe <var>$we</var> hat den Wert 1 wenn der abgefragte Tag auf ein
|
||||
Wochenende fällt (Z.B. <var>$wday</var> == 0 [Sonntag] oder
|
||||
<var>$wday</var> == 6 [Samstag]), und 0 für die anderen Wochentage.
|
||||
Wenn man das global <a href="#holiday2we">holiday2we</a> Attribut setzt,
|
||||
dann ist <var>$we</var> ebenfalls 1 bei Urlaubstagen.<br>
|
||||
<ul>
|
||||
define n2 notify piri:on { if($hour > 18 || $hour < 5) {
|
||||
fhem "set light on" } }<br>
|
||||
define roll_en *07:45:00 { fhem "trigger SwitchAllRoll on" if(!$we) }<br>
|
||||
define roll_en *08:30:00 { fhem "trigger SwitchAllRoll on" if($we) }<br>
|
||||
|
||||
</ul>
|
||||
$we wird mit IsWe() gesetzt, diese Funktion nimmt optional die Argumente
|
||||
"today", "yesterday" und "tomorrow". Achtung: alles andere wird als "today"
|
||||
interpretiert, ohne eine Fehlermeldung zu generieren.
|
||||
<br>
|
||||
|
||||
</li><li>
|
||||
|
34
fhem/fhem.pl
34
fhem/fhem.pl
@ -81,6 +81,7 @@ sub IsDisabled($);
|
||||
sub IsDummy($);
|
||||
sub IsIgnored($);
|
||||
sub IsIoDummy($);
|
||||
sub IsWe(;$$);
|
||||
sub LoadModule($;$);
|
||||
sub Log($$);
|
||||
sub Log3($$$);
|
||||
@ -1105,17 +1106,10 @@ AnalyzePerlCommand($$;$)
|
||||
}
|
||||
my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
|
||||
localtime(gettimeofday());
|
||||
my $hms = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
|
||||
my $we = (($wday==0 || $wday==6) ? 1 : 0);
|
||||
if(!$we) {
|
||||
foreach my $h2we (split(",", AttrVal("global", "holiday2we", ""))) {
|
||||
my ($a, $b) = ReplaceEventMap($h2we, [$h2we, Value($h2we)], 0);
|
||||
$we = 1 if($b && $b ne "none");
|
||||
}
|
||||
}
|
||||
$month++;
|
||||
$year+=1900;
|
||||
$month++; $year+=1900;
|
||||
my $today = sprintf('%04d-%02d-%02d', $year,$month,$mday);
|
||||
my $hms = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
|
||||
my $we = IsWe(undef, $wday);
|
||||
|
||||
if($evalSpecials) {
|
||||
$cmd = join("", map { my $n = substr($_,1); # ignore the %
|
||||
@ -5898,4 +5892,24 @@ sub genUUID()
|
||||
$fuuidHash{$uuid} = 1;
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
sub
|
||||
IsWe(;$$)
|
||||
{
|
||||
my ($when, $wday) = @_;
|
||||
$wday = (localtime(gettimeofday()))[6] if(!defined($wday));
|
||||
$when = "state" if(!$when || $when !~ m/^(yesterday|tomorrow)$/);
|
||||
|
||||
my $we = ($when eq "yesterday" ? ($wday==0 || $wday==1) :
|
||||
($when eq "state" ? ($wday==6 || $wday==0) :
|
||||
($wday==5 || $wday==6))); # tomorrow
|
||||
if(!$we) {
|
||||
foreach my $h2we (split(",", AttrVal("global", "holiday2we", ""))) {
|
||||
my $b = ReadingsVal($h2we, $when, 0);
|
||||
$we = 1 if($b && $b ne "none");
|
||||
}
|
||||
}
|
||||
return $we ? 1 : 0;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user