2 Commits f31cda65af ... eed4e2370a

Author SHA1 Message Date
  FloKra eed4e2370a 2023-08-29 8 months ago
  FloKra cfeb09fc3a 2023-08-29 8 months ago
3 changed files with 80 additions and 57 deletions
  1. 16 13
      CHANGELOG.txt
  2. 49 44
      ioext/config.py
  3. 15 0
      ioext/ioext.py

+ 16 - 13
CHANGELOG.txt

@@ -1,16 +1,19 @@
-03.07.2023
-	- revert last changes
-	- change structure of config
-	- add option to send retained MQTT messages for each device
-	- add option to send only if value changed for each device
-	- add option to send last change timestamp on a 2nd topic for each device
+2023-08-29
+ - added 4th input
+ - changed default baudrate to 115200
+ 
+2023-07-03
+ - revert last changes
+ - change structure of config
+ - add option to send retained MQTT messages for each device
+ - add option to send only if value changed for each device
+ - add option to send last change timestamp on a 2nd topic for each device
 	
-03.07.2023
-	- added config option 'filterUnchanged' so that filtering on state change can be disabled now (pin state is sent by the MCU every minute by default - now this will be published every time on MQTT if filterUnchanged = False)
+2023-07-03
+ - added config option 'filterUnchanged' so that filtering on state change can be disabled now (pin state is sent by the MCU every minute by default - now this will be published every time on MQTT if filterUnchanged = False)
 	
-30.05.2023
-	separate config in python daemon
+2023-05-30
+ - separate config in python daemon
 
-14.03.2023
-	initial checkin
-	
+2023-03-14
+ - initial checkin

+ 49 - 44
ioext/config.py

@@ -1,44 +1,49 @@
-# timeout in s to end script when nothing is received (will be restarted by systemd then)
-# must be higher than getStatusInterval 
-quitOnNoReceiveTimeout = 75
-
-# status file - on ramdrive (/tmp on RasPi by default)
-# is "touched" every time a serial message comes in so that working communication can be monitored easily
-#statusFile = '/tmp/ioext_running'
-#statusFile = '/run/user/1000/ioext_running'
-statusFile = ''
-
-# serial port config
-serialPort = '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'
-serialBaud = 57600
-serialTimeout = 1 # should be 1 as above interval/timeout relies on it
-
-# 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
-
-DHT22_MQTT_Topic_Temp = "T5/Abstr/Sensors/temp"
-DHT22_MQTT_Topic_Hum = "T5/Abstr/Sensors/hum"
-DHT22_MQTT_SendRetained = False
-DHT22_MQTT_SendLastUpdate = False
-
-# MQTT config
-mqtt_server = "mqtt.lan"
-mqtt_port = 1883
-mqtt_user = "xxxxx"
-mqtt_password = "xxxxx"
-
-mqtt_base_topic = "T5/HomeSvrIOExt"
-
+# timeout in s to end script when nothing is received (will be restarted by systemd then)
+# must be higher than getStatusInterval 
+quitOnNoReceiveTimeout = 75
+
+# status file - on ramdrive (/tmp on RasPi by default)
+# is "touched" every time a serial message comes in so that working communication can be monitored easily
+#statusFile = '/tmp/ioext_running'
+#statusFile = '/run/user/1000/ioext_running'
+statusFile = ''
+
+# serial port config
+serialPort = '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'
+serialBaud = 115200
+serialTimeout = 1 # should be 1 as above interval/timeout relies on it
+
+# MQTT config
+mqtt_server = "mqtt.lan"
+mqtt_port = 1883
+mqtt_user = ""
+mqtt_password = ""
+mqtt_base_topic = "T5/HomeSvrIOExt"
+
+# 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
+
+

+ 15 - 0
ioext/ioext.py

@@ -24,6 +24,7 @@ quiet = True
 lastState_P2 = None
 lastState_P3 = None
 lastState_P4 = None
+lastState_P5 = None
 # --- END GLOBAL VARS ---
 
 
@@ -163,6 +164,20 @@ try:
                     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}