2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

Added support for Elso protocol

git-svn-id: https://svn.fhem.de/fhem/trunk@5057 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
andreas-fey 2014-02-26 20:33:10 +00:00
parent 46d6f49563
commit 4f5074bec4
3 changed files with 48 additions and 24 deletions

View File

@ -1,6 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- SVN - SVN
- feature: 98_pilight: Added support for Elso protocol
- feature: readingsGroup: added sortDevices attribute - feature: readingsGroup: added sortDevices attribute
- feature: ENIGMA2: new reading 'recordings', new command record - feature: ENIGMA2: new reading 'recordings', new command record
- change: ENIGMA2: rewrite for NonBlocking - change: ENIGMA2: rewrite for NonBlocking

View File

@ -4,6 +4,7 @@ package main;
use strict; use strict;
use warnings; use warnings;
use IO::Socket::INET; use IO::Socket::INET;
use Switch;
sub sub
pilight_Initialize($) pilight_Initialize($)
@ -12,9 +13,10 @@ pilight_Initialize($)
$hash->{SetFn} = "pilight_Set"; $hash->{SetFn} = "pilight_Set";
$hash->{DefFn} = "pilight_Define"; $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 sub
pilight_Set($@) pilight_Set($@)
@ -32,11 +34,11 @@ pilight_Set($@)
if($command eq "on") if($command eq "on")
{ {
$rc = switch($hash, 1); $rc = commit($hash, 1);
} }
else else
{ {
$rc = switch($hash, 0); $rc = commit($hash, 0);
} }
if ($rc) { if ($rc) {
@ -55,24 +57,28 @@ pilight_Define($$)
my ($hash, $def) = @_; my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def); my @a = split("[ \t][ \t]*", $def);
my $u = "wrong syntax: define <name> <protocol> <housecode> <number>"; my $u = "wrong syntax: define <name> <protocol>";
return $u if(int(@a) < 4); return $u if(int(@a) < 2);
$hash->{protocol} = $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; return undef;
} }
sub switch sub commit
{ {
my ($hash, $on) = @_; my ($hash, $on) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $protocol = $hash->{protocol}; my $protocol = $hash->{protocol};
my $housecode = $hash->{housecode}; my $housecode = AttrVal($name, "id", AttrVal($name, "housecode", $hash->{housecode}));
my $number = $hash->{number}; my $unit = AttrVal($name, "unitcode", $hash->{unitcode});
my $systemcode = AttrVal($name, "systemcode", '0');
my $param = $on ? "on" : "off"; my $param = $on ? "on" : "off";
my $remote_ip = AttrVal($name, "remote_ip", '127.0.0.1'); my $remote_ip = AttrVal($name, "remote_ip", '127.0.0.1');
my $remote_port = AttrVal($name, "remote_port", '5000'); my $remote_port = AttrVal($name, "remote_port", '5000');
@ -87,18 +93,31 @@ sub switch
Proto => 'tcp', Proto => 'tcp',
); );
if (!$socket) { Log 3, "pilight: ERROR. Can't open socket to pilight-daemon: $!\n"; if (!$socket) {
return undef}; Log 3, "pilight: ERROR. Can't open socket to pilight-daemon: $!\n";
return undef
};
my $data = '{ "message": "client sender" }'; my $data = '{ "message": "client sender" }';
$socket->send($data); $socket->send($data);
$socket->recv($data,1024); $socket->recv($data,1024);
$data =~ s/\n/ /g; $data =~ s/\n/ /g;
if ( $data !~ /accept client/ ) { Log 3, "pilight: ERROR. No handshake with pilight-daemon. Received: >>>$data<<<\n"; if ( $data !~ /accept client/ ) {
return undef}; 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\"}}"; };
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->send($data);
$socket->close(); $socket->close();
@ -116,13 +135,16 @@ sub switch
<a name="pilight_define"></a> <a name="pilight_define"></a>
<h4>Define</h4> <h4>Define</h4>
<ul> <ul>
<code>define &lt;name&gt; pilight &lt;protocol&gt; &lt;housecode&gt; &lt;number&gt;</code> <code>define &lt;name&gt; pilight &lt;protocol&gt;</code>
<br/> <br/>
<br/> <br/>
Defines a module for setting pilight compartible switches on or off. See <a href="http://www.sweetpi.de/blog/258/funksteckdosen-mit-dem-raspberry-pi-und-pilight-schalten">Sweetpi</a>.<br><br> Defines a module for setting pilight compartible switches on or off. See <a href="http://www.sweetpi.de/blog/258/funksteckdosen-mit-dem-raspberry-pi-und-pilight-schalten">Sweetpi</a>.<br><br>
Supported protocols: kaku_switch, elso. If you need more, just contact me!<br/><br/>
Example: Example:
<ul> <ul>
<code>define Weihnachtsbaum pilight kaku_switch 12323578 0</code><br> <code>define Weihnachtsbaum pilight kaku_switch</code><br>
<code>attr Weihnachtsbaum housecode 12323578</code><br>
<code>attr Weihnachtsbaum unitcode 0</code><br>
</ul> </ul>
<br/> <br/>
If your pilight server does not run on localhost, please set both the attributes <b>remote_ip</b> and <b>remote_port</b>. If your pilight server does not run on localhost, please set both the attributes <b>remote_ip</b> and <b>remote_port</b>.
@ -135,11 +157,11 @@ sub switch
<li><a name="protocol"><code>attr &lt;name&gt; protocol &lt;string&gt;</code></a> <li><a name="protocol"><code>attr &lt;name&gt; protocol &lt;string&gt;</code></a>
<br />Protocol used in pilight, e.g. "kaku_switch"</li> <br />Protocol used in pilight, e.g. "kaku_switch"</li>
<li><a name="user"><code>attr &lt;name&gt; housecode &lt;string&gt;</code></a> <li><a name="user"><code>attr &lt;name&gt; housecode &lt;string&gt;</code></a>
<br />Housecode used in pilight</li> <br />Housecode used in pilight (for protocol kaku*)</li>
<li><a name="user"><code>attr &lt;name&gt; housecode &lt;string&gt;</code></a> <li><a name="user"><code>attr &lt;name&gt; unitcode &lt;string&gt;</code></a>
<br />Housecode used in pilight</li> <br />Unit code/device code used in pilight (for protocol kaku* or elso)</li>
<li><a name="number"><code>attr &lt;name&gt; number &lt;string&gt;</code></a> <li><a name="systemcode"><code>attr &lt;name&gt; systemcode &lt;string&gt;</code></a>
<br />Device number of your switch</li> <br />Systemcode of your switch (for protocol elso)</li>
<li><a name="numer"><code>attr &lt;name&gt; remote_ip &lt;string&gt;</code></a> <li><a name="numer"><code>attr &lt;name&gt; remote_ip &lt;string&gt;</code></a>
<br />Remote IP of you pilight server (127.0.0.1 is default)</li> <br />Remote IP of you pilight server (127.0.0.1 is default)</li>
<li><a name="numer"><code>attr &lt;name&gt; remote_port &lt;string&gt;</code></a> <li><a name="numer"><code>attr &lt;name&gt; remote_port &lt;string&gt;</code></a>

View File

@ -549,4 +549,5 @@
- Sat Feb 16 2014 (immiimmi) - Sat Feb 16 2014 (immiimmi)
- Added new Module "THZ" - Added new Module "THZ"
- Wed Feb 25 2014 (andreas-fey)
- Update on pilight module for more protocols