Skip to content

Instantly share code, notes, and snippets.

@cosmomill
Last active February 22, 2017 21:42
Show Gist options
  • Save cosmomill/f574e2c064c575f851e567aeec0e2206 to your computer and use it in GitHub Desktop.
Save cosmomill/f574e2c064c575f851e567aeec0e2206 to your computer and use it in GitHub Desktop.
Add LaCrosse support to FHEM CUL module. Patch created against rev 12983. https://forum.fhem.de/index.php/topic,36565.0.html
--- 00_CUL.pm.orig 2017-02-21 00:12:13.804553138 +0100
+++ 00_CUL.pm 2017-02-21 18:57:39.000000000 +0100
@@ -51,7 +51,7 @@
my $clientsSlowRF = ":FS20:FHT.*:KS300:USF1000:BS:HMS: ".
":CUL_EM:CUL_WS:CUL_FHTTK:CUL_HOERMANN: ".
":ESA2000:CUL_IR:CUL_TX:Revolt:IT:UNIRoll:SOMFY: ".
- ":$sccMods:CUL_RFR::CUL_TCM97001:CUL_REDIRECT:";
+ ":$sccMods:CUL_RFR::CUL_TCM97001:CUL_REDIRECT:LaCrosse:";
my $clientsHomeMatic = ":CUL_HM:HMS:CUL_IR:$sccMods:";
my $clientsMAX = ":CUL_MAX:HMS:CUL_IR:$sccMods:";
my $clientsWMBus = ":WMBUS:HMS:CUL_IR:$sccMods:";
@@ -80,6 +80,7 @@
"K:CUL_TCM97001" => "^s[A-F0-9]+",
"L:CUL_REDIRECT" => "^o+",
"M:TSSTACKED"=>"^\\*",
+ "O:LaCrosse" => "^N0[1-2][A-F0-9]{8}",
);
my %matchListHomeMatic = (
@@ -157,6 +158,9 @@
{
my ($name, $msg) = @_;
+ # Return nothing for LaCrosse commands
+ return (0, undef) if($msg =~ "^\\S+\\s+9 ");
+
# Store only the "relevant" part, as the CUL won't compute the checksum
$msg = substr($msg, 8) if($msg =~ m/^81/ && length($msg) > 8);
@@ -950,6 +954,32 @@
;
} elsif($fn eq "k" && $len >= 20) { # KOPP_FC
;
+ } elsif($fn eq "N" && $len >= 8) { # LaCrosse
+ # Adapt JeeLink command (F019204356A) to LaCrosse module standard syntax "OK 9 32 1 4 91 62" ("^\\S+\\s+9 ")
+ if( $dmsg =~ m/^N0[1-2][A-F0-9]{8}/ ) {
+ my( $addr, $temperature, $humidity, $batInserted ) = 0.0;
+ $addr = ((hex(substr($dmsg,3,2)) & 0x0F) << 2) | ((hex(substr($dmsg,5,2)) & 0xC0) >> 6);
+ $temperature = ( ( ((hex(substr($dmsg,5,2)) & 0x0F) * 100) + (((hex(substr($dmsg,7,2)) & 0xF0) >> 4) * 10) + (hex(substr($dmsg,7,2)) & 0x0F) ) / 10) - 40;
+ return if($temperature >= 60 || $temperature <= -40);
+
+ $humidity = hex(substr($dmsg,9,2));
+ $batInserted = ( (hex(substr($dmsg,5,2)) & 0x20) << 2 );
+
+ # Build string for 36_LaCrosse.pm
+ my $dmsgMod = "OK 9 $addr ";
+
+ # Bogus check humidity + eval 2 channel TX25IT
+ if (($humidity >= 0 && $humidity <= 99) || $humidity == 106 || ($humidity >= 128 && $humidity <= 227) || $humidity == 234) {
+ $dmsgMod .= (1 | $batInserted);
+ } elsif ($humidity == 125 || $humidity == 253 ) {
+ $dmsgMod .= (2 | $batInserted);
+ }
+
+ $temperature = (($temperature* 10 + 1000) & 0xFFFF);
+ $dmsgMod .= " " . (($temperature >> 8) & 0xFF) . " " . ($temperature & 0xFF) . " $humidity";
+
+ $dmsg = $dmsgMod;
+ }
} else {
DoTrigger($name, "UNKNOWNCODE $dmsg");
Log3 $name, 2, "$name: unknown message $dmsg";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment