瀏覽代碼

- add support for DIY DS18B20 sensor sending via 433MHz cheap transmitter

FloKra 1 年之前
父節點
當前提交
1ba93354f1
共有 3 個文件被更改,包括 57 次插入5 次删除
  1. 3 0
      CHANGELOG.txt
  2. 51 4
      cul2mqtt.py
  3. 3 1
      cul2mqtt_devices_example_value.yml

+ 3 - 0
CHANGELOG.txt

@@ -1,3 +1,6 @@
+2023-06-11:
+ - add support for DIY DS18B20 sensor sending via 433MHz cheap transmitter
+ 
 2023-06-11:
  - add support for sensors sending 24 bit where 12 bit is the device address and 12 bit the value
 

+ 51 - 4
cul2mqtt.py

@@ -395,6 +395,7 @@ def parseRXCode(rx_code, source_cul):
     receivedForDevice = None
     receivedCmnd = None
     receivedValue = None
+    skipPublishing = False
     
     if rx_code.startswith("i"):
         # parse Intertechno RX code
@@ -444,13 +445,59 @@ def parseRXCode(rx_code, source_cul):
             receivedCmnd = RXcodesToDevFunction_IT[rx_code_stripped][1]
             
             receivedValue = rx_code[-3:]
+            tmpReceivedValue = int(receivedValue, base=16)
             
-            # convert value to decimal if enabled for this device
-            if "convertValueToDecimal" in devdata[receivedForDevice]:
+            if debug: log_write("    RAW receivedValue=" + hex(tmpReceivedValue))
+            
+            
+            # sensor type DS18B20
+            # -> convert raw data to temperature °C
+            if "isSensorType" in devdata[receivedForDevice]:
+                if devdata[receivedForDevice]["isSensorType"] == "DS18B20":
+                    if debug: 
+                        log_write("    is sensor type DS18B20")
+                        log_write("    converting RAW data...")
+                    
+                    if tmpReceivedValue == 0xfff or tmpReceivedValue == 0xffe:
+                        _battState = ""
+                        # this is a low battery warning
+                        # -> send warning on MQTT if configured and skip value transmitting
+                        if "battTopic" in devdata[receivedForDevice]:
+                            if devdata[receivedForDevice]["battTopic"] is not None:
+                                if tmpReceivedValue == 0xfff:
+                                    _battState = "OK"
+                                elif tmpReceivedValue == 0xffe:
+                                    _battState = "LOW"
+                                mqttc.publish(devdata[receivedForDevice]["battTopic"], _battState, qos=0, retain=False)
+                                skipPublishing = True # no data will be published this time
+                    else:
+                        # left shift 2 bits as sender right shifts it
+                        tmpReceivedValue = tmpReceivedValue << 2
+                        
+                        if debug: log_write("    receivedValue=" + str(tmpReceivedValue))
+                        
+                        # if MSB (bit 13) == 1 -> negative value
+                        if tmpReceivedValue >= 8192:
+                            tmpReceivedValue = tmpReceivedValue - 16384
+                        
+                        tmpReceivedValue = round(0.0078125 * tmpReceivedValue, 1)
+                        if debug: log_write("    converted value=" + str(tmpReceivedValue))
+                        
+                        if tmpReceivedValue >= -50 and tmpReceivedValue <= 125:
+                            receivedValue = str(tmpReceivedValue)
+                        else:
+                            log_write("    WARN: value out of range - skipping")
+                            skipPublishing = True # no data will be published this time
+                        
+            
+            # not a "special" sensor but convertValueToDecimal is enabled
+            # -> convert value to decimal if enabled for this device
+            elif "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: 
@@ -481,7 +528,7 @@ def parseRXCode(rx_code, source_cul):
     #if debug: 
     #    log_write("    DEV: " + str(receivedForDevice) + ", CMD: " + str(receivedCmnd) + ", RX: " + rx_code)
     
-    if receivedForDevice != None and receivedCmnd != None and receivedForDevice != False and receivedCmnd != False:
+    if receivedForDevice != None and receivedCmnd != None and receivedForDevice != False and receivedCmnd != False and not skipPublishing:
         publish_device_statusupdate(receivedForDevice, receivedCmnd, receivedValue)
 
 def decodeInterTechnoRX(rx_code):
@@ -667,7 +714,7 @@ def cul_received(payload, source_cul):
         # split string and extract last row as we dont need the rest
         splitPayload = payload.split(' ')
         actualPayload = splitPayload[len(splitPayload)-1]
-        if debug: log_write("    actualPayload: '" + actualPayload)
+        if debug: log_write("    actualPayload: " + actualPayload)
                 
         ignoreCommand = False
                 

+ 3 - 1
cul2mqtt_devices_example_value.yml

@@ -12,5 +12,7 @@
     "%VALUE%": "i631"
     #"IMP": "i203C00"
     #"BATT": "i203C64"
-  "statTopic": "Test/TeichTemp/RAW"
+  "statTopic": "Test/TeichTemp/Temp"
+  "battTopic": "Test/TeichTemp/Batt"
+  "isSensorType": "DS18B20"
   "convertValueToDecimal": False