Skip to content

Commit

Permalink
added humidity alarm
Browse files Browse the repository at this point in the history
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
	modified:   bme280-homie.py
  • Loading branch information
alaub81 committed Sep 23, 2022
1 parent 1042793 commit a174c8c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions bme280-homie.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# Retry to connect to mqtt broker
mqttretry = 5
# how often should be a publish to MQTT (in Seconds)
publishtime=15
publishtime = 120
# At which value humidity alarm will be fired (x in %)
humidityalarm = 70

# do the stuff
### Functions
Expand All @@ -35,7 +37,7 @@ def on_connect(client, userdata, flags, rc):
publish("$nodes",nodes)
# homie node config
publish(nodes + "/$name","BME280 Sensor")
publish(nodes + "/$properties","temperature,humidity,pressure")
publish(nodes + "/$properties","temperature,humidity,humidityalarm,pressure")
publish(nodes + "/temperature/$name","Temperature")
publish(nodes + "/temperature/$unit","°C")
publish(nodes + "/temperature/$datatype","float")
Expand All @@ -44,6 +46,9 @@ def on_connect(client, userdata, flags, rc):
publish(nodes + "/humidity/$unit","%")
publish(nodes + "/humidity/$datatype","float")
publish(nodes + "/humidity/$settable","false")
publish(nodes + "/humidityalarm/$name", "Humidity Alarm")
publish(nodes + "/humidityalarm/$datatype", "boolean")
publish(nodes + "/humidityalarm/$settable", "false")
publish(nodes + "/pressure/$name","Pressure")
publish(nodes + "/pressure/$unit","hPa")
publish(nodes + "/pressure/$datatype","float")
Expand Down Expand Up @@ -92,9 +97,14 @@ def on_disconnect(client, userdata, rc):
# finaly the loop
while True:
try:
humidity = bme280.humidity
publish(nodes + "/temperature","{:.2f}".format(bme280.temperature))
publish(nodes + "/humidity","{:.2f}".format(bme280.humidity))
publish(nodes + "/humidity","{:.2f}".format(humidity))
publish(nodes + "/pressure","{:.2f}".format(bme280.pressure))
if humidity >= humidityalarm:
publish(nodes + "/humidityalarm", "true")
else:
publish(nodes + "/humidityalarm", "false")
time.sleep(publishtime)

except KeyboardInterrupt:
Expand Down

0 comments on commit a174c8c

Please sign in to comment.