From 60cdb69763adf25fd5c38782cdc7a8919335076e Mon Sep 17 00:00:00 2001 From: dietmar63 <> Date: Sat, 8 Nov 2014 16:47:09 +0000 Subject: [PATCH] Heating_Control, WeekdayTimer: switchingtimes in Perl can use as $date variable to compute exact startime for the hole week. Numeric Parameter are no longer translated into float. git-svn-id: https://svn.fhem.de/fhem/trunk@6918 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_Heating_Control.pm | 66 ++++++++++++++++++--------------- fhem/FHEM/98_WeekdayTimer.pm | 2 +- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/fhem/FHEM/98_Heating_Control.pm b/fhem/FHEM/98_Heating_Control.pm index a971ee6bc..866e76748 100644 --- a/fhem/FHEM/98_Heating_Control.pm +++ b/fhem/FHEM/98_Heating_Control.pm @@ -214,7 +214,7 @@ sub Heating_Control_ParseSwitchingProfile($$$) { $daysRegExp =~ s/\|$//g; $daysRegExp .= ")"; - my (@st, @days, $daylist, $time, $para); + my (@st, @days, $daylist, $time, $timeString, $para); for(my $i=0; $i<@{$switchingtimes}; $i++) { @st = split(/\|/, @{$switchingtimes}[$i]); @@ -270,26 +270,37 @@ sub Heating_Control_ParseSwitchingProfile($$$) { } @days = sort(SortNumber keys %hdays); - - # Zeitangabe verarbeiten. - if($time =~ m/^\{.*\}$/g) { # Perlausdruck {*} - $time = eval($time); # must deliver HH:MM[:SS] - $hash->{TIME_AS_PERL} = 1; - } - - if ($time =~ m/^[0-2][0-9]:[0-5][0-9]$/g) { # HH:MM - $time .= ":00"; # HH:MM:SS erzeugen - } elsif ($time =~ m/^[0-2][0-9](:[0-5][0-9]){2,2}$/g) { # HH:MM:SS - ; # ok. - } else { - Log3 $hash, 1, "[$name] invalid time <$time> HH:MM[:SS]"; - return 0; - } - + + if($time =~ m/^\{.*\}$/g) { + $hash->{TIME_AS_PERL} = 1; + } + + my $now = time(); + my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($now); my $listOfDays = ""; for (my $d=0; $d<@days; $d++) { - $listOfDays .= @{$$shortDays}[$days[$d]] . ","; - $hash->{helper}{SWITCHINGTIME}{$days[$d]}{$time} = $para; + + # Zeitangabe verarbeiten. + if ($hash->{TIME_AS_PERL}) { # Perlausdruck {*} + my $date = $now+($d-$wday)*86400; + $timeString = '{ my $date='."$date;" .$time."}"; + $timeString = eval( $timeString ); # must deliver HH:MM[:SS] + $@ =~ s/\n/ /g; Log3 ($hash, 3, "[$hash->{NAME}] " . $@) if ($@); + } else { + $timeString = $time; + } + + if ($timeString =~ m/^[0-2][0-9]:[0-5][0-9]$/g) { # HH:MM + $timeString .= ":00"; # HH:MM:SS erzeugen + } elsif ($timeString =~ m/^[0-2][0-9](:[0-5][0-9]){2,2}$/g) { # HH:MM:SS + ; # ok. + } else { + Log3 $hash, 1, "[$name] invalid time <$timeString> HH:MM[:SS]"; + #return 0; + } + + $listOfDays .= @{$$shortDays}[$days[$d]] . ","; + $hash->{helper}{SWITCHINGTIME}{$days[$d]}{$timeString} = $para; } $listOfDays =~ s/,$//g; Log3 $hash, 5, "[$name] Switchingtime: @{$switchingtimes}[$i] : $listOfDays -> $time -> $para "; @@ -493,11 +504,9 @@ sub Heating_Control_akt_next_param($$) { } if ($secondsToSwitch<=0) { $newParam = $hash->{helper}{SWITCHINGTIME}{$wd}{$st}; - $newParam = sprintf("%.1f", $newParam) if ($newParam =~ m/^[0-9]{1,3}$/i); $nowSwitch = $next; } else { $nextParam = $hash->{helper}{SWITCHINGTIME}{$wd}{$st}; - $nextParam = sprintf("%.1f", $nextParam) if ($nextParam =~ m/^[0-9]{1,3}$/i); $nextSwitch = $next; last; } @@ -507,7 +516,6 @@ sub Heating_Control_akt_next_param($$) { if ($now > $nextSwitch) { $nextSwitch = max ($now+60,$nextSwitch); - Log 3, "nextSwitch-+60----------->" . strftime("%d.%m.%Y %H:%M:%S",localtime($nextSwitch)); } return ($nowSwitch,$nextSwitch,$newParam,$nextParam); } @@ -530,9 +538,11 @@ sub Heating_Control_Device_Schalten($$$$) { $command = '{ fhem("set @ '. $setModifier .' %") }'; } - my $aktParam = ReadingsVal($hash->{DEVICE}, $setModifier, 0); - $aktParam = sprintf("%.1f", $aktParam) if ($aktParam =~ m/^[0-9]{1,3}$/i); - + my $isHeating = $setModifier gt ""; + my $aktParam = ReadingsVal($hash->{DEVICE}, $setModifier, 0); + $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); + Log3 $hash, 4, $mod .strftime('%d.%m.%Y %H:%M:%S',localtime($nowSwitch))." ; aktParam: $aktParam ; newParam: $newParam"; my $disabled = AttrVal($hash->{NAME}, "disable", 0); @@ -614,7 +624,6 @@ sub Heating_Control_isHeizung($) { } else { $model = AttrVal($hash->{DEVICE}, $subTypeReading, "nF"); } - Log3 $hash, 5, "model------------>$model"; if (defined($setmodifiers{$dType}{$model})) { $setModifier = $setmodifiers{$dType}{setModifier} @@ -622,7 +631,6 @@ sub Heating_Control_isHeizung($) { $setModifier = ""; } } - Log3 $hash, 5, "setModifier------------>$setModifier"; return $setModifier; } @@ -710,7 +718,7 @@ sub SortNumber {
weekdays: optional, if not set every day is using.
Otherwise you can define one day as number or as shortname.
- time:define the time to switch, format: HH:MM:[SS](HH in 24 hour format) or a Perlfunction like {sunrise_abs()}
+ 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 temperature to be set, using a float with mask 99.9 or a sybolic value like eco or comfort - whatever your thermostat understands. The symbolic value can be added an additional parameter: dayTemp:16 night-temp:15. See examples
@@ -884,7 +892,7 @@ sub SortNumber { Wochentage: optionale Angabe, falls nicht gesetzt wird der Schaltpunkt jeden Tag ausgeführt. Für die Tage an denen dieser Schaltpunkt aktiv sein soll, ist jeder Tag mit seiner Tagesnummer (Mo=1, ..., So=7) oder Name des Tages (Mo, Di, ..., So) einzusetzen.
- Uhrzeit:Angabe der Uhrzeit zu der geschaltet werden soll, Format: HH:MM:[SS](HH im 24 Stunden Format) oder eine Perlfunction wie {sunrise_abs()}
+ Uhrzeit:Angabe der Uhrzeit zu der geschaltet werden soll, Format: HH:MM:[SS](HH im 24 Stunden Format) oder eine Perlfunction wie {sunrise_abs()}. In {} kannst du die Variable $date(epoch) nutzen, um die Schlatzeiten der Woche zu berechnen. Beispiel: {sunrise_abs_dat($date)}
Parameter:Angabe der zu setzenden Temperatur als Zahl mit Format 99.9 oder als symbolische Konstante eco or comfort - was immer das Heizkörperthermostat versteht. Symbolischen Werten kann ein zusätzlicher Parameter angehängt werden: dayTemp:16 night-temp:15. Unten folgen Beispiele

diff --git a/fhem/FHEM/98_WeekdayTimer.pm b/fhem/FHEM/98_WeekdayTimer.pm index 657ec8f0c..78c360be3 100644 --- a/fhem/FHEM/98_WeekdayTimer.pm +++ b/fhem/FHEM/98_WeekdayTimer.pm @@ -155,7 +155,7 @@ sub WeekdayTimer_SetAllParms() { # {WeekdayTimer_SetAllParms()} Define the weekly profile. All timings are separated by space. A switchingtime is defined by the following example:

weekdays: optional, if not set every day is used. Otherwise you can define a day as a number or as shortname.
- time:define the time to switch, format: HH:MM(HH in 24 hour format).
+ time:define the time to switch, format: HH:MM(HH in 24 hour format). 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.