|
@@ -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,9 @@ verbose = False
|
|
|
debug = False
|
|
|
quiet = True
|
|
|
|
|
|
-lastState_tk = None
|
|
|
-lastState_pir1 = None
|
|
|
-lastState_pir2 = None
|
|
|
+lastState_P2 = None
|
|
|
+lastState_P3 = None
|
|
|
+lastState_P4 = None
|
|
|
# --- END GLOBAL VARS ---
|
|
|
|
|
|
|
|
@@ -121,7 +122,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 +130,13 @@ try:
|
|
|
elif serLine == "P2=H":
|
|
|
newState = "ON"
|
|
|
|
|
|
- if newState is not None and (lastState_tk != newState or not filterUnchanged):
|
|
|
- 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 +144,13 @@ try:
|
|
|
elif serLine == "P3=H":
|
|
|
newState = "ON"
|
|
|
|
|
|
- if newState is not None and (lastState_pir1 != newState or not filterUnchanged):
|
|
|
- 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 +158,11 @@ try:
|
|
|
elif serLine == "P4=H":
|
|
|
newState = "ON"
|
|
|
|
|
|
- if newState is not None and (lastState_pir2 != newState or not filterUnchanged):
|
|
|
- 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)
|
|
|
|
|
|
# DHT TH sensor
|
|
|
# {"T":26.60,"H":36}
|
|
@@ -164,10 +171,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:
|