From 0a2fffb0ed7c397ae4054ad86e56d0ba4e7eb86f Mon Sep 17 00:00:00 2001 From: robert Date: Sun, 24 Jan 2021 23:11:08 +0100 Subject: [PATCH] add datetime --- mqtt_publish_temp.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mqtt_publish_temp.py b/mqtt_publish_temp.py index d82a6da..c562b79 100644 --- a/mqtt_publish_temp.py +++ b/mqtt_publish_temp.py @@ -10,6 +10,12 @@ import Adafruit_DHT import paho.mqtt.publish as publish import paho.mqtt.client as paho +# DATETIME +now = datetime.now() +#print("now =", now) +#Output format: DD/MM/YYYY H:M:S +dt_string = now.strftime("%d/%m/%Y %H:%M:%S") + # MQTT credentials #mqtt_username = 'homeassistant' # MQTT client username #mqtt_password = '3355' # MQTT client password @@ -30,6 +36,7 @@ client = paho.Client(protocol=paho.MQTTv31) # * set a random string (max 23 cha # Command topic temperature_topic = 'weathersensors/' + client_id + '/temperature' humidity_topic = 'weathersensors/' + client_id + '/humidity' +time_topic = 'weathersensors/' + client_id + 'time' #client connection #client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials @@ -49,6 +56,7 @@ while True: # Publish our data client.publish(temperature_topic, temperature) client.publish(humidity_topic, humidity) + client.publish(time_topic, dt_string) time.sleep(30)