Browse Source

Merge branch 'master' of https://git.flokra.at/flo/CUL2MQTT

FloKra 1 year ago
parent
commit
fd3ab9674c

+ 11 - 0
README.md

@@ -22,5 +22,16 @@ Features:
 
 
 
+Installation:
 
+(on Raspberry Pi as "pi" in folder /home/pi)
 
+git clone *URL*
+
+Prerequisits:
+- Python 3
+- Python 3 modules (install via pip3): 
+  - pyyaml
+  - pyserial
+  - paho-mqtt
+  

+ 25 - 5
src/cul2mqtt.py → cul2mqtt.py

@@ -381,19 +381,39 @@ def publish_device_statusupdate(device, cmd):
 def parseRXCode(rx_code, source_cul):
     receivedForDevice = None
     receivedCmnd = None
+    
     if rx_code.startswith("i"):
         # parse InterTechno RX code
         if debug: log_write("INTERTECHNO PROTOCOL")
+        sucessfullyParsedITCode = False
+        
+        # look if this code is in the device_config
         if rx_code in RXcodesToDevFunction_IT:
             receivedForDevice = RXcodesToDevFunction_IT[rx_code][0]
             receivedCmnd = RXcodesToDevFunction_IT[rx_code][1]
+            sucessfullyParsedITCode = True
             if debug: log_write("DEV: " + receivedForDevice + ", CMD: " + receivedCmnd + ", RX: " + rx_code)
             if verbose: 
                 log_write("")
                 log_write("CUL '" + source_cul + "' received '" + rx_code + "' => DEV: " + receivedForDevice + ", CMD: " + receivedCmnd)
-        else:
+        
+        # if this had no result -> try again with removed last 2 chars as it is in many cases omitted as its only RSSI and not part of the code
+        rx_code = rx_code[0:-2]
+        if not sucessfullyParsedITCode and rx_code in RXcodesToDevFunction_IT:
+            receivedForDevice = RXcodesToDevFunction_IT[rx_code][0]
+            receivedCmnd = RXcodesToDevFunction_IT[rx_code][1]
+            sucessfullyParsedITCode = True
+            if debug: log_write("DEV: " + receivedForDevice + ", CMD: " + receivedCmnd + ", RX: " + rx_code)
+            if verbose: 
+                log_write("")
+                log_write("CUL '" + source_cul + "' received '" + rx_code + "' => DEV: " + receivedForDevice + ", CMD: " + receivedCmnd)
+        
+        # if this also did not work, try to parse it as "default/cheap" IT code... 
+        if not sucessfullyParsedITCode:
             receivedForDevice, receivedCmnd = decodeInterTechnoRX(rx_code)
-            if debug: log_write(receivedForDevice + ", " + receivedCmnd)
+            if debug: 
+                log_write(str(receivedForDevice) + ", " + str(receivedCmnd))
+            
     else:
         # parse other/RAW RX code
         if debug: log_write("OTHER/RAW PROTOCOL")
@@ -406,9 +426,9 @@ def parseRXCode(rx_code, source_cul):
                 log_write("CUL '" + source_cul + "' received '" + rx_code + "' => DEV: " + receivedForDevice + ", CMD: " + receivedCmnd)
     
     if debug: 
-        log_write("DEV: " + receivedForDevice + ", CMD: " + receivedCmnd + ", RX: " + rx_code)
+        log_write("DEV: " + str(receivedForDevice) + ", CMD: " + str(receivedCmnd) + ", RX: " + rx_code)
     
-    if receivedForDevice != None and receivedCmnd != None:
+    if receivedForDevice != None and receivedCmnd != None and receivedForDevice != False and receivedCmnd != False:
         publish_device_statusupdate(receivedForDevice, receivedCmnd)
 
 def decodeInterTechnoRX(rx_code):
@@ -468,7 +488,7 @@ def decodeInterTechnoRX(rx_code):
             
         else:
             if debug: log_write("unknown or invalid IT code '" + rx_code + "'")
-            return False
+            return False, False
 
     else:
         if debug: log_write("unknown or invalid IT code '" + rx_code + "'")

+ 0 - 0
src/cul2mqtt.service → cul2mqtt.service


+ 0 - 0
src/cul2mqtt_devices.yml → cul2mqtt_devices_example.yml


+ 0 - 0
src/cul2mqtt_disable_service.sh → cul2mqtt_disable_service.sh


+ 0 - 0
src/cul2mqtt_enable_service.sh → cul2mqtt_enable_service.sh


+ 40 - 40
src/cul2mqtt.ini → cul2mqtt_example.ini

@@ -1,40 +1,40 @@
-[main]
-devices_config_yml = cul2mqtt_devices.yml
-log_path = /home/pi/logs/cul2mqtt
-log_enable = true
-filterSelfSentIncomingTimeout = 100
-
-# UART or MQTT
-TX_interface_prefer = MQTT
-
-# also used as min repeat time, in ms
-lastReceivedMaxAge = 500
-
-lastSentMinInterval = 1500
-
-[cul]
-serialPort = /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
-serialBaudrate = 38400
-serialTimeout = 1
-serialCulInitTimeout = 3
-forceSerialCULConnected = False
-receive_from_serial_cul = True
-send_on_serial_cul = True
-culInitCmd = X05
-culSendsRSSI = False
-receive_from_mqtt_cul = True
-send_on_mqtt_cul = True
-
-# for "classic" MQTT-CUL
-#mqtt_cul_topic_received = MQTTCUL/received
-#mqtt_cul_topic_send = MQTTCUL/send
-
-# for Tasmota based MQTT-CUL using Tasmota´s serial bridge functions
-mqtt_cul_topic_received = tele/Tasmota-MQTT-CUL/RESULT
-mqtt_cul_topic_send = cmnd/Tasmota-MQTT-CUL/SerialSend
-
-[mqtt]
-server = mqtt.lan
-port = 1883
-user = mqttuser
-password = xxxxxx
+[main]
+devices_config_yml = cul2mqtt_devices.yml
+log_path = /home/pi/logs/cul2mqtt
+log_enable = true
+filterSelfSentIncomingTimeout = 100
+
+# UART or MQTT
+TX_interface_prefer = MQTT
+
+# also used as min repeat time, in ms
+lastReceivedMaxAge = 500
+
+lastSentMinInterval = 1500
+
+[cul]
+serialPort = /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
+serialBaudrate = 38400
+serialTimeout = 1
+serialCulInitTimeout = 3
+forceSerialCULConnected = False
+receive_from_serial_cul = True
+send_on_serial_cul = True
+culInitCmd = X05
+culSendsRSSI = False
+receive_from_mqtt_cul = True
+send_on_mqtt_cul = True
+
+# for "classic" MQTT-CUL
+#mqtt_cul_topic_received = MQTTCUL/received
+#mqtt_cul_topic_send = MQTTCUL/send
+
+# for Tasmota based MQTT-CUL using Tasmota´s serial bridge functions
+mqtt_cul_topic_received = tele/Tasmota-MQTT-CUL/RESULT
+mqtt_cul_topic_send = cmnd/Tasmota-MQTT-CUL/SerialSend
+
+[mqtt]
+server = mqtt.lan
+port = 1883
+user = mqttuser
+password = xxxxxx

+ 0 - 0
src/cul2mqtt_install_service.sh → cul2mqtt_install_service.sh


+ 0 - 0
src/cul2mqtt_start_service.sh → cul2mqtt_start_service.sh


+ 0 - 0
src/cul2mqtt_stop_service.sh → cul2mqtt_stop_service.sh


+ 0 - 0
src/cul_seriallog.py → cul_seriallog.py