diff --git a/fhem/CHANGED b/fhem/CHANGED index fac649546..fc1e040d0 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,6 +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. - SVN + - feature: 98_pilight: Added support for Elso protocol - feature: readingsGroup: added sortDevices attribute - feature: ENIGMA2: new reading 'recordings', new command record - change: ENIGMA2: rewrite for NonBlocking diff --git a/fhem/FHEM/98_pilight.pm b/fhem/FHEM/98_pilight.pm index 5d3c42b32..e7f8d73c6 100644 --- a/fhem/FHEM/98_pilight.pm +++ b/fhem/FHEM/98_pilight.pm @@ -4,6 +4,7 @@ package main; use strict; use warnings; use IO::Socket::INET; +use Switch; sub pilight_Initialize($) @@ -12,9 +13,10 @@ pilight_Initialize($) $hash->{SetFn} = "pilight_Set"; $hash->{DefFn} = "pilight_Define"; - $hash->{AttrList} = "protocol housecode number remote_ip remote_port"; + $hash->{AttrList} = "protocol housecode number systemcode unitcode id remote_ip remote_port"; } +# housecode == id und number == unitcode ################################### sub pilight_Set($@) @@ -32,11 +34,11 @@ pilight_Set($@) if($command eq "on") { - $rc = switch($hash, 1); + $rc = commit($hash, 1); } else { - $rc = switch($hash, 0); + $rc = commit($hash, 0); } if ($rc) { @@ -55,24 +57,28 @@ pilight_Define($$) my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); - my $u = "wrong syntax: define "; - return $u if(int(@a) < 4); + my $u = "wrong syntax: define "; + return $u if(int(@a) < 2); $hash->{protocol} = $a[2]; - $hash->{housecode} = $a[3]; - $hash->{number} = $a[4]; + + #for backward compartibility + + $hash->{housecode} = (int(@a) > 2) ? $a[3] : ''; + $hash->{unitcode} = (int(@a) > 2) ? $a[4] : ''; return undef; } -sub switch +sub commit { my ($hash, $on) = @_; my $name = $hash->{NAME}; my $protocol = $hash->{protocol}; - my $housecode = $hash->{housecode}; - my $number = $hash->{number}; + my $housecode = AttrVal($name, "id", AttrVal($name, "housecode", $hash->{housecode})); + my $unit = AttrVal($name, "unitcode", $hash->{unitcode}); + my $systemcode = AttrVal($name, "systemcode", '0'); my $param = $on ? "on" : "off"; my $remote_ip = AttrVal($name, "remote_ip", '127.0.0.1'); my $remote_port = AttrVal($name, "remote_port", '5000'); @@ -87,18 +93,31 @@ sub switch Proto => 'tcp', ); - if (!$socket) { Log 3, "pilight: ERROR. Can't open socket to pilight-daemon: $!\n"; - return undef}; + if (!$socket) { + Log 3, "pilight: ERROR. Can't open socket to pilight-daemon: $!\n"; + return undef + }; my $data = '{ "message": "client sender" }'; $socket->send($data); $socket->recv($data,1024); $data =~ s/\n/ /g; - if ( $data !~ /accept client/ ) { Log 3, "pilight: ERROR. No handshake with pilight-daemon. Received: >>>$data<<<\n"; - return undef}; - - my $data = "{ \"message\": \"send\", \"code\": {\"protocol\":[ \"$protocol\" ],\"id\":\"$housecode\", \"unit\":\"$number\",\"$param\":\"1\"}}"; + if ( $data !~ /accept client/ ) { + Log 3, "pilight: ERROR. No handshake with pilight-daemon. Received: >>>$data<<<\n"; + return undef + }; + + my $code = "{\"protocol\":[ \"$protocol\" ],"; + switch( $protocol ) { + case 'kaku_switch' { $code = $code . "\"id\":\"$housecode\", \"unit\":\"$unit\",\"$param\":\"1\""} + case 'elro' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""} + } + $code = $code . '}'; + + $data = "{ \"message\": \"send\", \"code\": $code}"; + Log 3, "pilight data: $data"; + $socket->send($data); $socket->close(); @@ -116,13 +135,16 @@ sub switch

Define

    - define <name> pilight <protocol> <housecode> <number> + define <name> pilight <protocol>

    Defines a module for setting pilight compartible switches on or off. See Sweetpi.

    + Supported protocols: kaku_switch, elso. If you need more, just contact me!

    Example:
      - define Weihnachtsbaum pilight kaku_switch 12323578 0
      + define Weihnachtsbaum pilight kaku_switch
      + attr Weihnachtsbaum housecode 12323578
      + attr Weihnachtsbaum unitcode 0

    If your pilight server does not run on localhost, please set both the attributes remote_ip and remote_port. @@ -135,11 +157,11 @@ sub switch
  • attr <name> protocol <string>
    Protocol used in pilight, e.g. "kaku_switch"
  • attr <name> housecode <string> -
    Housecode used in pilight
  • -
  • attr <name> housecode <string> -
    Housecode used in pilight
  • -
  • attr <name> number <string> -
    Device number of your switch
  • +
    Housecode used in pilight (for protocol kaku*) +
  • attr <name> unitcode <string> +
    Unit code/device code used in pilight (for protocol kaku* or elso)
  • +
  • attr <name> systemcode <string> +
    Systemcode of your switch (for protocol elso)
  • attr <name> remote_ip <string>
    Remote IP of you pilight server (127.0.0.1 is default)
  • attr <name> remote_port <string> diff --git a/fhem/HISTORY b/fhem/HISTORY index 5523e15b6..f8328f201 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -549,4 +549,5 @@ - Sat Feb 16 2014 (immiimmi) - Added new Module "THZ" - +- Wed Feb 25 2014 (andreas-fey) + - Update on pilight module for more protocols