2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

30_pilight_contact: new module to support contact sensors

git-svn-id: https://svn.fhem.de/fhem/trunk@12568 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
risiko79 2016-11-13 18:07:45 +00:00
parent a741be83d1
commit dc6321d916
5 changed files with 166 additions and 6 deletions

View File

@ -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.
- feature: 30_pilight_contact: new module to handle pilight contact sensors
- feature: 59_Weather: attribute disable
- new: 10_EQ3BT: Support EQ3 Bluetooth thermostat
define living.thermostat EQ3BT <MAC>

View File

@ -44,6 +44,8 @@
# V 1.17 2016-06-28 - FIX: Experimental splice on scalar is now forbidden - use explizit array notation
# V 1.18 2016-06-28 - NEW: support smoke sensors (protocol: secudo_smoke_sensor)
# V 1.19 2016-09-20 - FIX: PERL WARNING: Subroutine from Blocking.pm redefined
# V 1.20 2016-10-27 - FIX: ContactAsSwitch protocol independend
# V 1.21 2016-11-13 - NEW: support contact sensors
##############################################
package main;
@ -70,7 +72,8 @@ my %matchList = ( "1:pilight_switch" => "^PISWITCH",
"2:pilight_dimmer" => "^PISWITCH|^PIDIMMER|^PISCREEN",
"3:pilight_temp" => "^PITEMP",
"4:pilight_raw" => "^PIRAW",
"5:pilight_smoke" => "^PISMOKE");
"5:pilight_smoke" => "^PISMOKE",
"6:pilight_contact"=> "^PICONTACT");
my @idList = ("id","systemcode","gpio");
my @unitList = ("unit","unitcode","programcode");
@ -99,7 +102,7 @@ sub pilight_ctrl_Initialize($)
$hash->{StateFn} = "pilight_ctrl_State";
$hash->{AttrList}= "ignoreProtocol brands ContactAsSwitch SendTimeout ".$readingFnAttributes;
$hash->{Clients} = ":pilight_switch:pilight_dimmer:pilight_temp:pilight_raw::pilight_smoke:";
$hash->{Clients} = ":pilight_switch:pilight_dimmer:pilight_temp:pilight_raw:pilight_smoke:pilight_contact:";
#$hash->{MatchList} = \%matchList; #only for autocreate
}
@ -570,7 +573,7 @@ sub pilight_ctrl_createWhiteList($)
foreach my $d (keys %defs)
{
my $module = $defs{$d}{TYPE};
next if ($module !~ /pilight_[d|s|t].*/);
next if ($module !~ /pilight_[d|s|t|c].*/);
pilight_ctrl_addWhiteList($own,$defs{$d});
}
@ -782,11 +785,11 @@ sub pilight_ctrl_Parse($$)
# handling ContactAsSwitch befor white list check
my $asSwitch = $attr{$me}{ContactAsSwitch};
if ( defined($asSwitch) && $proto =~ /contact/ && $asSwitch =~ /$id/) {
if ( defined($asSwitch) && $asSwitch =~ /$id/ && ($state =~ /opened/ || $state =~ /closed/) ) {
$proto =~ s/contact/switch/g;
$state =~ s/opened/on/g;
$state =~ s/closed/off/g;
Log3 $me, 5, "$me(Parse): contact as switch for $id";
Log3 $me, 4, "$me(Parse): contact as switch for $id";
}
my @ignoreIDs = split(",",AttrVal($me, "ignoreProtocol",""));
@ -830,7 +833,11 @@ sub pilight_ctrl_Parse($$)
case m/quigg_gt/ {$protoID = 1;}
case m/dimmer/ {$protoID = 2;}
#contact sensors
case m/contact/ {$protoID = 3;}
case m/ev1527/ {$protoID = 3;}
case m/sc2262/ {$protoID = 3;}
#Weather Stations temperature, humidity
case m/alecto/ {$protoID = 4;}
@ -878,7 +885,7 @@ sub pilight_ctrl_Parse($$)
Log3 $me, 4, "$me(Dispatch): $msg";
return Dispatch($hash, $msg ,undef);
}
case 3 {return;}
case 3 { return Dispatch($hash, "PICONTACT,$proto,$id,$unit,$state",undef); }
case 4 {
my $piTempData = "";
$piTempData .= ",temperature:$data->{$s}{temperature}" if (defined($data->{$s}{temperature}));

View File

@ -0,0 +1,147 @@
##############################################
# $Id$
#
# Usage
#
# define <name> pilight_contact <protocol> <id> [unit]
#
# Changelog
#
# V 0.10 2016-11-13 - initial alpha version
##############################################
package main;
use strict;
use warnings;
use Time::HiRes qw(gettimeofday);
use JSON;
sub pilight_contact_Parse($$);
sub pilight_contact_Define($$);
sub pilight_contact_Initialize($)
{
my ($hash) = @_;
$hash->{DefFn} = "pilight_contact_Define";
$hash->{Match} = "^PICONTACT";
$hash->{ParseFn} = "pilight_contact_Parse";
$hash->{StateFn} = "pilight_contact_State";
$hash->{AttrList} = "IODev ".$readingFnAttributes;
}
#####################################
sub pilight_contact_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
if(@a < 4) {
my $msg = "wrong syntax: define <name> pilight_contact <protocol> <id> [unit]";
Log3 undef, 2, $msg;
return $msg;
}
my $me = $a[0];
my $protocol = $a[2];
my $id = $a[3];
my $unit = undef;
$unit = $a[4] if (@a == 5);
$hash->{STATE} = "defined";
$hash->{PROTOCOL} = lc($protocol);
$hash->{ID} = $id;
$hash->{UNIT} = $unit;
#$attr{$me}{verbose} = 5;
$modules{pilight_contact}{defptr}{lc($protocol)}{$me} = $hash;
AssignIoPort($hash);
return undef;
}
#####################################
sub pilight_contact_State($$$$)
{
my ($hash, $time, $name, $val) = @_;
my $me = $hash->{NAME};
#$hash->{STATE} wird nur ersetzt, wenn $hash->{STATE} == ??? fhem.pl Z: 2469
#machen wir es also selbst
$hash->{STATE} = $val if ($name eq "state");
return undef;
}
###########################################
sub pilight_contact_Parse($$)
{
my ($mhash, $rmsg, $rawdata) = @_;
my $backend = $mhash->{NAME};
Log3 $backend, 4, "pilight_contact_Parse ($backend): RCV -> $rmsg";
my ($dev,$protocol,$id,$unit,$state,@args) = split(",",$rmsg);
return () if($dev ne "PICONTACT");
my $chash;
foreach my $n (keys %{ $modules{pilight_contact}{defptr}{lc($protocol)} }) {
my $lh = $modules{pilight_contact}{defptr}{$protocol}{$n};
next if ( !defined($lh->{ID}) );
if ($lh->{ID} eq $id && $lh->{UNIT} eq $unit) {
$chash = $lh;
last;
}
}
return () if (!defined($chash->{NAME}));
readingsBeginUpdate($chash);
readingsBulkUpdate($chash,"state",$state);
readingsEndUpdate($chash, 1);
return $chash->{NAME};
}
1;
=pod
=item summary pilight contact sensors
=item summary_DE pilight Kontaktsensoren
=begin html
<a name="pilight_contact"></a>
<h3>pilight_contact</h3>
<ul>
pilight_contact represents a contact sensor receiving data from pilight<br>
You have to define the base device pilight_ctrl first.<br>
Further information to pilight: <a href="http://www.pilight.org/">http://www.pilight.org/</a><br>
<br>
<a name="pilight_contact_define"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; pilight_contact protocol id [unit]</code>
<br><br>
Example:
<ul>
<code>define myctrl pilight_contact arctech_contact 12836682 1</code><br>
</ul>
</ul>
<br>
<a name="pilight_contact_readings"></a>
<p><b>Readings</b></p>
<ul>
<li>
state<br>
present the current state (open|closed)
</li>
</ul>
</ul>
=end html
=cut

View File

@ -709,3 +709,6 @@
- Wed Nov 5 2016 (loredo)
- adding general (but optional) unit support for FHEM and FHEM modules
- Sun Nov 13 2016 (risiko)
- adding new module 30_pilight_contact

View File

@ -135,6 +135,8 @@ FHEM/30_pilight_dimmer.pm risiko http://forum.fhem.de Sonstige
FHEM/30_pilight_switch.pm risiko http://forum.fhem.de Sonstige Systeme
FHEM/30_pilight_temp.pm risiko http://forum.fhem.de Sonstige Systeme
FHEM/30_pilight_raw.pm risiko http://forum.fhem.de Sonstige Systeme
FHEM/30_pilight_smoke.pm risiko http://forum.fhem.de Sonstige Systeme
FHEM/30_pilight_contact.pm risiko http://forum.fhem.de Sonstige Systeme
FHEM/31_HUEDevice.pm justme1968 http://forum.fhem.de Beleuchtung
FHEM/31_MilightDevice.pm mattwire http://forum.fhem.de Beleuchtung
FHEM/31_ENECSYSINV.pm akw http://forum.fhem.de Sonstige Systeme