add availability topic

This commit is contained in:
Administrator 2021-10-19 14:36:45 +00:00
parent a1413281d6
commit e154723fbe
3 changed files with 7 additions and 2 deletions

View File

@ -31,6 +31,7 @@ client = paho.Client(protocol=paho.MQTTv31) # * set a random string (max 23 cha
temperature_topic = 'weathersensors/' + client_id + '/temperature'
humidity_topic = 'weathersensors/' + client_id + '/humidity'
time_topic = 'weathersensors/' + client_id + '/time'
availability_topic = 'weathersensors/' + client_id + '/availability'
#client connection
#client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
@ -45,6 +46,7 @@ dt_string = now.strftime("%d-%m-%Y %H:%M:%S")
print(dt_string)
# Get Temperature from DHT
_, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
print("temperature before round: " +str(temperature))
temperature = round(float(temperature),2)
@ -58,4 +60,5 @@ print("humidity after round: " + str(humidity))
# Publish our data
client.publish(temperature_topic, temperature)
client.publish(humidity_topic, humidity)
client.publish(time_topic, dt_string)
client.publish(time_topic, dt_string)
client.publish(availability_topic, "ON")

View File

@ -56,3 +56,4 @@ for line in container.split('\n'):
client.publish(topic + "/battery", "" + battery)
client.publish(topic + "/temperature", "" + temperature)
client.publish(topic + "/humidity", "" + humidity)
client.publish(topic + "/availability", "ON")

View File

@ -63,6 +63,7 @@ def write_wallmountedthermostatpro(room,device):
client.publish(topic + "/actualTemperature", "" + str(actualTemperature))
client.publish(topic + "/setPointTemperature", "" + str(setPointTemperature))
client.publish(topic + "/humidity", "" + str(humidity))
client.publish(topic + "/availability", "ON")
print({"Room":room, "Device Name":device.label, "Last Status Update" : device.lastStatusUpdate, "Actual Temperature":device.actualTemperature, "Set Point Temperature":device.setPointTemperature,"Humidity":device.humidity})
@ -82,4 +83,4 @@ def main():
write_wallmountedthermostatpro(group.label,device)
if __name__ == "__main__":
main()
main()