From 7042e59cc649d3cb80b7842c282d6a3cb46cb227 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sat, 13 May 2023 08:53:48 +0000 Subject: [PATCH] 76_SolarForecast: contrib 0.79.0 git-svn-id: https://svn.fhem.de/fhem/trunk@27562 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/76_SolarForecast.pm | 78 ++++++++++++++++----- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/fhem/contrib/DS_Starter/76_SolarForecast.pm b/fhem/contrib/DS_Starter/76_SolarForecast.pm index 8b4aa146b..9c85798cd 100644 --- a/fhem/contrib/DS_Starter/76_SolarForecast.pm +++ b/fhem/contrib/DS_Starter/76_SolarForecast.pm @@ -1,5 +1,5 @@ ######################################################################################################################## -# $Id: 76_SolarForecast.pm 21735 2023-05-11 23:53:24Z DS_Starter $ +# $Id: 76_SolarForecast.pm 21735 2023-05-13 23:53:24Z DS_Starter $ ######################################################################################################################### # 76_SolarForecast.pm # @@ -136,6 +136,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "0.79.0" => "13.05.2023 new consumer key locktime ", "0.78.2" => "11.05.2023 extend debug radiationProcess ", "0.78.1" => "08.05.2023 change default icon it_ups_on_battery to batterie ", "0.78.0" => "07.05.2023 activate NotifyFn Forum:https://forum.fhem.de/index.php?msg=1275005, new Consumerkey asynchron ", @@ -5184,17 +5185,22 @@ return; # Planungsdaten bzw. aktuelle Planungszustände setzen ################################################################ sub ___setConsumerPlanningState { - my $paref = shift; - my $hash = $paref->{hash}; - my $name = $paref->{name}; - my $type = $paref->{type}; - my $c = $paref->{consumer}; - my $ps = $paref->{ps}; # Planstatus - my $startts = $paref->{startts}; # Unix Timestamp für geplanten Switch on - my $stopts = $paref->{stopts}; # Unix Timestamp für geplanten Switch off - my $lang = $paref->{lang}; + my $paref = shift; + my $hash = $paref->{hash}; + my $name = $paref->{name}; + my $type = $paref->{type}; + my $c = $paref->{consumer}; + my $ps = $paref->{ps}; # Planstatus + my $startts = $paref->{startts}; # Unix Timestamp für geplanten Switch on + my $stopts = $paref->{stopts}; # Unix Timestamp für geplanten Switch off + my $loffts = $paref->{lastAutoOffTs}; # Timestamp des letzten Off-Schaltens bzw. letzter Unterbrechnung im Automatikmodus + my $lang = $paref->{lang}; my ($starttime,$stoptime); + + if (defined $loffts) { + $data{$type}{$name}{consumers}{$c}{lastAutoOffTs} = $loffts; + } if ($startts) { $starttime = (timestampToTimestring ($startts, $lang))[3]; @@ -5438,6 +5444,8 @@ sub ___switchConsumerOn { ($swoffcond,$info,$err) = isAddSwitchOffCond ($hash, $c); # zusätzliche Switch off Bedingung Log3 ($name, 1, "$name - $err") if($err); + my $iilt = isInLocktime ($paref); # Sperrzeit Status ermitteln + if ($debug =~ /consumerSwitching/x) { # nur für Debugging my $cons = CurrentVal ($hash, 'consumption', 0); my $nompow = ConsumerVal ($hash, $c, 'power', '-'); @@ -5445,14 +5453,14 @@ sub ___switchConsumerOn { Log3 ($name, 1, qq{$name DEBUG> consumer "$c" - general switching parameters => }. qq{auto mode: $auto, current Consumption: $cons W, nompower: $nompow, surplus: $sp W, }. - qq{planning state: $pstate, start timestamp: }.($startts ? $startts : "undef") + qq{isInLocktime: $iilt, planning state: $pstate, start timestamp: }.($startts ? $startts : "undef") ); Log3 ($name, 1, qq{$name DEBUG> consumer "$c" - current Context is switching "on" => }. qq{swoncond: $swoncond, on-command: $oncom } ); } - if ($auto && $oncom && $swoncond && !$swoffcond && # kein Einschalten wenn zusätzliche Switch off Bedingung zutrifft + if ($auto && $oncom && $swoncond && !$swoffcond && !$iilt && # kein Einschalten wenn zusätzliche Switch off Bedingung zutrifft simplifyCstate($pstate) =~ /planned|priority|starting/xs && isInTimeframe ($hash, $c)) { # Verbraucher Start ist geplant && Startzeit überschritten my $mode = ConsumerVal ($hash, $c, "mode", $defcmode); # Consumer Planungsmode @@ -5490,7 +5498,7 @@ sub ___switchConsumerOn { (isInterruptable($hash, $c) == 3 && isConsRcmd ($hash, $c))) && isInTimeframe ($hash, $c) && simplifyCstate ($pstate) =~ /interrupted|interrupting/xs && - $auto && $oncom) { + $auto && $oncom && !$iilt) { CommandSet(undef,"$cname $oncom"); @@ -5631,13 +5639,15 @@ sub ___setConsumerSwitchingState { Log3 ($name, 2, "$name - $state"); } elsif ($pstate eq 'stopping' && isConsumerPhysOff ($hash, $c)) { - $paref->{ps} = "switched off:"; - $paref->{stopts} = $t; + $paref->{ps} = "switched off:"; + $paref->{stopts} = $t; + $paref->{lastAutoOffTs} = $t; ___setConsumerPlanningState ($paref); delete $paref->{ps}; delete $paref->{stopts}; + delete $paref->{lastAutoOffTs}; $state = qq{Consumer '$calias' switched off}; @@ -5659,11 +5669,13 @@ sub ___setConsumerSwitchingState { Log3 ($name, 2, "$name - $state"); } elsif ($pstate eq 'interrupting' && isConsumerPhysOff ($hash, $c)) { - $paref->{ps} = "interrupted:"; + $paref->{ps} = "interrupted:"; + $paref->{lastAutoOffTs} = $t; ___setConsumerPlanningState ($paref); delete $paref->{ps}; + delete $paref->{lastAutoOffTs}; $state = qq{Consumer '$calias' switched off (interrupted)}; @@ -6546,6 +6558,11 @@ sub collectAllRegConsumers { $setshift *= 60 if($setshift); } } + + my $clt; + if (exists $hc->{locktime}) { + $clt = $hc->{locktime}; + } my $rauto = $hc->{auto} // q{}; my $ctype = $hc->{type} // $defctype; @@ -6574,6 +6591,7 @@ sub collectAllRegConsumers { $data{$type}{$name}{consumers}{$c}{notafter} = $hc->{notafter} // q{}; # nicht einschalten nach Stunde in 24h Format (00-23) $data{$type}{$name}{consumers}{$c}{rswstate} = $rswstate // 'state'; # Schaltstatus Reading $data{$type}{$name}{consumers}{$c}{asynchron} = $asynchron // 0; # Arbeitsweise FHEM Consumer Device + $data{$type}{$name}{consumers}{$c}{locktime} = $clt // 0; # Sperrzeit im Automatikmodus $data{$type}{$name}{consumers}{$c}{onreg} = $onreg // 'on'; # Regex für 'ein' $data{$type}{$name}{consumers}{$c}{offreg} = $offreg // 'off'; # Regex für 'aus' $data{$type}{$name}{consumers}{$c}{dswoncond} = $dswoncond // q{}; # Device zur Lieferung einer zusätzliche Einschaltbedingung @@ -10448,6 +10466,28 @@ sub isInTimeframe { return ConsumerVal ($hash, $c, 'isIntimeframe', 0); } +################################################################ +# liefert Entscheidung ob sich Consumer $c noch in der +# Sperrzeit befindet +################################################################ +sub isInLocktime { + my $paref = shift; + my $hash = $paref->{hash}; + my $name = $paref->{name}; + my $c = $paref->{consumer}; + my $t = $paref->{t}; + + my $iilt = 0; + my $clt = ConsumerVal ($hash, $c, 'locktime', 0); + my $lot = ConsumerVal ($hash, $c, 'lastAutoOffTs', 0); + + if ($t - $lot <= $clt) { + $iilt = 1; + } + +return $iilt; +} + ################################################################ # liefert den Status "Consumption Recommended" von Consumer $c ################################################################ @@ -10920,6 +10960,7 @@ return $def; # swoffcondregex - Regex einer einer vorrangige Ausschaltbedingung # isIntimeframe - ist Zeit innerhalb der Planzeit ein/aus # interruptable - Consumer "on" ist während geplanter "ein"-Zeit unterbrechbar +# lastAutoOffTs - Timestamp des letzten Off-Schaltens bzw. letzter Unterbrechnung (nur Automatik-Modus) # hysteresis - Hysterese # sunriseshift - Verschiebung (Sekunden) Sonnenaufgang bei SunPath Verwendung # sunsetshift - Verschiebung (Sekunden) Sonnenuntergang bei SunPath Verwendung @@ -11955,7 +11996,7 @@ Planung und Steuerung von PV Überschuß abhängigen Verbraucherschaltungen.
  • consumerXX <Device Name> type=<type> power=<power>
    [mode=<mode>] [icon=<Icon>] [mintime=<minutes> | SunPath[:<Offset_Sunrise>:<Offset_Sunset>]]
    [on=<Kommando>] [off=<Kommando>] [swstate=<Readingname>:<on-Regex>:<off-Regex>] [asynchron=<Option>]
    - [notbefore=<Stunde>] [notafter=<Stunde>]
    + [notbefore=<Stunde>] [notafter=<Stunde>] [locktime=<Sekunden>]
    [auto=<Readingname>] [pcurr=<Readingname>:<Einheit>[:<Schwellenwert>]] [etotal=<Readingname>:<Einheit>[:<Schwellenwert>]]
    [swoncond=<Device>:<Reading>:<Regex>] [swoffcond=<Device>:<Reading>:<Regex>] [interruptable=<Option>]


    @@ -12057,6 +12098,9 @@ Planung und Steuerung von PV Überschuß abhängigen Verbraucherschaltungen. PV Überschuß (wenn power ungleich 0) vorliegt. Die optionale Hysterese ist ein numerischer Wert um den der Ausschaltpunkt gegenüber dem Soll-Einschaltpunkt angehoben wird sofern der ausgewertete Readingwert ebenfalls numerisch ist. (default: 0) + locktime Sperrzeit nach dem Ausschalten oder der Unterbrechung des Verbrauchers (Sekunden). + Der Verbraucher wird erst wieder eingeschaltet wenn die angegebene Sperrzeit abgelaufen ist. + Hinweis: Der Schalter 'locktime' ist nur im Automatik-Modus wirksam.