From 76cadddeda6c16b0dbbe0dcab5a24595351ea3e5 Mon Sep 17 00:00:00 2001 From: sidey79 Date: Sat, 9 Mar 2019 23:50:11 +0000 Subject: [PATCH] 14_SD_WS07.pm: Fix autocreate loop bug (Forum #97704 #97910) git-svn-id: https://svn.fhem.de/fhem/trunk@18840 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 ++ fhem/FHEM/14_SD_WS07.pm | 96 ++++++++++++++++++----------------------- 2 files changed, 45 insertions(+), 54 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index e0b046dda..4d57de081 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # 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. + - bugfix: 14_SD_WS07.pm: fix bug autocreate define loop, + broken definitions will be repaired. You need so save your config! + removed rssi, slider for offsets and battery reading - new: 49_Arlo: module for Arlo security cams - feature: 93_DbRep: V8.15.0, readingsRename can be restricted to readings of a optional given device, fix deldoublets in SQLite diff --git a/fhem/FHEM/14_SD_WS07.pm b/fhem/FHEM/14_SD_WS07.pm index e713c61fd..785d8c987 100644 --- a/fhem/FHEM/14_SD_WS07.pm +++ b/fhem/FHEM/14_SD_WS07.pm @@ -4,6 +4,7 @@ # The purpose of this module is to support serval eurochron # weather sensors like eas8007 which use the same protocol # Sidey79, Ralf9 2015-2017 +# Sidey79, elektron-bbs 2018-2019 # # Nexus sensor protocol with ID, temperature and optional humidity # also FreeTec NC-7345 sensors for FreeTec Weatherstation NC-7344. @@ -44,7 +45,9 @@ SD_WS07_Initialize($) $hash->{AttrFn} = "SD_WS07_Attr"; $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 showtime:1,0 " . "negation-batt:no,yes ". - "$readingFnAttributes "; + "max-deviation-temp:1,2,3,4,5,6,7,8,9,10,15,20,25,30,35,40,45,50 ". + "offset-temp ". + "$readingFnAttributes "; $hash->{AutoCreate} = { "SD_WS07_TH_.*" => { ATTR => "event-min-interval:.*:300 event-on-change-reading:.*", FILTER => "%NAME", GPLOT => "temp4hum4:Temp/Hum,", autocreateThreshold => "2:180"}, @@ -90,12 +93,7 @@ sub SD_WS07_Parse($$) { my ($iohash, $msg) = @_; - #my $rawData = substr($msg, 2); - my (undef ,$rawData, $rssi) = split("#",$msg); - if (defined($rssi)) { - $rssi = hex(substr($rssi,1)); - $rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74)); - } + my (undef ,$rawData) = split("#",$msg); #$protocol=~ s/^P(\d+)/$1/; # extract protocol my $model = "SD_WS07"; @@ -104,21 +102,17 @@ SD_WS07_Parse($$) my $blen = $hlen * 4; my $bitData = unpack("B$blen", pack("H$hlen", $rawData)); - if (defined($rssi)) { - Log3 $iohash, 4, "$iohash->{NAME}: SD_WS07_Parse $model ($msg) length: $hlen RSSI = $rssi"; - } else { Log3 $iohash, 4, "$iohash->{NAME}: SD_WS07_Parse $model ($msg) length: $hlen"; - } - # 4 8 9 12 24 28 36 + # 0 4 8 9 12 24 28 36 # 0011 0110 1 010 000100000010 1111 00111000 0000 eas8007 # 0111 0010 1 010 000010111100 1111 00000000 0000 other device from anfichtn # 1101 0010 0 000 000000010001 1111 00101000 other device from elektron-bbs - # 0110 0011 1 000 000011101010 1111 00001010 other device from HomeAuto_User SD_WS07_TH_631 - # 1110 1011 1 000 000010111000 1111 00000000 other device from HomeAuto_User SD_WS07_T_EB1 - # 1100 0100 1 000 000100100010 1111 00000000 other device from HomeAuto_User SD_WS07_T_C41 - # 0110 0100 0 000 000100001110 1111 00101010 hama TS36E from HomeAuto_User - Bat bit identified - # ID Bat CHN TMP ?? HUM + # 0110 0011 1 000 000011101010 1111 00001010 other device from HomeAuto_User SD_WS07_TH_631 + # 1110 1011 1 000 000010111000 1111 00000000 other device from HomeAuto_User SD_WS07_T_EB1 + # 1100 0100 1 000 000100100010 1111 00000000 other device from HomeAuto_User SD_WS07_T_C41 + # 0110 0100 0 000 000100001110 1111 00101010 hama TS36E from HomeAuto_User - Bat bit identified + # ID Bat CHN TMP ?? HUM # Modelliste my %models = ( @@ -154,24 +148,29 @@ SD_WS07_Parse($$) } ### Model specific attributes - if ($models{$modelkey} eq "T") { - addToDevAttrList($model."_".$deviceCode,"max-deviation-temp:1,2,3,4,5,6,7,8,9,10,15,20,25,30,35,40,45,50 "); - addToDevAttrList($model."_".$deviceCode,"offset-temp:slider,-25,1.0,25"); - } elsif ($models{$modelkey} eq "TH") { - addToDevAttrList($model."_".$deviceCode,"max-deviation-temp:1,2,3,4,5,6,7,8,9,10,15,20,25,30,35,40,45,50 "); + if ($models{$modelkey} eq "TH") { addToDevAttrList($model."_".$deviceCode,"max-deviation-hum:1,2,3,4,5,6,7,8,9,10,15,20,25,30,35,40,45,50 "); - addToDevAttrList($model."_".$deviceCode,"offset-temp:slider,-25,1.0,25"); - addToDevAttrList($model."_".$deviceCode,"offset-hum:slider,-50,1.0,50"); + addToDevAttrList($model."_".$deviceCode,"offset-hum"); } #print Dumper($modules{SD_WS07}{defptr}); - - my $def = $modules{SD_WS07}{defptr}{$iohash->{NAME} . "." . $deviceCode}; - $def = $modules{SD_WS07}{defptr}{$deviceCode} if(!$def); - my $device = $model."_".$deviceCode; + my $oldDeviceCode = $deviceCode; # temporary statement to find wrong definitions + + $deviceCode = $model . "_" . $deviceCode; + my $def = $modules{SD_WS07}{defptr}{$deviceCode}; # test for already defined devices use normal naming convention (model_channel or model_lonid) + + if (!defined($def)) # temporary statement: fix wrong definition + { + $def = $modules{SD_WS07}{defptr}{$oldDeviceCode}; # test for already defined devices use wrong naming convention (only channel or longid) + if(defined($def)) { + Log3 $iohash,4, "$def->{NAME}: Updating decrepated DEF of this sensor. Save config is needed to avoid further messages like this."; + CommandModify(undef,"$def->{NAME} $deviceCode") + } + } + if(!$def) { Log3 $iohash, 1, "$iohash->{NAME}: UNDEFINED Sensor $model detected, code $deviceCode"; - return "UNDEFINED $device SD_WS07 $deviceCode"; + return "UNDEFINED $deviceCode SD_WS07 $deviceCode"; } #Log3 $iohash, 3, 'SD_WS07: ' . $def->{NAME} . ' ' . $id; @@ -191,12 +190,12 @@ SD_WS07_Parse($$) $hum += AttrVal($name, "offset-hum", 0); # correction value for humidity (default 0 %) if ($model ne "SD_WS07_T" && $hum > 100 || $model ne "SD_WS07_T" && $hum < 0) { - Log3 $name, 3, "$iohash->{NAME}: $name ERROR - Humidity unknown ($hum)"; + Log3 $name, 4, "$iohash->{NAME}: $name ERROR - Humidity out of range 0-100: ($hum)"; return ""; } - if ($temp > 700 && $temp < 3840) { # -25,6 .. 70,0 °C - Log3 $name, 3, "$iohash->{NAME}: $name ERROR - Temperature unknown ($temp)"; + if ($temp > 700 && $temp < 3840) { # -25,6 .. 70,0 °C + Log3 $name, 4, "$iohash->{NAME}: $name ERROR - Temperature out of range 700-3840 ($temp)"; return ""; } elsif ($temp >= 3840) { # negative Temperaturen, ist ueberprueft worden $temp -= 4096; @@ -261,17 +260,11 @@ SD_WS07_Parse($$) my $state = "T: $temp". ($hum>0 ? " H: $hum":""); readingsBeginUpdate($hash); - readingsBulkUpdate($hash, "model", $models{$modelkey}); + #readingsBulkUpdate($hash, "model", $models{$modelkey}); readingsBulkUpdate($hash, "state", $state); readingsBulkUpdate($hash, "temperature", $temp) if ($temp ne""); readingsBulkUpdate($hash, "humidity", $hum) if ($models{$modelkey} eq "TH"); - #my $battery = ReadingsVal($name, "battery", "unknown"); - #if ($bat ne $battery) { - - readingsBulkUpdate($hash, "battery", $bat); - readingsBulkUpdate($hash, "batteryState", $bat); - - #} + readingsBulkUpdate($hash, "batteryState", $bat); readingsBulkUpdate($hash, "channel", $channel) if ($channel ne ""); readingsEndUpdate($hash, 1); # Notify is done by Dispatch @@ -279,9 +272,6 @@ SD_WS07_Parse($$) #delete $hash->{READINGS}{"humidity"} if($hash->{READINGS} && $models{$modelkey} eq "T"); delete $hash->{READINGS}{humidity} if($hash->{READINGS}{humidity} && $models{$modelkey} eq "T"); - if(defined($rssi)) { - $hash->{RSSI} = $rssi; - } return $name; } @@ -305,7 +295,7 @@ sub SD_WS07_Attr(@) =pod -=item summary Supports weather sensors protocl 7 from SIGNALduino +=item summary Supports weather sensors protocol 7 from SIGNALduino =item summary_DE Unterstützt Wettersensoren mit Protokol 7 vom SIGNALduino =begin html @@ -322,11 +312,13 @@ sub SD_WS07_Attr(@)
New received devices are added in FHEM with autocreate.

+ The module writes from verbose 4 messages, if not possible values like humidity > 100% are decoded. +

Define
@@ -337,7 +329,7 @@ sub SD_WS07_Attr(@)
  • state (T: H:)
  • temperature (°C)
  • humidity: (the humidity 1-100)
  • -
  • battery: (low or ok)
  • +
  • batteryState: (low or ok)
  • channel: (the channelnumberf)

  • @@ -345,11 +337,9 @@ sub SD_WS07_Attr(@)
    @@ -427,11 +417,9 @@ sub SD_WS07_Attr(@)