Przeglądaj źródła

2023-08-29
- added 4th input
- changed default baudrate to 115200

FloKra 1 rok temu
rodzic
commit
cfeb09fc3a
3 zmienionych plików z 77 dodań i 30 usunięć
  1. 8 5
      CHANGELOG.txt
  2. 28 7
      ioext/config.py
  3. 41 18
      ioext/ioext.py

+ 8 - 5
CHANGELOG.txt

@@ -1,6 +1,9 @@
-30.05.2023
-	separate config in python daemon
+2023-08-29
+ - added 4th input
+ - changed default baudrate to 115200
 
-14.03.2023
-	initial checkin
-	
+2023-05-30
+ - separate config in python daemon
+
+2023-03-14
+ - initial checkin

+ 28 - 7
ioext/config.py

@@ -10,7 +10,7 @@ statusFile = ''
 
 # serial port config
 serialPort = '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'
-serialBaud = 57600
+serialBaud = 115200
 serialTimeout = 1 # should be 1 as above interval/timeout relies on it
 
 # MQTT config
@@ -18,11 +18,32 @@ mqtt_server = "mqtt.lan"
 mqtt_port = 1883
 mqtt_user = ""
 mqtt_password = ""
-
 mqtt_base_topic = "T5/HomeSvrIOExt"
 
-mqtt_topic_tuerkontakt = "T5/Wohnungstuer/Tuerkontakt"
-mqtt_topic_pir1 = "T5/VZ/PIR1"
-mqtt_topic_pir2 = "T5/VZ/PIR2"
-mqtt_topic_out_temp = "T5/Abstr/Sensors/temp"
-mqtt_topic_out_hum = "T5/Abstr/Sensors/hum"
+# Input Pins / MQTT Topics/Settings
+P2_MQTT_Topic = "T5/Wohnungstuer/Tuerkontakt"
+P2_MQTT_SendRetained = True
+P2_MQTT_SendLastUpdate = True
+P2_MQTT_SendOnlyIfValueChanged = True
+
+P3_MQTT_Topic = "T5/VZ/PIR1"
+P3_MQTT_SendRetained = False
+P3_MQTT_SendLastUpdate = False
+P3_MQTT_SendOnlyIfValueChanged = True
+
+P4_MQTT_Topic = "T5/VZ/PIR2"
+P4_MQTT_SendRetained = False
+P4_MQTT_SendLastUpdate = False
+P4_MQTT_SendOnlyIfValueChanged = True
+
+P5_MQTT_Topic = "T5/VZ/PRESENCE"
+P5_MQTT_SendRetained = False
+P5_MQTT_SendLastUpdate = False
+P5_MQTT_SendOnlyIfValueChanged = True
+
+DHT22_MQTT_Topic_Temp = "T5/Abstr/Sensors/temp"
+DHT22_MQTT_Topic_Hum = "T5/Abstr/Sensors/hum"
+DHT22_MQTT_SendRetained = False
+DHT22_MQTT_SendLastUpdate = False
+
+

+ 41 - 18
ioext/ioext.py

@@ -6,6 +6,7 @@ import os
 import sys
 import paho.mqtt.client as mqtt
 import json
+from datetime import datetime
 
 # --- CONFIGURATION ---
 import config
@@ -20,9 +21,10 @@ verbose = False
 debug = False
 quiet = True
 
-lastState_tk = None
-lastState_pir1 = None
-lastState_pir2 = None
+lastState_P2 = None
+lastState_P3 = None
+lastState_P4 = None
+lastState_P5 = None
 # --- END GLOBAL VARS ---
 
 
@@ -121,7 +123,7 @@ try:
                 print ('RX: ' + repr(serLine))    #Echo the serial buffer bytes up to the CRLF back to screen
             mqttc.publish(config.mqtt_base_topic + "/RX", str(serLine), qos=0, retain=False)
             
-            # Tuerkontakt
+            # digital input P2
             if serLine.startswith('P2='):
                 newState = None
                 if serLine == "P2=L":
@@ -129,11 +131,13 @@ try:
                 elif serLine == "P2=H":
                     newState = "ON"
                     
