From 72c8bbd2b9a732e8135a06aa80fecac20b1b2688 Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Fri, 23 Oct 2020 05:32:18 +0000 Subject: [PATCH] 73_AutoShuttersControl: fix IsDay Fn for weekend condition and more git-svn-id: https://svn.fhem.de/fhem/trunk@23008 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 + fhem/FHEM/73_AutoShuttersControl.pm | 10 +- fhem/lib/FHEM/Automation/ShuttersControl.pm | 10 +- .../EventProcessingFunctions.pm | 23 +++- .../FHEM/Automation/ShuttersControl/Helper.pm | 16 ++- .../Automation/ShuttersControl/Shading.pm | 110 +++++++++++------- .../ShuttersControl/Shutters/Attr.pm | 4 +- 7 files changed, 115 insertions(+), 61 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 8728d8d4e..1229b8116 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 73_AutoShuttersControl: fix IsDay Fn for weekend condition + - fix detected IsDay for Brightness + - https://git.cooltux.net/FHEM/mod-AutoShuttersControl/issues/25 - feature: 72_XiaomiDevice: New fan type FA1 - change: 50_TelegramBot: sendVideo and support for video format - bugfix: 89_FULLY: Removed log messages diff --git a/fhem/FHEM/73_AutoShuttersControl.pm b/fhem/FHEM/73_AutoShuttersControl.pm index d7f3afde6..1a67e748d 100644 --- a/fhem/FHEM/73_AutoShuttersControl.pm +++ b/fhem/FHEM/73_AutoShuttersControl.pm @@ -2,7 +2,7 @@ # # Developed with Kate # -# (c) 2018-2020 Copyright: Marko Oldenburg (leongaultier at gmail dot com) +# (c) 2018-2020 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) # All rights reserved # # Special thanks goes to: @@ -41,6 +41,12 @@ # !!!!! - Innerhalb einer Shutterschleife kein CommandAttr verwenden. Bring Fehler!!! Kommen Raumnamen in die Shutterliste !!!!!! # +package main; + +use Meta; + + + package FHEM::AutoShuttersControl; use strict; @@ -1258,7 +1264,7 @@ sub Initialize { ], "release_status": "testing", "license": "GPL_2", - "version": "v0.10.9", + "version": "v0.10.10", "author": [ "Marko Oldenburg " ], diff --git a/fhem/lib/FHEM/Automation/ShuttersControl.pm b/fhem/lib/FHEM/Automation/ShuttersControl.pm index 489525517..2908d958f 100644 --- a/fhem/lib/FHEM/Automation/ShuttersControl.pm +++ b/fhem/lib/FHEM/Automation/ShuttersControl.pm @@ -506,7 +506,7 @@ sub Notify { { # Kommt ein globales Event und beinhaltet folgende Syntax wird die Funktion zur Verarbeitung aufgerufen if ( grep -m{^(ATTR|DELETEATTR)\s(.*ASC_Time_Up_WE_Holiday|.*ASC_Up|.*ASC_Down|.*ASC_AutoAstroModeMorning|.*ASC_AutoAstroModeMorningHorizon|.*ASC_AutoAstroModeEvening|.*ASC_AutoAstroModeEveningHorizon|.*ASC_Time_Up_Early|.*ASC_Time_Up_Late|.*ASC_Time_Down_Early|.*ASC_Time_Down_Late|.*ASC_autoAstroModeMorning|.*ASC_autoAstroModeMorningHorizon|.*ASC_PrivacyDownValue_beforeNightClose|.*ASC_PrivacyUpValue_beforeDayOpen|.*ASC_autoAstroModeEvening|.*ASC_autoAstroModeEveningHorizon|.*ASC_Roommate_Device|.*ASC_WindowRec|.*ASC_residentsDev|.*ASC_rainSensor|.*ASC_windSensor|.*ASC_tempSensor|.*ASC_BrightnessSensor|.*ASC_twilightDevice|.*ASC_ExternalTrigger|.*ASC_Shading_StateChange_SunnyCloudy)(\s.*|$)}xms, +m{^(ATTR|DELETEATTR)\s(.*ASC_Time_Up_WE_Holiday|.*ASC_Up|.*ASC_Down|.*ASC_AutoAstroModeMorning|.*ASC_AutoAstroModeMorningHorizon|.*ASC_AutoAstroModeEvening|.*ASC_AutoAstroModeEveningHorizon|.*ASC_Time_Up_Early|.*ASC_Time_Up_Late|.*ASC_Time_Down_Early|.*ASC_Time_Down_Late|.*ASC_autoAstroModeMorning|.*ASC_autoAstroModeMorningHorizon|.*ASC_PrivacyDownValue_beforeNightClose|.*ASC_PrivacyUpValue_beforeDayOpen|.*ASC_autoAstroModeEvening|.*ASC_autoAstroModeEveningHorizon|.*ASC_Roommate_Device|.*ASC_WindowRec|.*ASC_residentsDev|.*ASC_rainSensor|.*ASC_windSensor|.*ASC_tempSensor|.*ASC_BrightnessSensor|.*ASC_twilightDevice|.*ASC_ExternalTrigger|.*ASC_Shading_StateChange_SunnyCloudy|.*ASC_TempSensor|.*ASC_Shading_Mode)(\s.*|$)}xms, @{$events} ) { @@ -571,7 +571,7 @@ sub Set { elsif ( lc $cmd eq 'controlshading' ) { return "usage: $cmd" if ( scalar( @{$aArg} ) > 1 ); - my $response = CheckASC_ConditionsForShadingFn($hash); + my $response = CheckASC_ConditionsForShadingFn($hash,$aArg->[0]); readingsSingleUpdate( $hash, $cmd, ( @@ -985,8 +985,6 @@ sub ShuttersCommandSet { ( CheckIfShuttersWindowRecOpen($shuttersDev) == 2 && $shutters->getShuttersPlace eq 'terrace' - && ( $shutters->getLockOut eq 'soft' - || $shutters->getLockOut eq 'hard' ) && !$shutters->getQueryShuttersPos($posValue) ) || ( @@ -1017,7 +1015,9 @@ sub ShuttersCommandSet { ) || ( CheckIfShuttersWindowRecOpen($shuttersDev) == 2 && $shutters->getShuttersPlace eq 'terrace' - && !$shutters->getQueryShuttersPos($posValue) ) + && !$shutters->getQueryShuttersPos($posValue) + && ( $shutters->getLockOut eq 'soft' + || $shutters->getLockOut eq 'hard' ) ) || ( $shutters->getRainProtectionStatus eq 'protected' || $shutters->getWindProtectionStatus eq 'protected' ) ) diff --git a/fhem/lib/FHEM/Automation/ShuttersControl/EventProcessingFunctions.pm b/fhem/lib/FHEM/Automation/ShuttersControl/EventProcessingFunctions.pm index 1f1538236..5a719ee3d 100644 --- a/fhem/lib/FHEM/Automation/ShuttersControl/EventProcessingFunctions.pm +++ b/fhem/lib/FHEM/Automation/ShuttersControl/EventProcessingFunctions.pm @@ -209,8 +209,21 @@ m{^(DELETEATTR|ATTR) #global ATTR myASC ASC_tempSensor Cellar (.*)?}xms ) { - CommandSet( undef, $name . ' controlShading on' ) - if ( ReadingsVal( $name, 'controlShading', 'off' ) ne 'off' ); +# ATTR RolloKinZimSteven_F1 ASC_Shading_Mode off + if ( $events =~ m{^ATTR\s(.*)\sASC_Shading_Mode\s(off)}xms ) { + my %funcHash = ( + hash => $hash, + shuttersdevice => $1, + value => $2, + attrEvent => 1, + ); + + FHEM::Automation::ShuttersControl::Shading::_CheckShuttersConditionsForShadingFn(\%funcHash); + } + else { + CommandSet( undef, $name . ' controlShading on' ) + if ( ReadingsVal( $name, 'controlShading', 'off' ) ne 'off' ); + } } } @@ -913,11 +926,13 @@ sub EventProcessingResidents { for my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) { $FHEM::Automation::ShuttersControl::shutters->setShuttersDev( $shuttersDev); + my $getModeUp = $FHEM::Automation::ShuttersControl::shutters->getModeUp; my $getModeDown = $FHEM::Automation::ShuttersControl::shutters->getModeDown; $FHEM::Automation::ShuttersControl::shutters->setHardLockOut('off'); + if ( $FHEM::Automation::ShuttersControl::ascDev->getSelfDefense eq 'on' @@ -1594,7 +1609,7 @@ sub EventProcessingBrightness { if ( $events =~ m{$reading:\s(\d+(\.\d+)?)}xms ) { my $brightnessMinVal; if ( $FHEM::Automation::ShuttersControl::shutters->getBrightnessMinVal > - -1 ) + -2 ) { $brightnessMinVal = $FHEM::Automation::ShuttersControl::shutters->getBrightnessMinVal; @@ -1606,7 +1621,7 @@ sub EventProcessingBrightness { my $brightnessMaxVal; if ( $FHEM::Automation::ShuttersControl::shutters->getBrightnessMaxVal > - -1 ) + -2 ) { $brightnessMaxVal = $FHEM::Automation::ShuttersControl::shutters->getBrightnessMaxVal; diff --git a/fhem/lib/FHEM/Automation/ShuttersControl/Helper.pm b/fhem/lib/FHEM/Automation/ShuttersControl/Helper.pm index 8fcd653a8..5767ff561 100644 --- a/fhem/lib/FHEM/Automation/ShuttersControl/Helper.pm +++ b/fhem/lib/FHEM/Automation/ShuttersControl/Helper.pm @@ -257,13 +257,13 @@ sub _IsDay { $FHEM::Automation::ShuttersControl::shutters->setShuttersDev($shuttersDev); my $brightnessMinVal = ( - $FHEM::Automation::ShuttersControl::shutters->getBrightnessMinVal > -1 + $FHEM::Automation::ShuttersControl::shutters->getBrightnessMinVal > -2 ? $FHEM::Automation::ShuttersControl::shutters->getBrightnessMinVal : $FHEM::Automation::ShuttersControl::ascDev->getBrightnessMinVal ); my $brightnessMaxVal = ( - $FHEM::Automation::ShuttersControl::shutters->getBrightnessMaxVal > -1 + $FHEM::Automation::ShuttersControl::shutters->getBrightnessMaxVal > -2 ? $FHEM::Automation::ShuttersControl::shutters->getBrightnessMaxVal : $FHEM::Automation::ShuttersControl::ascDev->getBrightnessMaxVal ); @@ -284,7 +284,15 @@ sub _IsDay { $FHEM::Automation::ShuttersControl::shutters ->getTimeUpEarly ) / 86400 ) - && !IsWe() + && ( !IsWe() + || ( IsWe() + && ( $FHEM::Automation::ShuttersControl::ascDev + ->getSunriseTimeWeHoliday eq 'off' + || $FHEM::Automation::ShuttersControl::shutters + ->getTimeUpWeHoliday eq '01:25' + ) + ) + ) ) || ( int( gettimeofday() / 86400 ) != int( @@ -336,7 +344,7 @@ sub _IsDay { && !$FHEM::Automation::ShuttersControl::shutters ->getSunset ) - || !$FHEM::Automation::ShuttersControl::shutters->getSunset + || $FHEM::Automation::ShuttersControl::shutters->getSunrise ) ? 1 : 0 ) if ( $FHEM::Automation::ShuttersControl::shutters->getDown eq diff --git a/fhem/lib/FHEM/Automation/ShuttersControl/Shading.pm b/fhem/lib/FHEM/Automation/ShuttersControl/Shading.pm index 2da13966f..c7c626194 100644 --- a/fhem/lib/FHEM/Automation/ShuttersControl/Shading.pm +++ b/fhem/lib/FHEM/Automation/ShuttersControl/Shading.pm @@ -83,7 +83,8 @@ BEGIN { } sub CheckASC_ConditionsForShadingFn { - my $hash = shift; + my $hash = shift; + my $value = shift; my $error; @@ -96,10 +97,17 @@ sub CheckASC_ConditionsForShadingFn { my $count = 1; for my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) { + my %funcHash = ( + hash => $hash, + shuttersdevice => $shuttersDev, + value => $value, + attrEvent => 0, + ); + InternalTimer( gettimeofday() + $count, 'FHEM::Automation::ShuttersControl::Shading::_CheckShuttersConditionsForShadingFn', - $shuttersDev + \%funcHash ); $count++; @@ -113,7 +121,11 @@ sub CheckASC_ConditionsForShadingFn { } sub _CheckShuttersConditionsForShadingFn { - my $shuttersDev = shift; + my $funcHash = shift; + + my $hash = $funcHash->{hash}; + my $shuttersDev = $funcHash->{shuttersdevice}; + my $value = $funcHash->{value}; $FHEM::Automation::ShuttersControl::shutters->setShuttersDev($shuttersDev); my $shuttersDevHash = $defs{$shuttersDev}; @@ -121,59 +133,67 @@ sub _CheckShuttersConditionsForShadingFn { my $errorMessage; my $warnMessage; my $infoMessage; + + if ( $value eq 'off' ) { + $FHEM::Automation::ShuttersControl::shutters->setShadingStatus('out'); + $infoMessage .= ' shading was deactivated ' . ($funcHash->{attrEvent} ? 'in the device' : 'globally'); + $errorMessage .= ''; + ShadingProcessingDriveCommand( $hash, $shuttersDev ); + } + else { + $infoMessage .= ( + $FHEM::Automation::ShuttersControl::shutters->getShadingMode ne 'off' + && $FHEM::Automation::ShuttersControl::ascDev + ->getAutoShuttersControlShading eq 'on' + && $FHEM::Automation::ShuttersControl::shutters->getOutTemp == -100 + ? ' shading active, global temp sensor is set, but shutters temperature sensor is not set' + : '' + ); - $infoMessage .= ( - $FHEM::Automation::ShuttersControl::shutters->getShadingMode ne 'off' - && $FHEM::Automation::ShuttersControl::ascDev - ->getAutoShuttersControlShading eq 'on' - && $FHEM::Automation::ShuttersControl::shutters->getOutTemp == -100 - ? ' shading active, global temp sensor is set, but shutters temperature sensor is not set' - : '' - ); + $warnMessage .= ( + $FHEM::Automation::ShuttersControl::shutters->getShadingMode eq 'off' + && $FHEM::Automation::ShuttersControl::ascDev + ->getAutoShuttersControlShading eq 'on' + ? ' global shading active but ASC_Shading_Mode attribut is not set or off' + : '' + ); - $warnMessage .= ( - $FHEM::Automation::ShuttersControl::shutters->getShadingMode eq 'off' - && $FHEM::Automation::ShuttersControl::ascDev - ->getAutoShuttersControlShading eq 'on' - ? ' global shading active but ASC_Shading_Mode attribut is not set or off' - : '' - ); + $errorMessage .= ( + $FHEM::Automation::ShuttersControl::shutters->getShadingMode ne 'off' + && $FHEM::Automation::ShuttersControl::ascDev + ->getAutoShuttersControlShading ne 'on' + && $FHEM::Automation::ShuttersControl::ascDev + ->getAutoShuttersControlShading ne 'off' + ? ' ASC_Shading_Mode attribut is set but global shading has errors, look at ASC device ' + . '' + . ReadingsVal( $shuttersDev, 'associatedWith', 'ASC device' ) + . '' + : '' + ); - $errorMessage .= ( - $FHEM::Automation::ShuttersControl::shutters->getShadingMode ne 'off' - && $FHEM::Automation::ShuttersControl::ascDev - ->getAutoShuttersControlShading ne 'on' - && $FHEM::Automation::ShuttersControl::ascDev - ->getAutoShuttersControlShading ne 'off' - ? ' ASC_Shading_Mode attribut is set but global shading has errors, look at ASC device ' - . '' - . ReadingsVal( $shuttersDev, 'associatedWith', 'ASC device' ) - . '' - : '' - ); - - $errorMessage .= ( - $FHEM::Automation::ShuttersControl::shutters->getBrightness == -1 - && $FHEM::Automation::ShuttersControl::shutters->getShadingMode ne - 'off' - ? ' no brightness sensor found, please set ASC_BrightnessSensor attribut' - : '' - ); + $errorMessage .= ( + $FHEM::Automation::ShuttersControl::shutters->getBrightness == -1 + && $FHEM::Automation::ShuttersControl::shutters->getShadingMode ne + 'off' + ? ' no brightness sensor found, please set ASC_BrightnessSensor attribut' + : '' + ); + } $message .= ' ERROR: ' . $errorMessage - if ( defined($errorMessage) + if ( defined($errorMessage) && $errorMessage ne '' ); $message .= ' WARN: ' . $warnMessage - if ( defined($warnMessage) + if ( defined($warnMessage) && $warnMessage ne '' && $errorMessage eq '' ); $message .= ' INFO: ' . $infoMessage - if ( defined($infoMessage) + if ( defined($infoMessage) && $infoMessage ne '' && $errorMessage eq '' ); @@ -452,6 +472,8 @@ sub ShadingProcessing { || $FHEM::Automation::ShuttersControl::shutters->getModeUp eq 'off' || $FHEM::Automation::ShuttersControl::shutters->getModeUp eq 'absent' + || $FHEM::Automation::ShuttersControl::shutters->getModeUp eq + 'gone' || ( $FHEM::Automation::ShuttersControl::shutters->getModeUp eq 'home' && $homemode ne 'asleep' ) diff --git a/fhem/lib/FHEM/Automation/ShuttersControl/Shutters/Attr.pm b/fhem/lib/FHEM/Automation/ShuttersControl/Shutters/Attr.pm index 9128d3cac..86952325b 100644 --- a/fhem/lib/FHEM/Automation/ShuttersControl/Shutters/Attr.pm +++ b/fhem/lib/FHEM/Automation/ShuttersControl/Shutters/Attr.pm @@ -738,9 +738,9 @@ sub _getBrightnessSensor { $self->{ $self->{shuttersDev} }->{ASC_BrightnessSensor}->{reading} = ( $reading ne 'none' ? $reading : 'brightness' ); $self->{ $self->{shuttersDev} }->{ASC_BrightnessSensor}->{triggermin} = - ( $min ne 'none' ? $min : -1 ); + ( $min ne 'none' ? $min : -2 ); $self->{ $self->{shuttersDev} }->{ASC_BrightnessSensor}->{triggermax} = - ( $max ne 'none' ? $max : -1 ); + ( $max ne 'none' ? $max : -2 ); return $self->{ $self->{shuttersDev} }->{ASC_BrightnessSensor}->{device}; }