mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 18:56:03 +00:00
98_WeekdayTimer, 98_Heating_Control:
correction of some bugs with inactive/active state nextValue has now Format 2015-04-25 18:15:00 as before added better logging and attr switchInThePast git-svn-id: https://svn.fhem.de/fhem/trunk@8477 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
82a0cb737e
commit
29554b0092
@ -41,7 +41,7 @@ sub Heating_Control_Initialize($)
|
|||||||
$hash->{UndefFn} = "Heating_Control_Undef";
|
$hash->{UndefFn} = "Heating_Control_Undef";
|
||||||
$hash->{GetFn} = "Heating_Control_Get";
|
$hash->{GetFn} = "Heating_Control_Get";
|
||||||
$hash->{UpdFn} = "Heating_Control_Update";
|
$hash->{UpdFn} = "Heating_Control_Update";
|
||||||
$hash->{AttrList}= "disable:0,1 delayedExecutionCond windowSensor ".
|
$hash->{AttrList}= "disable:0,1 delayedExecutionCond windowSensor switchInThePast:0,1 ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -72,7 +72,6 @@ sub Heating_Control_Define($$){
|
|||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
|
|
||||||
my $ret = WeekdayTimer_Define($hash, $def);
|
my $ret = WeekdayTimer_Define($hash, $def);
|
||||||
$hash->{helper}{DESIRED_TEMP_READING} = "";
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -30,6 +30,7 @@ use Time::Local 'timelocal_nocheck';
|
|||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
$Data::Dumper::Sortkeys = 1;
|
$Data::Dumper::Sortkeys = 1;
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
sub WeekdayTimer_Initialize($){
|
sub WeekdayTimer_Initialize($){
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
@ -46,7 +47,7 @@ sub WeekdayTimer_Initialize($){
|
|||||||
$hash->{GetFn} = "WeekdayTimer_Get";
|
$hash->{GetFn} = "WeekdayTimer_Get";
|
||||||
$hash->{AttrFn} = "WeekdayTimer_Attr";
|
$hash->{AttrFn} = "WeekdayTimer_Attr";
|
||||||
$hash->{UpdFn} = "WeekdayTimer_Update";
|
$hash->{UpdFn} = "WeekdayTimer_Update";
|
||||||
$hash->{AttrList}= "disable:0,1 delayedExecutionCond ".
|
$hash->{AttrList}= "disable:0,1 delayedExecutionCond switchInThePast:0,1 ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -153,6 +154,7 @@ sub WeekdayTimer_Define($$) {
|
|||||||
$hash->{NAME} = $name;
|
$hash->{NAME} = $name;
|
||||||
$hash->{DEVICE} = $device;
|
$hash->{DEVICE} = $device;
|
||||||
$hash->{SWITCHINGTIMES} = \@switchingtimes;
|
$hash->{SWITCHINGTIMES} = \@switchingtimes;
|
||||||
|
$attr{$name}{verbose} = 4 if ($name =~ m/^tst.*/ );
|
||||||
|
|
||||||
$modules{$hash->{TYPE}}{defptr}{$hash->{NAME}} = $hash;
|
$modules{$hash->{TYPE}}{defptr}{$hash->{NAME}} = $hash;
|
||||||
|
|
||||||
@ -454,8 +456,13 @@ sub WeekdayTimer_SetTimer($) {
|
|||||||
my $now = time();
|
my $now = time();
|
||||||
|
|
||||||
my $switchedInThePast = 0;
|
my $switchedInThePast = 0;
|
||||||
|
my $switchInThePast = AttrVal($name, "switchInThePast", 0);
|
||||||
my $isHeating = WeekdayTimer_isHeizung($hash);
|
my $isHeating = WeekdayTimer_isHeizung($hash);
|
||||||
my $grenzSeconds = $isHeating ? -24*3600 : -5;
|
my $grenzSeconds = $isHeating || $switchInThePast ? -24*3600 : -5;
|
||||||
|
|
||||||
|
Log3 $hash, 4, "[$name] Heating recognized - switch in the past activated" if ($isHeating);
|
||||||
|
Log3 $hash, 4, "[$name] no switch in the yesterdays because of the devices type($hash->{DEVICE} is not recognized as heating) - use attr switchInThePast" if (!($isHeating || $switchInThePast));
|
||||||
|
|
||||||
|
|
||||||
my @switches = sort keys %{$hash->{profil}};
|
my @switches = sort keys %{$hash->{profil}};
|
||||||
if ($#switches < 0) {
|
if ($#switches < 0) {
|
||||||
@ -466,6 +473,7 @@ sub WeekdayTimer_SetTimer($) {
|
|||||||
my $nextSwitch = $switches[0];
|
my $nextSwitch = $switches[0];
|
||||||
my $nextPara = $hash->{profil}{$switches[0]}{PARA};
|
my $nextPara = $hash->{profil}{$switches[0]}{PARA};
|
||||||
|
|
||||||
|
readingsSingleUpdate ($hash, "state", "inactive", 1);
|
||||||
my @reverseSwitches = ((reverse @switches), $switches[$#switches]);
|
my @reverseSwitches = ((reverse @switches), $switches[$#switches]);
|
||||||
for(my $i=0; $i<=$#reverseSwitches; $i++) {
|
for(my $i=0; $i<=$#reverseSwitches; $i++) {
|
||||||
my $time = $reverseSwitches[$i];
|
my $time = $reverseSwitches[$i];
|
||||||
@ -481,11 +489,19 @@ sub WeekdayTimer_SetTimer($) {
|
|||||||
$timToSwitch -= 24*3600 if ($i == $#reverseSwitches);
|
$timToSwitch -= 24*3600 if ($i == $#reverseSwitches);
|
||||||
my $secondsToSwitch = $timToSwitch - $now;
|
my $secondsToSwitch = $timToSwitch - $now;
|
||||||
|
|
||||||
readingsSingleUpdate ($hash, "state", "inactive", 1);
|
|
||||||
my $isActiveTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $nextPara);
|
my $isActiveTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $nextPara);
|
||||||
if ($secondsToSwitch>$grenzSeconds && !$switchedInThePast) {
|
if ($secondsToSwitch>$grenzSeconds && !$switchedInThePast) {
|
||||||
if ($secondsToSwitch>0 || $isActiveTimer) {
|
if ($secondsToSwitch>0 || $isActiveTimer) {
|
||||||
myInternalTimer ("$time", $timToSwitch, "$hash->{TYPE}_Update", $hash, 0)
|
|
||||||
|
Log3 $hash, 4, "[$name] timer seems to be active today: ".join("",@$tage)."|$time|$nextPara" if($isActiveTimer);
|
||||||
|
myInternalTimer ("$time", $timToSwitch, "$hash->{TYPE}_Update", $hash, 0);
|
||||||
|
|
||||||
|
my ($stunde, $minute, $sekunde) = split (":",$nextSwitch);
|
||||||
|
my $epoch = WeekdayTimer_zeitErmitteln ($now, $stunde, $minute, $sekunde, 0);
|
||||||
|
|
||||||
|
readingsSingleUpdate ($hash, "nextUpdate", FmtDateTime($epoch), 1);
|
||||||
|
readingsSingleUpdate ($hash, "nextValue", $nextPara, 1);
|
||||||
|
readingsSingleUpdate ($hash, "state", "active", 1) if ($isActiveTimer);
|
||||||
};
|
};
|
||||||
$switchedInThePast = ($secondsToSwitch<0 && $isActiveTimer) ;
|
$switchedInThePast = ($secondsToSwitch<0 && $isActiveTimer) ;
|
||||||
}
|
}
|
||||||
@ -524,9 +540,11 @@ sub WeekdayTimer_Update($) {
|
|||||||
# ggf. Device schalten
|
# ggf. Device schalten
|
||||||
WeekdayTimer_Device_Schalten($hash, $newParam, $tage);
|
WeekdayTimer_Device_Schalten($hash, $newParam, $tage);
|
||||||
|
|
||||||
|
my ($stunde, $minute, $sekunde) = split (":",$nextSwitch);
|
||||||
|
my $epoch = WeekdayTimer_zeitErmitteln ($now, $stunde, $minute, $sekunde, 0);
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate ($hash, "nextUpdate", $nextSwitch);
|
readingsBulkUpdate ($hash, "nextUpdate", FmtDateTime($epoch));
|
||||||
readingsBulkUpdate ($hash, "nextUpdate", $nextSwitch);
|
|
||||||
readingsBulkUpdate ($hash, "nextValue", $nextParam);
|
readingsBulkUpdate ($hash, "nextValue", $nextParam);
|
||||||
readingsBulkUpdate ($hash, "state", $active ? $newParam : "inactive" );
|
readingsBulkUpdate ($hash, "state", $active ? $newParam : "inactive" );
|
||||||
readingsEndUpdate ($hash, defined($hash->{LOCAL} ? 0 : 1));
|
readingsEndUpdate ($hash, defined($hash->{LOCAL} ? 0 : 1));
|
||||||
@ -545,12 +563,15 @@ sub WeekdayTimer_isAnActiveTimer ($$$) {
|
|||||||
my $xPression = "{".$tageAsHash.";;".$condition ."}";
|
my $xPression = "{".$tageAsHash.";;".$condition ."}";
|
||||||
$xPression = EvalSpecials($xPression, %specials);
|
$xPression = EvalSpecials($xPression, %specials);
|
||||||
|
|
||||||
return AnalyzeCommandChain(undef, $xPression);
|
my $ret = AnalyzeCommandChain(undef, $xPression);
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
sub WeekdayTimer_isHeizung($) {
|
sub WeekdayTimer_isHeizung($) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
my %setmodifiers =
|
my %setmodifiers =
|
||||||
("FHT" => "desired-temp",
|
("FHT" => "desired-temp",
|
||||||
"PID20" => "desired",
|
"PID20" => "desired",
|
||||||
@ -565,6 +586,8 @@ sub WeekdayTimer_isHeizung($) {
|
|||||||
"HM-CC-TC" => 1,
|
"HM-CC-TC" => 1,
|
||||||
"HM-TC-IT-WM-W-EU" => 1,
|
"HM-TC-IT-WM-W-EU" => 1,
|
||||||
"HM-CC-RT-DN" => 1 } );
|
"HM-CC-RT-DN" => 1 } );
|
||||||
|
|
||||||
|
my $model = "";
|
||||||
my $dHash = $defs{$hash->{DEVICE}};
|
my $dHash = $defs{$hash->{DEVICE}};
|
||||||
my $dType = $dHash->{TYPE};
|
my $dType = $dHash->{TYPE};
|
||||||
return "" if (!defined($dType));
|
return "" if (!defined($dType));
|
||||||
@ -575,7 +598,6 @@ sub WeekdayTimer_isHeizung($) {
|
|||||||
|
|
||||||
my $subTypeReading = $setmodifiers{$dType}{subTypeReading};
|
my $subTypeReading = $setmodifiers{$dType}{subTypeReading};
|
||||||
|
|
||||||
my $model;
|
|
||||||
if ($subTypeReading eq "type" ) {
|
if ($subTypeReading eq "type" ) {
|
||||||
$model = $dHash->{type};
|
$model = $dHash->{type};
|
||||||
} else {
|
} else {
|
||||||
@ -588,6 +610,7 @@ sub WeekdayTimer_isHeizung($) {
|
|||||||
$setModifier = "";
|
$setModifier = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log3 $hash, 4, "[$name] device type $dType:$model recognized, setModifier:$setModifier";
|
||||||
return $setModifier;
|
return $setModifier;
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -662,7 +685,6 @@ sub WeekdayTimer_FensterOffen ($$$) {
|
|||||||
Log3 $hash, 3, "[$name] switch of $hash->{DEVICE} delayed - sensor '$fk' Reading/Attribute '$reading' is '$windowStatus'";
|
Log3 $hash, 3, "[$name] switch of $hash->{DEVICE} delayed - sensor '$fk' Reading/Attribute '$reading' is '$windowStatus'";
|
||||||
}
|
}
|
||||||
myRemoveInternalTimer("Update", $hash);
|
myRemoveInternalTimer("Update", $hash);
|
||||||
#myInternalTimer ("Update", time()+60, "$hash->{TYPE}_Update", $hash, 0);
|
|
||||||
myInternalTimer ("$time", time()+60, "$hash->{TYPE}_Update", $hash, 0);
|
myInternalTimer ("$time", time()+60, "$hash->{TYPE}_Update", $hash, 0);
|
||||||
$hash->{VERZOEGRUNG} = 1;
|
$hash->{VERZOEGRUNG} = 1;
|
||||||
return 1
|
return 1
|
||||||
@ -760,9 +782,12 @@ sub WeekdayTimer_TageAsCondition ($) {
|
|||||||
sub WeekdayTimer_Attr($$$) {
|
sub WeekdayTimer_Attr($$$) {
|
||||||
my ($cmd, $name, $attrName, $attrVal) = @_;
|
my ($cmd, $name, $attrName, $attrVal) = @_;
|
||||||
|
|
||||||
if( $attrName eq "disable" ) {
|
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
|
if( $attrName eq "disable" ) {
|
||||||
readingsSingleUpdate ($hash, "disabled", $attrVal, 1);
|
readingsSingleUpdate ($hash, "disabled", $attrVal, 1);
|
||||||
|
} elsif ( $attrName eq "switchInThePast" ) {
|
||||||
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
|
WeekdayTimer_SetTimerOfDay({ HASH => $hash});
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user