-                if newState is not None and lastState_tk != newState:
-                    lastState_tk = newState
-                    mqttc.publish(config.mqtt_topic_tuerkontakt, newState, qos=0, retain=False)
+                if newState is not None and (lastState_P2 != newState or not config.P2_MQTT_SendOnlyIfValueChanged):
+                    lastState_P2 = newState
+                    mqttc.publish(config.P2_MQTT_Topic, newState, qos=0, retain=config.P2_MQTT_SendRetained)
+                    if config.P2_MQTT_SendLastUpdate:
+                        mqttc.publish(config.P2_MQTT_Topic + "_lastUpdate", datetime.now().isoformat(), qos=0, retain=config.P2_MQTT_SendRetained)
                     
-            # PIR #1
+            # digital input P3
             if serLine.startswith('P3='):
                 newState = None
                 if serLine == "P3=L":
@@ -141,11 +145,13 @@ try:
                 elif serLine == "P3=H":
                     newState = "ON"
                     
-                if newState is not None and lastState_pir1 != newState:
-                    lastState_pir1 = newState
-                    mqttc.publish(config.mqtt_topic_pir1, newState, qos=0, retain=False)
+                if newState is not None and (lastState_P3 != newState or not config.P3_MQTT_SendOnlyIfValueChanged):
+                    lastState_P3 = newState
+                    mqttc.publish(config.P3_MQTT_Topic, newState, qos=0, retain=config.P3_MQTT_SendRetained)
+                    if config.P3_MQTT_SendLastUpdate:
+                        mqttc.publish(config.P3_MQTT_Topic + "_lastUpdate", datetime.now().isoformat(), qos=0, retain=config.P3_MQTT_SendRetained)
             
-            # PIR #2
+            # digital input P4
             if serLine.startswith('P4='):
                 newState = None
                 if serLine == "P4=L":
@@ -153,9 +159,25 @@ try:
                 elif serLine == "P4=H":
                     newState = "ON"
                 
-                if newState is not None and lastState_pir2 != newState:
-                    lastState_pir2 = newState
-                    mqttc.publish(config.mqtt_topic_pir2, newState, qos=0, retain=False)
+                if newState is not None and (lastState_P4 != newState or not config.P4_MQTT_SendOnlyIfValueChanged):
+                    lastState_P4 = newState
+                    mqttc.publish(config.P4_MQTT_Topic, newState, qos=0, retain=config.P4_MQTT_SendRetained)
+                    if config.P4_MQTT_SendLastUpdate:
+                        mqttc.publish(config.P4_MQTT_Topic + "_lastUpdate", datetime.now().isoformat(), qos=0, retain=config.P4_MQTT_SendRetained)
+                        
+            # digital input P5
+            if serLine.startswith('P5='):
+                newState = None
+                if serLine == "P5=L":
+                    newState = "OFF"
+                elif serLine == "P5=H":
+                    newState = "ON"
+                
+                if newState is not None and (lastState_P5 != newState or not config.P5_MQTT_SendOnlyIfValueChanged):
+                    lastState_P5 = newState
+                    mqttc.publish(config.P5_MQTT_Topic, newState, qos=0, retain=config.P5_MQTT_SendRetained)
+                    if config.P5_MQTT_SendLastUpdate:
+                        mqttc.publish(config.P5_MQTT_Topic + "_lastUpdate", datetime.now().isoformat(), qos=0, retain=config.P5_MQTT_SendRetained)
                    
             # DHT TH sensor
             # {"T":26.60,"H":36}
@@ -164,10 +186,11 @@ try:
                 t = round(float(th["T"]), 1)
                 h = int(th["H"])
                 if t >= -20 and t <= 50:
-                    mqttc.publish(config.mqtt_topic_out_temp, str(t), qos=0, retain=False)
+                    mqttc.publish(config.DHT22_MQTT_Topic_Temp, str(t), qos=0, retain=config.DHT22_MQTT_SendRetained)
                 if h >= 0 and h <= 100:
-                    mqttc.publish(config.mqtt_topic_out_hum, str(h), qos=0, retain=False)
-                
+                    mqttc.publish(config.DHT22_MQTT_Topic_Hum, str(h), qos=0, retain=config.DHT22_MQTT_SendRetained)
+                if config.DHT22_MQTT_SendLastUpdate:
+                        mqttc.publish(config.DHT22_MQTT_Topic_Temp + "_lastUpdate", datetime.now().isoformat(), qos=0, retain=config.DHT22_MQTT_SendRetained)
                 
         # nothing came in this time...
         else: