mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 23:06:37 +00:00
98_Heating_Control, 98_WeekdayTimer:
a more sophisticated way to switch heatings in the past in startup phase of fhem or a HC and by calling Heating_Control_SetAllTemps() git-svn-id: https://svn.fhem.de/fhem/trunk@10983 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
1c892d15cc
commit
7a58bcb7da
@ -109,15 +109,16 @@ sub Heating_Control_SetTemp($) {
|
|||||||
my $hash = $modules{Heating_Control}{defptr}{$name};
|
my $hash = $modules{Heating_Control}{defptr}{$name};
|
||||||
if(defined $hash) {
|
if(defined $hash) {
|
||||||
Heating_Control_SetTimer($hash);
|
Heating_Control_SetTimer($hash);
|
||||||
Log3 undef, 3, "Heating_Control_SetTimer() for $hash->{NAME} done!";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
########################################################################
|
########################################################################
|
||||||
sub Heating_Control_SetAllTemps() { # {Heating_Control_SetAllTemps()}
|
sub Heating_Control_SetAllTemps() { # {Heating_Control_SetAllTemps()}
|
||||||
foreach my $hcName ( sort keys %{$modules{Heating_Control}{defptr}} ) {
|
|
||||||
|
my @hcNamen = sort keys %{$modules{Heating_Control}{defptr}};
|
||||||
|
foreach my $hcName ( @hcNamen ) {
|
||||||
Heating_Control_SetTemp($hcName);
|
Heating_Control_SetTemp($hcName);
|
||||||
}
|
}
|
||||||
Log3 undef, 3, "Heating_Control_SetAllTemps() done!";
|
Log3 undef, 3, "Heating_Control_SetAllTemps() done on: ".join(" ",@hcNamen );
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -539,7 +539,6 @@ sub WeekdayTimer_SetTimer($) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
my $now = time();
|
my $now = time();
|
||||||
#Log3 $hash, 3, "WeekdayTimer_SetTimer------------>WeekdayTimer_SetTimer";
|
|
||||||
|
|
||||||
my $isHeating = WeekdayTimer_isHeizung($hash);
|
my $isHeating = WeekdayTimer_isHeizung($hash);
|
||||||
my $swip = AttrVal($name, "switchInThePast", 0);
|
my $swip = AttrVal($name, "switchInThePast", 0);
|
||||||
@ -598,15 +597,52 @@ sub WeekdayTimer_SetTimer($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
myInternalTimer ("$aktIdx", $aktTime, "$hash->{TYPE}_Update", $hash, 0);
|
# alle in der Vergangenheit liegenden Schaltungen sammeln und
|
||||||
my $active = 1;
|
# nach 5 Sekunden in der Reihenfolge der Schaltzeiten
|
||||||
if ($hash->{CONDITION} gt "") {
|
# durch WeekdayTimer_delayedTimerInPast() als Timer einstellen
|
||||||
$active = AnalyzeCommandChain(undef, "{".$hash->{CONDITION}."}");
|
# die Parameter merken wir uns kurzzeitig im hash
|
||||||
}
|
# modules{WeekdayTimer}{timerInThePast}
|
||||||
readingsSingleUpdate ($hash, "state", $aktParameter, 1) if ($active);
|
my $device = $hash->{DEVICE};
|
||||||
|
Log3 $hash, 4, "[$name] past timer on $hash->{DEVICE} at ". FmtDateTime($aktTime). " with $aktParameter activated";
|
||||||
|
|
||||||
|
my $parameter = $modules{WeekdayTimer}{timerInThePast}{$device}{$aktTime};
|
||||||
|
$parameter = [] if (!defined $parameter);
|
||||||
|
push (@$parameter,["$aktIdx", $aktTime, "$hash->{TYPE}_Update", $hash, 0]);
|
||||||
|
$modules{WeekdayTimer}{timerInThePast}{$device}{$aktTime} = $parameter;
|
||||||
|
|
||||||
|
my $tipHash = $modules{WeekdayTimer}{timerInThePastHash};
|
||||||
|
$tipHash = $hash if (!defined $tipHash);
|
||||||
|
$modules{WeekdayTimer}{timerInThePastHash} = $tipHash;
|
||||||
|
|
||||||
|
myRemoveInternalTimer("delayed", $tipHash);
|
||||||
|
myInternalTimer ("delayed", time()+5, "WeekdayTimer_delayedTimerInPast", $tipHash, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
|
sub WeekdayTimer_delayedTimerInPast($) {
|
||||||
|
my ($myHash) = @_;
|
||||||
|
my $hash = myGetHashIndirekt($myHash, (caller(0))[3]);
|
||||||
|
return if (!defined($hash));
|
||||||
|
|
||||||
|
my $tim = time();
|
||||||
|
my $tipIpHash = $modules{WeekdayTimer}{timerInThePast};
|
||||||
|
|
||||||
|
foreach my $device ( keys %$tipIpHash ) {
|
||||||
|
foreach my $time ( sort keys %{$tipIpHash->{$device}} ) {
|
||||||
|
Log3 $hash, 4, "$device ".FmtDateTime($time)." ".($tim-$time)."s ";
|
||||||
|
|
||||||
|
foreach my $para ( @{$tipIpHash->{$device}{$time}} ) {
|
||||||
|
#myInternalTimer ("$aktIdx", $aktTime, "$hash->{TYPE}_Update", $hash, 0);
|
||||||
|
my $mHash =myInternalTimer (@$para[0],@$para[1],@$para[2],@$para[3],@$para[4]);
|
||||||
|
$mHash->{immerSchalten} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete $modules{WeekdayTimer}{timerInThePast};
|
||||||
|
delete $modules{WeekdayTimer}{timerInThePastHash}
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
sub WeekdayTimer_searchAktNext($$) {
|
sub WeekdayTimer_searchAktNext($$) {
|
||||||
my ($hash, $now) = @_;
|
my ($hash, $now) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -673,44 +709,32 @@ sub WeekdayTimer_Update($) {
|
|||||||
my $time = $hash->{profil}{$idx}{TIME};
|
my $time = $hash->{profil}{$idx}{TIME};
|
||||||
my $newParam = $hash->{profil}{$idx}{PARA};
|
my $newParam = $hash->{profil}{$idx}{PARA};
|
||||||
|
|
||||||
#Log3 $hash, 3, "[$name] $idx ".FmtDateTime($epoch) . " " . $newParam . " " . join("",@$tage);
|
#Log3 $hash, 3, "[$name] $idx ". $time . " " . $newParam . " " . join("",@$tage);
|
||||||
|
|
||||||
#if ($hash->{STILLDONETIME} <= $sollZeit ) {
|
|
||||||
# $hash->{STILLDONETIME} = $sollZeit;
|
|
||||||
#} else {
|
|
||||||
# Log3 $hash, 3, "[$name] Timer $time overwritten by " . FmtDateTime($hash->{STILLDONETIME});
|
|
||||||
# return;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Fenserkontakte abfragen - wenn einer im Status closed, dann Schaltung um 60 Sekunden verzögern
|
# Fenserkontakte abfragen - wenn einer im Status closed, dann Schaltung um 60 Sekunden verzögern
|
||||||
if (WeekdayTimer_FensterOffen($hash, $newParam, $idx)) {
|
if (WeekdayTimer_FensterOffen($hash, $newParam, $idx)) {
|
||||||
readingsSingleUpdate ($hash, "state", "open window", 1);
|
readingsSingleUpdate ($hash, "state", "open window", 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $activeTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $newParam);
|
my $dieGanzeWoche = [7,8];
|
||||||
Log3 $hash, 4, "[$name] Update - timer seems to be active today: ".join("",@$tage)."|$time|$newParam" if($activeTimer);
|
my ($activeTimer, $activeTimerState);
|
||||||
|
if (defined $myHash->{immerSchalten}) {
|
||||||
|
$activeTimer = WeekdayTimer_isAnActiveTimer ($hash, $dieGanzeWoche, $newParam);
|
||||||
|
$activeTimerState = WeekdayTimer_isAnActiveTimer ($hash, $tage, $newParam);
|
||||||
|
Log3 $hash, 4, "[$name] Update - past timer activated";
|
||||||
|
} else {
|
||||||
|
$activeTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $newParam);
|
||||||
|
$activeTimerState = $activeTimer;
|
||||||
|
Log3 $hash, 4, "[$name] Update - timer seems to be active today: ".join("",@$tage)."|$time|$newParam" if($activeTimer);
|
||||||
|
}
|
||||||
|
#Log3 $hash, 3, "activeTimer------------>$activeTimer";
|
||||||
|
#Log3 $hash, 3, "activeTimerState------->$activeTimerState";
|
||||||
my ($aktIdx, $aktTime, $aktParameter, $nextTime, $nextParameter) =
|
my ($aktIdx, $aktTime, $aktParameter, $nextTime, $nextParameter) =
|
||||||
WeekdayTimer_searchAktNext($hash, time()+5);
|
WeekdayTimer_searchAktNext($hash, time()+5);
|
||||||
|
|
||||||
my $device = $hash->{DEVICE};
|
my $device = $hash->{DEVICE};
|
||||||
my $disabled = AttrVal($hash->{NAME}, "disable", 0);
|
my $disabled = AttrVal($hash->{NAME}, "disable", 0);
|
||||||
if ($activeTimer && !$disabled && $defs{$device}) {
|
|
||||||
|
|
||||||
#my $sollZeit = $myHash->{TIME};
|
|
||||||
|
|
||||||
#Log3 $hash, 3, "[$name] $idx ". FmtDateTime($defs{$device}{STILLDONETIME}) . " " . $newParam . " " . join("",@$tage);
|
|
||||||
#Log3 $hash, 3, "[$name] $idx ". FmtDateTime($sollZeit) . " " . $newParam . " " . join("",@$tage);
|
|
||||||
|
|
||||||
#$defs{$device}{STILLDONETIME} = 0 if (!defined($defs{$device}{STILLDONETIME}));
|
|
||||||
#if ($defs{$device}{STILLDONETIME} <= $sollZeit ) {
|
|
||||||
# $defs{$device}{STILLDONETIME} = $sollZeit;
|
|
||||||
#} else {
|
|
||||||
# Log3 $hash, 3, "[$name:$time] Timer ".FmtDateTime($sollZeit)." overwritten by " . FmtDateTime($defs{$device}{STILLDONETIME});
|
|
||||||
# return;
|
|
||||||
#}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ggf. Device schalten
|
# ggf. Device schalten
|
||||||
WeekdayTimer_Device_Schalten($hash, $newParam, $tage) if($activeTimer);
|
WeekdayTimer_Device_Schalten($hash, $newParam, $tage) if($activeTimer);
|
||||||
@ -719,7 +743,7 @@ sub WeekdayTimer_Update($) {
|
|||||||
readingsBulkUpdate ($hash, "nextUpdate", FmtDateTime($nextTime));
|
readingsBulkUpdate ($hash, "nextUpdate", FmtDateTime($nextTime));
|
||||||
readingsBulkUpdate ($hash, "nextValue", $nextParameter);
|
readingsBulkUpdate ($hash, "nextValue", $nextParameter);
|
||||||
readingsBulkUpdate ($hash, "currValue", $aktParameter); # HB
|
readingsBulkUpdate ($hash, "currValue", $aktParameter); # HB
|
||||||
readingsBulkUpdate ($hash, "state", $newParam ) if($activeTimer);
|
readingsBulkUpdate ($hash, "state", $newParam ) if($activeTimerState);
|
||||||
readingsEndUpdate ($hash, defined($hash->{LOCAL} ? 0 : 1));
|
readingsEndUpdate ($hash, defined($hash->{LOCAL} ? 0 : 1));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -739,6 +763,7 @@ sub WeekdayTimer_isAnActiveTimer ($$$) {
|
|||||||
Log3 $hash, 5, "[$name] condition: $xPression";
|
Log3 $hash, 5, "[$name] condition: $xPression";
|
||||||
|
|
||||||
my $ret = AnalyzeCommandChain(undef, $xPression);
|
my $ret = AnalyzeCommandChain(undef, $xPression);
|
||||||
|
#Log3 $hash, 3, "[$name] condition:>>>$ret<<< $xPression";
|
||||||
Log3 $hash, 5, "[$name] result of condition:$ret";
|
Log3 $hash, 5, "[$name] result of condition:$ret";
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
@ -919,14 +944,14 @@ sub WeekdayTimer_Device_Schalten($$$) {
|
|||||||
|
|
||||||
#Kommando ausführen
|
#Kommando ausführen
|
||||||
if ($command && !$disabled && $activeTimer
|
if ($command && !$disabled && $activeTimer
|
||||||
&& $aktParam ne $newParam
|
# && $aktParam ne $newParam
|
||||||
) {
|
) {
|
||||||
$newParam =~ s/:/ /g;
|
$newParam =~ s/:/ /g;
|
||||||
|
|
||||||
my %specials = ( "%NAME" => $hash->{DEVICE}, "%EVENT" => $newParam);
|
my %specials = ( "%NAME" => $hash->{DEVICE}, "%EVENT" => $newParam);
|
||||||
$command= EvalSpecials($command, %specials);
|
$command= EvalSpecials($command, %specials);
|
||||||
|
|
||||||
Log3 $hash, 4, "[$name] command: $command executed";
|
Log3 $hash, 4, "[$name] command: '$command' executed with ".join(",", map { "$_=>$specials{$_}" } keys %specials);
|
||||||
my $ret = AnalyzeCommandChain(undef, $command);
|
my $ret = AnalyzeCommandChain(undef, $command);
|
||||||
Log3 ($hash, 3, $ret) if($ret);
|
Log3 ($hash, 3, $ret) if($ret);
|
||||||
}
|
}
|
||||||
@ -944,6 +969,9 @@ sub WeekdayTimer_tageAsHash($$) {
|
|||||||
sub WeekdayTimer_Condition($$) {
|
sub WeekdayTimer_Condition($$) {
|
||||||
my ($hash, $tage) = @_;
|
my ($hash, $tage) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
Log3 $hash, 4, "[$name] condition:$hash->{CONDITION} - Tage:".join(",",@$tage);
|
||||||
|
|
||||||
my $condition = "( ";
|
my $condition = "( ";
|
||||||
$condition .= ($hash->{CONDITION} gt "") ? $hash->{CONDITION} : 1 ;
|
$condition .= ($hash->{CONDITION} gt "") ? $hash->{CONDITION} : 1 ;
|
||||||
$condition .= " && " . WeekdayTimer_TageAsCondition($tage);
|
$condition .= " && " . WeekdayTimer_TageAsCondition($tage);
|
||||||
@ -993,16 +1021,16 @@ sub WeekdayTimer_SetParm($) {
|
|||||||
if(defined $hash) {
|
if(defined $hash) {
|
||||||
WeekdayTimer_DeleteTimer($hash);
|
WeekdayTimer_DeleteTimer($hash);
|
||||||
WeekdayTimer_SetTimer($hash);
|
WeekdayTimer_SetTimer($hash);
|
||||||
Log3 undef, 3, "WeekdayTimer_SetParm() for $hash->{NAME} done!";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
sub WeekdayTimer_SetAllParms() { # {WeekdayTimer_SetAllParms()}
|
sub WeekdayTimer_SetAllParms() { # {WeekdayTimer_SetAllParms()}
|
||||||
|
|
||||||
foreach my $wdName ( sort keys %{$modules{WeekdayTimer}{defptr}} ) {
|
my @wdNamen = sort keys %{$modules{WeekdayTimer}{defptr}};
|
||||||
|
foreach my $wdName ( @wdNamen ) {
|
||||||
WeekdayTimer_SetParm($wdName);
|
WeekdayTimer_SetParm($wdName);
|
||||||
}
|
}
|
||||||
Log3 undef, 3, "WeekdayTimer_SetAllParms() done!";
|
Log3 undef, 3, "WeekdayTimer_SetAllParms() done on: ".join(" ",@wdNamen );
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user