From d1ad0c0369a7806345ad7911e0d48b6e4dd8c72b Mon Sep 17 00:00:00 2001
From: andreas-fey <>
Date: Wed, 12 Aug 2015 13:46:42 +0000
Subject: [PATCH] 98_pilight: more protocols and rewrite
git-svn-id: https://svn.fhem.de/fhem/trunk@9060 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/98_pilight.pm | 88 ++++++++++++++++++++++-------------------
2 files changed, 49 insertions(+), 40 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index e4418efb3..7fde6671f 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# 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.
+ - change: 98_pilight: all protocols, rewrite
- feature: 70_PHTV: added support for WoWifi/WoLAN to wake device up
- change: 98_GEOFANCY: improved/tightened input validation. 3rd party mobile
apps need to ensure using correct API data format.
diff --git a/fhem/FHEM/98_pilight.pm b/fhem/FHEM/98_pilight.pm
index 457471222..f5cf7bffe 100644
--- a/fhem/FHEM/98_pilight.pm
+++ b/fhem/FHEM/98_pilight.pm
@@ -13,7 +13,7 @@ pilight_Initialize($)
$hash->{SetFn} = "pilight_Set";
$hash->{DefFn} = "pilight_Define";
- $hash->{AttrList} = "protocol housecode number systemcode unitcode id remote_ip remote_port useOldVersion rawCodeOn rawCodeOff";
+ $hash->{AttrList} = "protocol housecode number systemcode unitcode id remote_ip remote_port useOldVersion rawCodeOn rawCodeOff follow-on-for-timer";
}
# housecode == id und number == unitcode
@@ -27,8 +27,9 @@ pilight_Set($@)
return "no set value specified" if(int(@a) < 2);
return "on off" if($a[1] eq "?");
- shift @a;
- my $command = shift @a;
+ my $command = $a[1];
+ my $c_timer= "";
+ if(defined($a[2])) { $c_timer=$a[2]; }
Log 3, "pilight command: $command";
@@ -36,6 +37,13 @@ pilight_Set($@)
{
$rc = commit($hash, 1);
}
+ elsif($command eq "on-for-timer")
+ {
+ InternalTimer(gettimeofday()+$c_timer, "pilight_on_timeout",$hash, 0);
+ # on-for-timer is now a on.
+ $rc = commit($hash, 1);
+ }
+# elsif
else
{
$rc = commit($hash, 0);
@@ -51,6 +59,22 @@ pilight_Set($@)
return undef;
}
+###################################
+sub
+pilight_on_timeout($)
+{
+ my ($hash) = @_;
+ my @a;
+
+ $a[0]=$hash->{NAME};
+ $a[1]="off";
+
+ pilight_Set($hash,@a);
+
+ return undef;
+}
+
+
sub
pilight_Define($$)
{
@@ -101,48 +125,33 @@ sub commit
return undef
};
- my $data = '{ "message": "client sender" }';
+
+ my $data = $useOldVersion ? '{ "message": "client sender" }' : '{ "action": "identify" }';
$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
+ if ( $data !~ /accept client/ && $data !~ /success/) # "accept client" < v6,
+ {
+ Log 3, "pilight: ERROR. No handshake with pilight-daemon. Received: >>>$data<<<\n";
+ return undef
};
my $code = "{\"protocol\":[ \"$protocol\" ],";
- if($useOldVersion) {
- switch( $protocol ) {
- case 'kaku_switch' { $code = $code . "\"id\":\"$housecode\", \"unit\":\"$unit\",\"$param\":\"1\""}
- case 'quigg_switch' { $code = $code . "\"id\":\"$housecode\", \"unit\":\"$unit\",\"$param\":\"1\""}
- case 'elro' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""}
- case 'elro_he' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""}
- case 'elro_hc' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""}
- case 'silvercrest' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""}
- case 'pollin' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""}
- case 'mumbi' { $code = $code . "\"systemcode\":\"$systemcode\", \"unitcode\":\"$unit\",\"$param\":\"1\""}
- case 'intertechno_old' { $code = $code . "\"id\":\"$systemcode\", \"unit\":\"$unit\",\"$param\":\"1\""}
+ if( $protocol eq 'raw')
+ {
+ switch( $param ) {
+ case 'on' { $code = $code . "\"code\":\"$rawCodeOn\""} # on
+ case 'off' { $code = $code . "\"code\":\"$rawCodeOff\""} #off
}
- }
- else {
- if( $protocol eq 'raw')
- {
- Log 3, "pilight protocol: $protocol";
- Log 4, "pilight raw param: $param";
- Log 4, "pilight rawCodeOn: $rawCodeOn";
- Log 4, "piligth rawCodeCff: $rawCodeOff";
-
- switch( $param ) {
- case 'on' { $code = $code . "\"code\":\"$rawCodeOn\""} # on
- case 'off' { $code = $code . "\"code\":\"$rawCodeOff\""} #off
- }
- }
- else
- {
+ }
+ else
+ {
switch( $protocol ) {
case 'kaku_switch' { $code = $code . "\"id\":$housecode, \"unit\":$unit,\"$param\":1"}
case 'quigg_switch' { $code = $code . "\"id\":$housecode, \"unit\":$unit,\"$param\":1"}
+ case 'quigg_gt7000' { $code = $code . "\"id\":$housecode, \"unit\":$unit,\"$param\":1"}
+ case 'quigg_gt1000' { $code = $code . "\"id\":$housecode, \"unit\":$unit,\"$param\":1"}
case 'elro' { $code = $code . "\"systemcode\":$systemcode, \"unitcode\":$unit,\"$param\":1"}
case 'elro_he' { $code = $code . "\"systemcode\":$systemcode, \"unitcode\":$unit,\"$param\":1"}
case 'elro_hc' { $code = $code . "\"systemcode\":$systemcode, \"unitcode\":$unit,\"$param\":1"}
@@ -153,16 +162,15 @@ sub commit
case 'impuls' { $code = $code . "\"systemcode\":$systemcode, \"programcode\":$unit,\"$param\":1"}
case 'rsl366' { $code = $code . "\"systemcode\":$systemcode, \"programcode\":$unit,\"$param\":1"}
case 'intertechno_old' { $code = $code . "\"id\":$systemcode, \"unit\":$unit,\"$param\":1"}
- case 'clarus_switch' { $code = $code . "\"id\":$systemcode, \"unit\":$unit,\"$param\":1"}
+ case 'clarus_switch' { $code = $code . "\"id\":\"$systemcode\", \"unit\":$unit,\"$param\":1"}
case 'rev1_switch' { $code = $code . "\"id\":\"$systemcode\", \"unit\":$unit,\"$param\":1"}
case 'rev2_switch' { $code = $code . "\"id\":\"$systemcode\", \"unit\":$unit,\"$param\":1"}
case 'rev3_switch' { $code = $code . "\"id\":\"$systemcode\", \"unit\":$unit,\"$param\":1"}
}
- }
}
$code = $code . '}';
- $data = "{ \"message\": \"send\", \"code\": $code}";
+ $data = $useOldVersion ? "{ \"message\": \"send\", \"code\": $code}" : "{ \"action\": \"send\", \"code\": $code}";
Log 3, "pilight data: $data";
$socket->send($data);
@@ -186,7 +194,7 @@ sub commit
Defines a module for setting pilight compartible switches on or off. See Sweetpi.
- Supported protocols: kaku_switch, quigg_switch, elro_he, elro_hc, silvercrest, pollin, brennenstuhl, mumbi, impuls, rsl366, rev1_switch, rev2_switch, clarus_switch, raw, and intertechno_old. If you need more, just write an issue!
+ Supported protocols: kaku_switch, quigg_*, elro_he, elro_hc, silvercrest, pollin, brennenstuhl, mumbi, impuls, rsl366, rev1_switch, rev2_switch, clarus_switch, raw, and intertechno_old. If you need more, just write an issue!
Example:
define Weihnachtsbaum pilight kaku_switch
attr Weihnachtsbaum useOldVersion 1
attr <name> protocol <string>
attr <name> housecode <string>
- attr <name> systemcode <string>
attr <name> unitcode <string>