From 76201682dfb7d5c0a07d22cc9e9ea67a44062a64 Mon Sep 17 00:00:00 2001 From: dietmar63 <> Date: Sun, 4 Dec 2016 21:42:11 +0000 Subject: [PATCH] 98_Heating_Control, 98_WeekdayTimer: a bug fixed when starting a WDT or a HC an trying to switch in the past. now being able to use on-till:13:30:30 as a parameter the parameter can now be a Perlcode git-svn-id: https://svn.fhem.de/fhem/trunk@12715 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_Heating_Control.pm | 98 ++++++++++++++++++++++++------- fhem/FHEM/98_WeekdayTimer.pm | 100 +++++++++++++++++++++++--------- 2 files changed, 149 insertions(+), 49 deletions(-) diff --git a/fhem/FHEM/98_Heating_Control.pm b/fhem/FHEM/98_Heating_Control.pm index b97037a4e..ebf7f0ccf 100644 --- a/fhem/FHEM/98_Heating_Control.pm +++ b/fhem/FHEM/98_Heating_Control.pm @@ -211,7 +211,7 @@ sub Heating_Control_SetAllTemps() { # {Heating_Control_SetAllTemps()} The parameter $NAME and $EVENT will be interpreted.

- Example: + Examples:

@@ -391,7 +443,7 @@ sub Heating_Control_SetAllTemps() { # {Heating_Control_SetAllTemps()} Die Parameter $NAME und $EVENT werden interpretiert.

- Beispiel: + Beispiele:

diff --git a/fhem/FHEM/98_WeekdayTimer.pm b/fhem/FHEM/98_WeekdayTimer.pm index aa5c5dbed..13eab7711 100644 --- a/fhem/FHEM/98_WeekdayTimer.pm +++ b/fhem/FHEM/98_WeekdayTimer.pm @@ -590,13 +590,15 @@ sub WeekdayTimer_SetTimer($) { my ($aktIdx,$aktTime,$aktParameter,$nextTime,$nextParameter) = WeekdayTimer_searchAktNext($hash, time()+5); + if(!defined $aktTime) { + Log3 $hash, 3, "[$name] can not compute past switching time"; + } readingsSingleUpdate ($hash, "nextUpdate", FmtDateTime($nextTime), 1); readingsSingleUpdate ($hash, "nextValue", $nextParameter, 1); readingsSingleUpdate ($hash, "currValue", $aktParameter, 1); # HB - - if ($switchInThePast) { + if ($switchInThePast && defined $aktTime) { # Fensterkontakte abfragen - wenn einer im Status closed, dann Schaltung um 60 Sekunden verzögern if (WeekdayTimer_FensterOffen($hash, $aktParameter, $aktIdx)) { return; @@ -712,7 +714,7 @@ sub WeekdayTimer_Update($) { # Schaltparameter ermitteln my $tage = $hash->{profil}{$idx}{TAGE}; my $time = $hash->{profil}{$idx}{TIME}; - my $newParam = $hash->{profil}{$idx}{PARA}; + my $newParam = WeekdayTimer_evalAndcleanupParam($hash,$time,$hash->{profil}{$idx}{PARA}); #Log3 $hash, 3, "[$name] $idx ". $time . " " . $newParam . " " . join("",@$tage); @@ -940,13 +942,45 @@ sub WeekdayTimer_FensterOffen ($$$) { delete $hash->{VERZOEGRUNG_IDX} if defined($hash->{VERZOEGRUNG_IDX}); return 0; } + +################################################################################ +sub WeekdayTimer_evalAndcleanupParam($$$) { + my ($hash,$time,$param) = @_; + + my $name = $hash->{DEVICE} ; + my $wdName = $hash->{NAME}; + + my $newParam = $param; + if ($param =~ m/^{.*}$/) { + + Log3 $hash, 4, "[$wdName] calculating dynamic param before all: ....... $newParam"; + + $newParam =~ s/\$NAME/$hash->{DEVICE}/g; + $newParam =~ s/\$TIME/$time/g; + Log3 $hash, 4, "[$wdName] calculating dynamic param after substitutions: $newParam"; + + $newParam = eval $newParam; + if ($@ || not defined $newParam) { + Log3 $hash, 1, "[$wdName] problem calculating dynamic param: ........... $param"; + Log3 $hash, 1, "[$wdName] $@"; + } else { + Log3 $hash, 4, "[$wdName] calculating dynamic param after eval: ........ $newParam"; + } + + }elsif($param =~ m/^\d{1,3}$/){ + $newParam = sprintf("%.1f", $param); + } + return $newParam; +} + ################################################################################ sub WeekdayTimer_Device_Schalten($$$) { my ($hash, $newParam, $tage) = @_; my ($command, $condition, $tageAsHash) = ""; - my $name = $hash->{NAME}; ### - + my $name = $hash->{NAME}; ### + my $dummy = ""; + my $now = time(); #modifier des Zieldevices auswaehlen my $setModifier = WeekdayTimer_isHeizung($hash); @@ -957,10 +991,9 @@ sub WeekdayTimer_Device_Schalten($$$) { my $activeTimer = 1; my $isHeating = $setModifier gt ""; - my $aktParam = ReadingsVal($hash->{DEVICE}, $setModifier, ""); - $aktParam = sprintf("%.1f", $aktParam) if ($isHeating && $aktParam =~ m/^[0-9]{1,3}$/i); - $newParam = sprintf("%.1f", $newParam) if ($isHeating && $newParam =~ m/^[0-9]{1,3}$/i); - + my $aktParam = WeekdayTimer_evalAndcleanupParam($hash,$dummy,ReadingsVal($hash->{DEVICE}, $setModifier, "")); + # newParam is already processed by evalAndcleanupParam() + my $disabled = AttrVal($hash->{NAME}, "disable", 0); my $disabled_txt = $disabled ? " " : " not"; Log3 $hash, 4, "[$name] aktParam:$aktParam newParam:$newParam - is $disabled_txt disabled"; @@ -969,7 +1002,7 @@ sub WeekdayTimer_Device_Schalten($$$) { if ($command && !$disabled && $activeTimer && $aktParam ne $newParam ) { - $newParam =~ s/:/ /g; + $newParam =~ s/:/ /; my %specials = ( "%NAME" => $hash->{DEVICE}, "%EVENT" => $newParam); $command= EvalSpecials($command, %specials); @@ -1058,6 +1091,9 @@ sub WeekdayTimer_SetAllParms() { # {WeekdayTimer_SetAllParms()} 1; =pod +=item device +=item summary sends parameter to devices at defined times +=item summary_DE sendet Parameter an devices zu einer Liste mit festen Zeiten =begin html @@ -1116,6 +1152,7 @@ sub WeekdayTimer_SetAllParms() { # {WeekdayTimer_SetAllParms()} It is possible to define $we or !$we in daylist to easily allow weekend an holiday. $we !$we are coded as 7 8, when using a numeric daylist.

time:define the time to switch, format: HH:MM:[SS](HH in 24 hour format) or a Perlfunction like {sunrise_abs()}. Within the {} you can use the variable $date(epoch) to get the exact switchingtimes of the week. Example: {sunrise_abs_dat($date)}

parameter:the parameter to be set, using any text value like on, off, dim30%, eco or comfort - whatever your device understands.
+ If the parameter is perl code (embraced in {}), it is evaluated automatically.

- Example: + Examples:

@@ -1239,4 +1283,4 @@ sub WeekdayTimer_SetAllParms() { # {WeekdayTimer_SetAllParms()} =end html -=cut +=cut \ No newline at end of file