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: svn://svn.code.sf.net/p/fhem/code/trunk@6918 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
dietmar63
2014-11-08 16:47:09 +00:00
parent 8385cfe16c
commit 019fc5c532
2 changed files with 38 additions and 30 deletions

View File

@@ -214,7 +214,7 @@ sub Heating_Control_ParseSwitchingProfile($$$) {
$daysRegExp =~ s/\|$//g; $daysRegExp =~ s/\|$//g;
$daysRegExp .= ")"; $daysRegExp .= ")";
my (@st, @days, $daylist, $time, $para); my (@st, @days, $daylist, $time, $timeString, $para);
for(my $i=0; $i<@{$switchingtimes}; $i++) { for(my $i=0; $i<@{$switchingtimes}; $i++) {
@st = split(/\|/, @{$switchingtimes}[$i]); @st = split(/\|/, @{$switchingtimes}[$i]);
@@ -271,25 +271,36 @@ sub Heating_Control_ParseSwitchingProfile($$$) {
@days = sort(SortNumber keys %hdays); @days = sort(SortNumber keys %hdays);
# Zeitangabe verarbeiten. if($time =~ m/^\{.*\}$/g) {
if($time =~ m/^\{.*\}$/g) { # Perlausdruck {*} $hash->{TIME_AS_PERL} = 1;
$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;
} }
my $now = time();
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($now);
my $listOfDays = ""; my $listOfDays = "";
for (my $d=0; $d<@days; $d++) { 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; $listOfDays =~ s/,$//g;
Log3 $hash, 5, "[$name] Switchingtime: @{$switchingtimes}[$i] : $listOfDays -> $time -> $para "; Log3 $hash, 5, "[$name] Switchingtime: @{$switchingtimes}[$i] : $listOfDays -> $time -> $para ";
@@ -493,11 +504,9 @@ sub Heating_Control_akt_next_param($$) {
} }
if ($secondsToSwitch<=0) { if ($secondsToSwitch<=0) {
$newParam = $hash->{helper}{SWITCHINGTIME}{$wd}{$st}; $newParam = $hash->{helper}{SWITCHINGTIME}{$wd}{$st};
$newParam = sprintf("%.1f", $newParam) if ($newParam =~ m/^[0-9]{1,3}$/i);
$nowSwitch = $next; $nowSwitch = $next;
} else { } else {
$nextParam = $hash->{helper}{SWITCHINGTIME}{$wd}{$st}; $nextParam = $hash->{helper}{SWITCHINGTIME}{$wd}{$st};
$nextParam = sprintf("%.1f", $nextParam) if ($nextParam =~ m/^[0-9]{1,3}$/i);
$nextSwitch = $next; $nextSwitch = $next;
last; last;
} }
@@ -507,7 +516,6 @@ sub Heating_Control_akt_next_param($$) {
if ($now > $nextSwitch) { if ($now > $nextSwitch) {
$nextSwitch = max ($now+60,$nextSwitch); $nextSwitch = max ($now+60,$nextSwitch);
Log 3, "nextSwitch-+60----------->" . strftime("%d.%m.%Y %H:%M:%S",localtime($nextSwitch));
} }
return ($nowSwitch,$nextSwitch,$newParam,$nextParam); return ($nowSwitch,$nextSwitch,$newParam,$nextParam);
} }
@@ -530,8 +538,10 @@ sub Heating_Control_Device_Schalten($$$$) {
$command = '{ fhem("set @ '. $setModifier .' %") }'; $command = '{ fhem("set @ '. $setModifier .' %") }';
} }
my $aktParam = ReadingsVal($hash->{DEVICE}, $setModifier, 0); my $isHeating = $setModifier gt "";
$aktParam = sprintf("%.1f", $aktParam) if ($aktParam =~ m/^[0-9]{1,3}$/i); 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"; Log3 $hash, 4, $mod .strftime('%d.%m.%Y %H:%M:%S',localtime($nowSwitch))." ; aktParam: $aktParam ; newParam: $newParam";
@@ -614,7 +624,6 @@ sub Heating_Control_isHeizung($) {
} else { } else {
$model = AttrVal($hash->{DEVICE}, $subTypeReading, "nF"); $model = AttrVal($hash->{DEVICE}, $subTypeReading, "nF");
} }
Log3 $hash, 5, "model------------>$model";
if (defined($setmodifiers{$dType}{$model})) { if (defined($setmodifiers{$dType}{$model})) {
$setModifier = $setmodifiers{$dType}{setModifier} $setModifier = $setmodifiers{$dType}{setModifier}
@@ -622,7 +631,6 @@ sub Heating_Control_isHeizung($) {
$setModifier = ""; $setModifier = "";
} }
} }
Log3 $hash, 5, "setModifier------------>$setModifier";
return $setModifier; return $setModifier;
} }
@@ -710,7 +718,7 @@ sub SortNumber {
<ul><b>[&lt;weekdays&gt;|]&lt;time&gt;|&lt;parameter&gt;</b></ul><br> <ul><b>[&lt;weekdays&gt;|]&lt;time&gt;|&lt;parameter&gt;</b></ul><br>
<u>weekdays:</u> optional, if not set every day is using.<br> <u>weekdays:</u> optional, if not set every day is using.<br>
Otherwise you can define one day as number or as shortname.<br> Otherwise you can define one day as number or as shortname.<br>
<u>time:</u>define the time to switch, format: HH:MM:[SS](HH in 24 hour format) or a Perlfunction like {sunrise_abs()}<br> <u>time:</u>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)}<br>
<u>parameter:</u>the temperature to be set, using a float with mask 99.9 or a sybolic value like <b>eco</b> or <b>comfort</b> - whatever your thermostat understands. <u>parameter:</u>the temperature to be set, using a float with mask 99.9 or a sybolic value like <b>eco</b> or <b>comfort</b> - whatever your thermostat understands.
The symbolic value can be added an additional parameter: dayTemp:16 night-temp:15. See examples <br> The symbolic value can be added an additional parameter: dayTemp:16 night-temp:15. See examples <br>
</ul> </ul>
@@ -884,7 +892,7 @@ sub SortNumber {
<u>Wochentage:</u> optionale Angabe, falls nicht gesetzt wird der Schaltpunkt jeden Tag ausgef&uumlhrt. <u>Wochentage:</u> optionale Angabe, falls nicht gesetzt wird der Schaltpunkt jeden Tag ausgef&uumlhrt.
F&uumlr die Tage an denen dieser Schaltpunkt aktiv sein soll, ist jeder Tag mit seiner F&uumlr 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.<br> Tagesnummer (Mo=1, ..., So=7) oder Name des Tages (Mo, Di, ..., So) einzusetzen.<br>
<u>Uhrzeit:</u>Angabe der Uhrzeit zu der geschaltet werden soll, Format: HH:MM:[SS](HH im 24 Stunden Format) oder eine Perlfunction wie {sunrise_abs()}<br> <u>Uhrzeit:</u>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)}<br>
<u>Parameter:</u>Angabe der zu setzenden Temperatur als Zahl mit Format 99.9 oder als symbolische Konstante <b>eco</b> <u>Parameter:</u>Angabe der zu setzenden Temperatur als Zahl mit Format 99.9 oder als symbolische Konstante <b>eco</b>
or <b>comfort</b> - was immer das Heizk&oumlrperthermostat versteht. or <b>comfort</b> - was immer das Heizk&oumlrperthermostat versteht.
Symbolischen Werten kann ein zus&aumltzlicher Parameter angeh&aumlngt werden: dayTemp:16 night-temp:15. Unten folgen Beispiele<br><br> Symbolischen Werten kann ein zus&aumltzlicher Parameter angeh&aumlngt werden: dayTemp:16 night-temp:15. Unten folgen Beispiele<br><br>

View File

@@ -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:<br> Define the weekly profile. All timings are separated by space. A switchingtime is defined by the following example:<br>
<ul><b>[&lt;weekdays&gt;|]&lt;time&gt;|&lt;parameter&gt;</b></ul><br> <ul><b>[&lt;weekdays&gt;|]&lt;time&gt;|&lt;parameter&gt;</b></ul><br>
<u>weekdays:</u> optional, if not set every day is used. Otherwise you can define a day as a number or as shortname.<br> <u>weekdays:</u> optional, if not set every day is used. Otherwise you can define a day as a number or as shortname.<br>
<u>time:</u>define the time to switch, format: HH:MM(HH in 24 hour format).<br> <u>time:</u>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)}<br>
<u>parameter:</u>the parameter to be set, using any text value like <b>on</b>, <b>off</b>, <b>dim30%</b>, <b>eco</b> or <b>comfort</b> - whatever your device understands.<br> <u>parameter:</u>the parameter to be set, using any text value like <b>on</b>, <b>off</b>, <b>dim30%</b>, <b>eco</b> or <b>comfort</b> - whatever your device understands.<br>
</ul> </ul>
<p> <p>