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 " .
|
||||
$readingFnAttributes;
|
||||
$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 @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);
|
||||
|
||||
$hash->{CODE} = 0; #$a[2];
|
||||
$hash->{CODE} = $a[2];
|
||||
$hash->{lastT} = 0;
|
||||
$hash->{lastH} = 0;
|
||||
|
||||
@ -61,14 +61,18 @@ CUL_TCM97001_Parse($$)
|
||||
my ($hash, $msg) = @_;
|
||||
$msg = substr($msg, 1);
|
||||
# Msg format: AAATT
|
||||
my @a = split("", $msg);
|
||||
my @a = split("", $msg);
|
||||
|
||||
my $id3 = hex($a[0] . $a[1]);
|
||||
|
||||
my $def = $modules{CUL_TCM97001}{defptr}{$id3};
|
||||
if(!$def) {
|
||||
Log3 $hash, 2, "CUL_TCM97001 Unknown device $id3, please define it";
|
||||
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
|
||||
if (length($msg) == 8) {
|
||||
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
|
||||
} else {
|
||||
return "UNDEFINED CUL_TCM97001_$id3 CUL_TCM97001 $id3" if(!$def);
|
||||
}
|
||||
}
|
||||
my $now = time();
|
||||
|
||||
@ -78,74 +82,170 @@ CUL_TCM97001_Parse($$)
|
||||
|
||||
my ($msgtype, $val);
|
||||
|
||||
#eg. 1000 1111 0100 0011 0110 1000 = 21.8C
|
||||
#eg. --> shift2 0100 0011 0110 10
|
||||
my $temp = (hex($a[3].$a[4].$a[5]) >> 2) & 0xFFFF;
|
||||
if (length($msg) == 8) {
|
||||
# Only tmp device
|
||||
#eg. 1000 1111 0100 0011 0110 1000 = 21.8C
|
||||
#eg. --> shift2 0100 0011 0110 10
|
||||
my $temp = (hex($a[3].$a[4].$a[5]) >> 2) & 0xFFFF;
|
||||
|
||||
|
||||
my $negative = (hex($a[2]) >> 0) & 0x3;
|
||||
my $negative = (hex($a[2]) >> 0) & 0x3;
|
||||
|
||||
if ($negative == 0x3) {
|
||||
$temp = (~$temp & 0x03FF) + 1;
|
||||
$temp = -$temp;
|
||||
}
|
||||
if ($negative == 0x3) {
|
||||
$temp = (~$temp & 0x03FF) + 1;
|
||||
$temp = -$temp;
|
||||
}
|
||||
|
||||
$temp = $temp / 10;
|
||||
$temp = $temp / 10;
|
||||
|
||||
$def->{lastT} = $now;
|
||||
$msgtype = "temperature";
|
||||
$val = sprintf("%2.1f", ($temp) );
|
||||
Log3 $name, 4, "CUL_TCM97001 $msgtype $name $id3 T: $val";
|
||||
$def->{lastT} = $now;
|
||||
$msgtype = "temperature";
|
||||
$val = sprintf("%2.1f", ($temp) );
|
||||
Log3 $name, 4, "CUL_TCM97001 $msgtype $name $id3 T: $val";
|
||||
|
||||
|
||||
# I think bit 3 on byte 3 is battery warning
|
||||
my $batbit = (hex($a[2]) >> 0) & 0x4;
|
||||
# I think bit 3 on byte 3 is battery warning
|
||||
my $batbit = (hex($a[2]) >> 0) & 0x4;
|
||||
|
||||
my $mode = (hex($a[5]) >> 0) & 0x1;
|
||||
my $mode = (hex($a[5]) >> 0) & 0x1;
|
||||
|
||||
my $unknown = (hex($a[4]) >> 0) & 0x2;
|
||||
|
||||
my $unknown = (hex($a[4]) >> 0) & 0x2;
|
||||
|
||||
|
||||
my $state="";
|
||||
my $t = ReadingsVal($name, "temperature", undef);
|
||||
my $state="";
|
||||
my $t = ReadingsVal($name, "temperature", undef);
|
||||
|
||||
if(defined($t)) {
|
||||
$state="T: $t";
|
||||
if(defined($t)) {
|
||||
$state="T: $t";
|
||||
}
|
||||
|
||||
readingsBeginUpdate($def);
|
||||
readingsBulkUpdate($def, "state", $state);
|
||||
readingsBulkUpdate($def, $msgtype, $val);
|
||||
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";
|
||||
}
|
||||
if ($unknown) {
|
||||
Log3 $def, 5, "CUL_TCM97001 Unknown Bit: $unknown";
|
||||
}
|
||||
my $debug = "TEMP:$val°C BATT:";
|
||||
if ($batbit) {
|
||||
$debug = $debug . "empty";
|
||||
} else {
|
||||
$debug = $debug . "OK";
|
||||
}
|
||||
$debug = $debug . " HEX:0x";
|
||||
$debug = $debug . $a[0].$a[1].$a[2].$a[3].$a[4].$a[5];
|
||||
$debug = $debug . " BIN:";
|
||||
|
||||
my @list = unpack("(A4)*", unpack ('B*', pack ('H*',$a[0].$a[1].$a[2].$a[3].$a[4].$a[5])));
|
||||
my $string = join(" ", @list);
|
||||
$debug = $debug . $string;
|
||||
Log3 $def, 5, "CUL_TCM97001 DEBUG: $debug";
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
readingsBeginUpdate($def);
|
||||
readingsBulkUpdate($def, "state", $state);
|
||||
readingsBulkUpdate($def, $msgtype, $val);
|
||||
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";
|
||||
}
|
||||
if ($unknown) {
|
||||
Log3 $def, 5, "CUL_TCM97001 Unknown Bit: $unknown";
|
||||
}
|
||||
my $debug = "TEMP:$val°C BATT:";
|
||||
if ($batbit) {
|
||||
$debug = $debug . "empty";
|
||||
} else {
|
||||
$debug = $debug . "OK";
|
||||
}
|
||||
$debug = $debug . " HEX:0x";
|
||||
$debug = $debug . $a[0].$a[1].$a[2].$a[3].$a[4].$a[5];
|
||||
$debug = $debug . " BIN:";
|
||||
|
||||
my @list = unpack("(A4)*", unpack ('B*', pack ('H*',$a[0].$a[1].$a[2].$a[3].$a[4].$a[5])));
|
||||
my $string = join(" ", @list);
|
||||
$debug = $debug . $string;
|
||||
Log3 $def, 5, "CUL_TCM97001 DEBUG: $debug";
|
||||
readingsEndUpdate($def, 1);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
@ -158,27 +258,20 @@ CUL_TCM97001_Parse($$)
|
||||
<a name="CUL_TCM97001"></a>
|
||||
<h3>CUL_TCM97001</h3>
|
||||
<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>
|
||||
|
||||
<a name="CUL_TCM97001define"</a>
|
||||
<b>Define</b> <ul>N/A</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_TCM97001define"></a>
|
||||
<b>Define</b> <ul>The received devices created automatically.</ul><br>
|
||||
|
||||
<a name="CUL_TCM97001events"></a>
|
||||
<b>Generated events:</b>
|
||||
<ul>
|
||||
<li>temperature: $temp</li>
|
||||
<li>humidity: $hum</li>
|
||||
<li>Battery: $bat</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user