From 08a5cc97e49477e7ca16e7b77e105540df480272 Mon Sep 17 00:00:00 2001 From: orti-otto <> Date: Wed, 19 Apr 2017 20:04:24 +0000 Subject: [PATCH] 98_RandomTimer: should solve the problem with the disable attribute: https://forum.fhem.de/index.php/topic,14010.msg621068.html#msg621068 git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@14040 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/98_RandomTimer.pm | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/FHEM/98_RandomTimer.pm b/FHEM/98_RandomTimer.pm index bafa906f2..696699c63 100644 --- a/FHEM/98_RandomTimer.pm +++ b/FHEM/98_RandomTimer.pm @@ -108,6 +108,8 @@ sub RandomTimer_Define($$) $hash->{helper}{S_REL} = $srel; $hash->{COMMAND} = Value($hash->{DEVICE}); + #$attr{$name}{verbose} = 4; + readingsSingleUpdate ($hash, "TimeToSwitch", $hash->{helper}{TIMETOSWITCH}, 1); myRemoveInternalTimer("SetTimer", $hash); @@ -151,12 +153,17 @@ sub RandomTimer_SetTimer($) { # attr Test verbose 5 ; # define ds at +00:00:30 attr Test disable 1 ; # +# delete RT_Test; define RT_Test RandomTimer *22:00:00 Brunnen 23:00:00 300 +# set RT_Test disable 0 +# delete RT_Test sub RandomTimer_Exec($) { my ($myHash) = @_; my $hash = myGetHashIndirekt($myHash, (caller(0))[3]); return if (!defined($hash)); - + + my $now = time(); + # Wenn aktiv aber disabled, dann timer abschalten, Meldung ausgeben. my $active = RandomTimer_isAktive($hash); my $disabled = RandomTimer_isDisabled($hash); @@ -201,15 +208,19 @@ sub RandomTimer_Exec($) { return; } if (!$disabled) { - Log3 $hash, 3, "[".$hash->{NAME}."]"." starting RandomTimer on $hash->{DEVICE}: " - . strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - " - . strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime})); - RandomTimer_setActive($hash,1); + if ($now>$hash->{helper}{startTime} && $now<$hash->{helper}{stopTime}) { + Log3 $hash, 3, "[".$hash->{NAME}."]"." starting RandomTimer on $hash->{DEVICE}: " + . strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - " + . strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime})); + RandomTimer_setActive($hash,1); + } } } RandomTimer_setState($hash); - RandomTimer_device_toggle($hash) if (!$disabled); + if ($now>$hash->{helper}{startTime} && $now<$hash->{helper}{stopTime}) { + RandomTimer_device_toggle($hash) if (!$disabled); + } my $nextSwitch = time() + RandomTimer_getSecsToNextAbschaltTest($hash); myRemoveInternalTimer("Exec", $hash); @@ -575,6 +586,17 @@ sub RandomTimer_Wakeup() { # {RandomTimer_Wakeup()} + the decision to switch on or off depends on the state of the device and is evaluated by the funktion Value(). Value() must + evaluate one of the values "on" or "off". The behavior of devices that do not evaluate one of those values can be corrected by defining a statFormat: +
+       attr stateFormat  EDIPlug_01  {(ReadingsVal("EDIPlug_01","state","nF") =~ m/(ON|on)/i)  ? "on" : "off" }
+    
+ if a devices Value() funktion does not evalute to on or off(like WLAN-Steckdose von Edimax) you get the message: +
+       [EDIPlug] result of function Value(EDIPlug_01) must be 'on' or 'off'
+    
+ +
  • switchmode
    Setting the switchmode you can influence the behavior of switching on/off. The parameter has the Format 999/999 and the default ist 800/200. The values are in "per mill".