Browse Source

add support for sensors sending 24 bit where 12 bit is the device address and 12 bit the value

FloKra 11 tháng trước cách đây
mục cha
commit
c24677194c
3 tập tin đã thay đổi với 37 bổ sung3 xóa
  1. 3 0
      CHANGELOG.txt
  2. 26 3
      cul2mqtt.py
  3. 8 0
      cul2mqtt_devices_example_value.yml

+ 3 - 0
CHANGELOG.txt

@@ -1,3 +1,6 @@
+2023-06-11:
+ - add support for sensors sending 24 bit where 12 bit is the device address and 12 bit the value
+
 2023-05-30:
  - add a status file that is touched every minute as long as something has been received
 

+ 26 - 3
cul2mqtt.py

@@ -412,11 +412,12 @@ def parseRXCode(rx_code, source_cul):
                 #log_write("")
                 log_write("    CUL '" + source_cul + "' received '" + rx_code + "' => DEV: " + receivedForDevice + ", CMD: " + receivedCmnd)
         
-        # if this had no result -> try again with last 16 bit stripped, as in many cases this is only RSSI and not part of the code
-        # in this case treat this last 16bit as sensor value
+        # if this had no result -> try again with last 8 bit stripped, as in many cases this is only RSSI and not part of the code
+        # in this case treat this last 8 bit as sensor value
+        # --> sensor with 16 bit address and 8 bit data (i.E. Arduino sending using RCSwitch library)
         rx_code_stripped = rx_code[0:-2]
         if not sucessfullyParsedITCode and rx_code_stripped in RXcodesToDevFunction_IT:
-            if debug: log_write("    code found in device config with last 16 bit stripped")
+            if debug: log_write("    code found in device config with last 8 bit stripped")
             receivedForDevice = RXcodesToDevFunction_IT[rx_code_stripped][0]
             receivedCmnd = RXcodesToDevFunction_IT[rx_code_stripped][1]
             
@@ -433,6 +434,28 @@ def parseRXCode(rx_code, source_cul):
             if verbose: 
                 #log_write("")
                 log_write("    CUL '" + source_cul + "' received '" + rx_code_stripped + "' => DEV: " + receivedForDevice + ", CMD: " + receivedCmnd + ", VALUE: " + receivedValue)
+                
+        # if this also had no result -> try again with last 12 bit stripped
+        # --> sensor with 12 bit address and 12 bit data (i.E. Arduino sending using RCSwitch library)
+        rx_code_stripped = rx_code[0:-3]
+        if not sucessfullyParsedITCode and rx_code_stripped in RXcodesToDevFunction_IT:
+            if debug: log_write("    code found in device config with last 12 bit stripped")
+            receivedForDevice = RXcodesToDevFunction_IT[rx_code_stripped][0]
+            receivedCmnd = RXcodesToDevFunction_IT[rx_code_stripped][1]
+            
+            receivedValue = rx_code[-3:]
+            
+            # convert value to decimal if enabled for this device
+            if "convertValueToDecimal" in devdata[receivedForDevice]:
+                if devdata[receivedForDevice]["convertValueToDecimal"] == True:
+                    if debug: log_write("    converting value to decimal")
+                    receivedValue = str(int(receivedValue, base=16))
+            
+            sucessfullyParsedITCode = True
+            if debug: log_write("    DEV: " + receivedForDevice + ", CMD: " + receivedCmnd + ", VALUE: " + receivedValue + ", RX: " + rx_code_stripped)
+            if verbose: 
+                #log_write("")
+                log_write("    CUL '" + source_cul + "' received '" + rx_code_stripped + "' => DEV: " + receivedForDevice + ", CMD: " + receivedCmnd + ", VALUE: " + receivedValue)
         
         # if this also did not work, try to parse it as "default/cheap" Intertechno code... 
         if not sucessfullyParsedITCode:

+ 8 - 0
cul2mqtt_devices_example_value.yml

@@ -6,3 +6,11 @@
     #"BATT": "i203C64"
   "statTopic": "D9/Gaszaehler/Impuls"
   "convertValueToDecimal": True
+"TEICH_TEMP":
+  name: "TeichTemp"
+  "RX":
+    "%VALUE%": "i631"
+    #"IMP": "i203C00"
+    #"BATT": "i203C64"
+  "statTopic": "Test/TeichTemp/RAW"
+  "convertValueToDecimal": False