mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
14_CUL_TCM97001.pm: Implement TCM97001 sensor with temp/hum. Update docu.
git-svn-id: https://svn.fhem.de/fhem/trunk@8101 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6c7a28f35d
commit
852c129edf
@ -20,7 +20,7 @@ CUL_TCM97001_Initialize($)
|
|||||||
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 showtime:1,0 " .
|
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 showtime:1,0 " .
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
$hash->{AutoCreate}=
|
$hash->{AutoCreate}=
|
||||||
{ "CUL_TCM97001.*" => { GPLOT => "temp4:Temp,", FILTER => "%NAME" } };
|
{ "CUL_TCM97001.*" => { GPLOT => "temp4hum4:Temp/Hum,", FILTER => "%NAME" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
@ -30,10 +30,10 @@ CUL_TCM97001_Define($$)
|
|||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
return "wrong syntax: define <name> CUL_TCM97001 <code> [corr] [minsecs]"
|
return "wrong syntax: define <name> CUL_TCM97001 <code>"
|
||||||
if(int(@a) < 3 || int(@a) > 5);
|
if(int(@a) < 3 || int(@a) > 5);
|
||||||
|
|
||||||
$hash->{CODE} = 0; #$a[2];
|
$hash->{CODE} = $a[2];
|
||||||
$hash->{lastT} = 0;
|
$hash->{lastT} = 0;
|
||||||
$hash->{lastH} = 0;
|
$hash->{lastH} = 0;
|
||||||
|
|
||||||
@ -68,7 +68,11 @@ CUL_TCM97001_Parse($$)
|
|||||||
my $def = $modules{CUL_TCM97001}{defptr}{$id3};
|
my $def = $modules{CUL_TCM97001}{defptr}{$id3};
|
||||||
if(!$def) {
|
if(!$def) {
|
||||||
Log3 $hash, 2, "CUL_TCM97001 Unknown device $id3, please define it";
|
Log3 $hash, 2, "CUL_TCM97001 Unknown device $id3, please define it";
|
||||||
|
if (length($msg) == 8) {
|
||||||
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
|
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
|
||||||
|
} else {
|
||||||
|
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
my $now = time();
|
my $now = time();
|
||||||
|
|
||||||
@ -78,6 +82,8 @@ CUL_TCM97001_Parse($$)
|
|||||||
|
|
||||||
my ($msgtype, $val);
|
my ($msgtype, $val);
|
||||||
|
|
||||||
|
if (length($msg) == 8) {
|
||||||
|
# Only tmp device
|
||||||
#eg. 1000 1111 0100 0011 0110 1000 = 21.8C
|
#eg. 1000 1111 0100 0011 0110 1000 = 21.8C
|
||||||
#eg. --> shift2 0100 0011 0110 10
|
#eg. --> shift2 0100 0011 0110 10
|
||||||
my $temp = (hex($a[3].$a[4].$a[5]) >> 2) & 0xFFFF;
|
my $temp = (hex($a[3].$a[4].$a[5]) >> 2) & 0xFFFF;
|
||||||
@ -111,7 +117,6 @@ CUL_TCM97001_Parse($$)
|
|||||||
|
|
||||||
if(defined($t)) {
|
if(defined($t)) {
|
||||||
$state="T: $t";
|
$state="T: $t";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBeginUpdate($def);
|
readingsBeginUpdate($def);
|
||||||
@ -145,6 +150,101 @@ CUL_TCM97001_Parse($$)
|
|||||||
$debug = $debug . $string;
|
$debug = $debug . $string;
|
||||||
Log3 $def, 5, "CUL_TCM97001 DEBUG: $debug";
|
Log3 $def, 5, "CUL_TCM97001 DEBUG: $debug";
|
||||||
readingsEndUpdate($def, 1);
|
readingsEndUpdate($def, 1);
|
||||||
|
} elsif (length($msg) == 12) {
|
||||||
|
# Long with tmp
|
||||||
|
# All nibbles must be reversed
|
||||||
|
# e.g. 154E800480 0001 0101 0100 1110 1000 0000 0000 0100 1000 0000
|
||||||
|
# A B C D E F G H I
|
||||||
|
# A+B = Addess
|
||||||
|
# C Bit 1 Battery
|
||||||
|
# D+E+F Temp
|
||||||
|
# G+H Hum
|
||||||
|
my $bin = undef;
|
||||||
|
|
||||||
|
my @a = split("", $msg);
|
||||||
|
my $bitReverse = undef;
|
||||||
|
my $x = undef;
|
||||||
|
foreach $x (@a) {
|
||||||
|
my $bin3=sprintf("%04b",hex($x));
|
||||||
|
$bitReverse = $bitReverse . reverse($bin3);
|
||||||
|
}
|
||||||
|
my $hexReverse = unpack("H*", pack ("B*", $bitReverse));
|
||||||
|
|
||||||
|
#Split reversed a again
|
||||||
|
my @aReverse = split("", $hexReverse);
|
||||||
|
|
||||||
|
my $CRC = (hex($aReverse[0])+hex($aReverse[1])+hex($aReverse[2])+hex($aReverse[3])
|
||||||
|
+hex($aReverse[4])+hex($aReverse[5])+hex($aReverse[6])+hex($aReverse[7])) & 15;
|
||||||
|
if ($CRC + hex($aReverse[8]) == 15) {
|
||||||
|
Log3 $def, 5, "CUL_TCM97001: CRC OK";
|
||||||
|
my $temp = undef;
|
||||||
|
if (hex($aReverse[5]) > 3) {
|
||||||
|
# negative temp
|
||||||
|
$temp = ((-hex($aReverse[3]) + -hex($aReverse[4]) * 16 + -hex($aReverse[5]) * 256)+1+4096)/10;
|
||||||
|
} else {
|
||||||
|
# positive temp
|
||||||
|
$temp = (hex($aReverse[3]) + hex($aReverse[4]) * 16 + hex($aReverse[5]) * 256)/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
$def->{lastT} = $now;
|
||||||
|
my $humidity = hex($aReverse[7]).hex($aReverse[6]);
|
||||||
|
|
||||||
|
$msgtype = "humidity";
|
||||||
|
$val = $humidity;
|
||||||
|
readingsBeginUpdate($def);
|
||||||
|
readingsBulkUpdate($def, $msgtype, $val);
|
||||||
|
|
||||||
|
$msgtype = "temperature";
|
||||||
|
$val = sprintf("%2.1f", ($temp) );
|
||||||
|
readingsBulkUpdate($def, $msgtype, $val);
|
||||||
|
Log3 $name, 4, "CUL_TCM97001 $msgtype $name $id3 T: $val H: $humidity";
|
||||||
|
|
||||||
|
my $state="";
|
||||||
|
my $t = ReadingsVal($name, "temperature", undef);
|
||||||
|
my $h = ReadingsVal($name, "humidity", undef);
|
||||||
|
if(defined($t) && defined($h)) {
|
||||||
|
$state="T: $t H: $h";
|
||||||
|
|
||||||
|
} elsif(defined($t)) {
|
||||||
|
$state="T: $t";
|
||||||
|
|
||||||
|
} elsif(defined($h)) {
|
||||||
|
$state="H: $h";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsBulkUpdate($def, "state", $state);
|
||||||
|
|
||||||
|
|
||||||
|
my $batbit = hex($aReverse[2]) & 1;
|
||||||
|
my $mode = (hex($aReverse[2]) & 8) >> 3;
|
||||||
|
|
||||||
|
if ($batbit) {
|
||||||
|
readingsBulkUpdate($def, "Battery", "Low");
|
||||||
|
} else {
|
||||||
|
readingsBulkUpdate($def, "Battery", "ok");
|
||||||
|
}
|
||||||
|
if ($mode) {
|
||||||
|
Log3 $def, 5, "CUL_TCM97001 Mode: manual triggert";
|
||||||
|
} else {
|
||||||
|
Log3 $def, 5, "CUL_TCM97001 Mode: auto triggert";
|
||||||
|
}
|
||||||
|
my $debug = "TEMP:$val°C HUM:$humidity :BATT:";
|
||||||
|
if ($batbit) {
|
||||||
|
$debug = $debug . "empty";
|
||||||
|
} else {
|
||||||
|
$debug = $debug . "OK";
|
||||||
|
}
|
||||||
|
$debug = $debug . " HEX:0x";
|
||||||
|
$debug = $debug . $hexReverse;
|
||||||
|
$debug = $debug . " BIN:$bitReverse";
|
||||||
|
Log3 $def, 5, "CUL_TCM97001 DEBUG: $debug";
|
||||||
|
readingsEndUpdate($def, 1);
|
||||||
|
} else {
|
||||||
|
Log3 $def, 5, "CUL_TCM97001: CRC Failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
@ -158,27 +258,20 @@ CUL_TCM97001_Parse($$)
|
|||||||
<a name="CUL_TCM97001"></a>
|
<a name="CUL_TCM97001"></a>
|
||||||
<h3>CUL_TCM97001</h3>
|
<h3>CUL_TCM97001</h3>
|
||||||
<ul>
|
<ul>
|
||||||
The CUL_TCM97001 module interprets temperature messages of TCM 97001 sendor received by the CUL.
|
The CUL_TCM97001 module interprets temperature messages of TCM 97001 sensor received by the CUL.<br>
|
||||||
|
<br>
|
||||||
|
New received device packages are add in fhem category CUL_TCM97001 with autocreate.
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<a name="CUL_TCM97001define"</a>
|
<a name="CUL_TCM97001define"></a>
|
||||||
<b>Define</b> <ul>N/A</ul><br>
|
<b>Define</b> <ul>The received devices created automatically.</ul><br>
|
||||||
|
|
||||||
<a name="CUL_TCM97001set"></a>
|
|
||||||
<b>Set</b> <ul>N/A</ul><br>
|
|
||||||
|
|
||||||
<a name="CUL_TCM97001get"></a>
|
|
||||||
<b>Get</b> <ul>N/A</ul><br>
|
|
||||||
|
|
||||||
<a name="CUL_TCM97001attr"></a>
|
|
||||||
<b>Attributes</b>
|
|
||||||
<ul>N/A</ul>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<a name="CUL_TCM97001events"></a>
|
<a name="CUL_TCM97001events"></a>
|
||||||
<b>Generated events:</b>
|
<b>Generated events:</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>temperature: $temp</li>
|
<li>temperature: $temp</li>
|
||||||
|
<li>humidity: $hum</li>
|
||||||
|
<li>Battery: $bat</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user