diff --git a/fhem/CHANGED b/fhem/CHANGED index 1a48bfecc..5056a4973 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - feature: PRESENCE: new set command "powerOn" to execute a Perl function + which power on the checked device (given via attribute) - feature: readingsGroup: added valueColumn attribute - feature: readingsGroup: added ...,@,... argument format - feature: 52_I2C_PCF8574.pm: added attribute OnStartup diff --git a/fhem/FHEM/73_PRESENCE.pm b/fhem/FHEM/73_PRESENCE.pm index 7b8d7852b..a32c673ff 100755 --- a/fhem/FHEM/73_PRESENCE.pm +++ b/fhem/FHEM/73_PRESENCE.pm @@ -51,7 +51,7 @@ PRESENCE_Initialize($) $hash->{DefFn} = "PRESENCE_Define"; $hash->{UndefFn} = "PRESENCE_Undef"; $hash->{AttrFn} = "PRESENCE_Attr"; - $hash->{AttrList}= "do_not_notify:0,1 disable:0,1 fritzbox_repeater:0,1 ping_count:1,2,3,4,5,6,7,8,9,10 ".$readingFnAttributes; + $hash->{AttrList}= "do_not_notify:0,1 disable:0,1 fritzbox_repeater:0,1 ping_count:1,2,3,4,5,6,7,8,9,10 powerOnFn ".$readingFnAttributes; } @@ -238,7 +238,6 @@ sub PRESENCE_Undef($$) { my ($hash, $arg) = @_; - my $name = $hash->{NAME}; RemoveInternalTimer($hash); @@ -255,16 +254,20 @@ sub PRESENCE_Set($@) { my ($hash, @a) = @_; - + my $name = $hash->{NAME}; + return "No Argument given" if(!defined($a[1])); my $usage = "Unknown argument ".$a[1].", choose one of statusRequest"; + my $powerOnFn = AttrVal($name, "powerOnFn", undef); + $usage .= " powerOn" if(defined($powerOnFn)); + if($a[1] eq "statusRequest") { if($hash->{MODE} ne "lan-bluetooth") { - Log3 $hash->{NAME}, 5, "PRESENCE (".$hash->{NAME}.") - starting local scan"; + Log3 $name, 5, "PRESENCE ($name) - starting local scan"; PRESENCE_StartLocalScan($hash, 1); return undef; } @@ -276,10 +279,36 @@ PRESENCE_Set($@) } else { - return "PRESENCE Definition \"".$hash->{NAME}."\" is not connected to ".$hash->{DeviceName}; + return "PRESENCE Definition \"$name\" is not connected to ".$hash->{DeviceName}; } } } + elsif(defined($powerOnFn) && $a[1] eq "powerOn") + { + my %specials= ( + "%NAME" => $name, + "%ADDRESS" => $hash->{ADDRESS}, + "%ARGUMENT" => $a[2] + ); + + $powerOnFn= EvalSpecials($powerOnFn, %specials); + + Log3 $name, 5, "PRESENCE ($name) - executing powerOnFn: $powerOnFn"; + eval $powerOnFn; + + if($@) + { + Log3 $name, 3, "PRESENCE ($name) - executed powerOnFn failed: ".$@; + readingsSingleUpdate($hash, "powerOnFn", "failed",1); + return "executed powerOnFn failed: ".$@; + } + else + { + readingsSingleUpdate($hash, "powerOnFn", "executed",1); + } + + return undef; + } else { return $usage; @@ -360,6 +389,18 @@ PRESENCE_Attr(@) PRESENCE_StartLocalScan($hash); } } + elsif($a[0] eq "set" and $a[2] eq "powerOnFn") + { + my $powerOnFn = $a[3]; + + $powerOnFn =~ s/^\s+//; + $powerOnFn =~ s/\s+$//; + + if($powerOnFn eq "") + { + return "powerOnFn contains no value"; + } + } return undef; } @@ -372,7 +413,7 @@ sub PRESENCE_Read($) { my ($hash) = @_; - + my $name = $hash->{NAME}; my $buf = DevIo_SimpleRead($hash); return "" if(!defined($buf)); @@ -398,7 +439,6 @@ PRESENCE_Read($) { readingsBulkUpdate($hash, "device_name", $1); } - } elsif($buf eq "command accepted") { @@ -410,19 +450,19 @@ PRESENCE_Read($) } elsif($buf =~ /socket_closed;(.+?)$/) { - Log3 $hash->{NAME}, 3, "PRESENCE: collectord lost connection to room $1 for device ".$hash->{NAME}; + Log3 $hash->{NAME}, 3, "PRESENCE ($name) - collectord lost connection to room $1 for device ".$hash->{NAME}; } elsif($buf =~ /socket_reconnected;(.+?)$/) { - Log3 $hash->{NAME}, 3, "PRESENCE: collectord reconnected to room $1 for device ".$hash->{NAME}; + Log3 $hash->{NAME}, 3, "PRESENCE ($name) - collectord reconnected to room $1 for device ".$hash->{NAME}; } elsif($buf =~ /error;(.+?)$/) { - Log3 $hash->{NAME}, 3, "PRESENCE: room $1 cannot execute hcitool to check device ".$hash->{NAME}; + Log3 $hash->{NAME}, 3, "PRESENCE ($name) - room $1 cannot execute hcitool to check device ".$hash->{NAME}; } elsif($buf =~ /error$/) { - Log3 $hash->{NAME}, 3, "PRESENCE: presenced cannot execute hcitool to check device ".$hash->{NAME}; + Log3 $hash->{NAME}, 3, "PRESENCE ($name) - presenced cannot execute hcitool to check device ".$hash->{NAME}; } readingsEndUpdate($hash, 1); @@ -1093,6 +1133,7 @@ Options: Set
@@ -1123,8 +1164,18 @@ Options:

Possible values: 0 => Use default recognition, 1 => Use repeater-supported recognition
Default Value is 0 (Use default recognition) -

+
  • powerOnFn

  • + Define a Perl statement, which powers on the device.

    + + When executing the powerOnFn (set command: powerOn) following placeholders will be replaced by there corresponding values:

    + +
    + Example: powerOn("%ADDRESS", "username", "password")
    @@ -1134,6 +1185,7 @@ Options: General Events:



    Bluetooth specific events:


    @@ -1363,6 +1427,7 @@ Options: Generelle Events:



    Bluetooth-spezifische Events: