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:   dht22-homie-adafruit.py
	modified:   dht22-homie.py
  • Loading branch information
alaub81 committed Sep 23, 2022
1 parent fa90492 commit 22824ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 11 additions & 2 deletions dht22-homie-adafruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
insecure = True
qos = 1
retain_message = True
# how often should be a publish to MQTT (in Seconds)
publishtime = 120
# Retry to connect to mqtt broker
mqttretry = 5
# how often should be a publish to MQTT (in Seconds)
publishtime = 120
# At which value humidity alarm will be fired (x in %)
humidityalarm = 70

# do the stuff
### Functions
Expand All @@ -45,6 +47,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")
# homie stae ready
publish("$state","ready")

Expand All @@ -54,6 +59,10 @@ def on_disconnect(client, userdata, rc):
def sensorpublish():
publish(nodes + "/temperature","{:.1f}".format(temperature))
publish(nodes + "/humidity","{:.1f}".format(humidity))
if humidity >= humidityalarm:
publish(nodes + "/humidityalarm", "true")
else:
publish(nodes + "/humidityalarm", "false")

# running the Script
#MQTT Connection
Expand Down
11 changes: 10 additions & 1 deletion dht22-homie.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mqttclientid = "clientid-dht22-homie"
clientid = "clientid-dht22"
clientname = "Clientname DHT22 Sensor"
nodes="dht22"
nodes = "dht22"
username = "mosquitto"
password = "password"
insecure = True
Expand All @@ -21,6 +21,8 @@
mqttretry = 5
# how often should be a publish to MQTT (in Seconds)
publishtime = 120
# At which value humidity alarm will be fired (x in %)
humidityalarm = 70

# do the stuff
### Functions
Expand All @@ -45,6 +47,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")
# homie stae ready
publish("$state","ready")

Expand All @@ -54,6 +59,10 @@ def on_disconnect(client, userdata, rc):
def sensorpublish():
publish(nodes + "/temperature","{:.1f}".format(temperature))
publish(nodes + "/humidity","{:.1f}".format(humidity))
if humidity >= humidityalarm:
publish(nodes + "/humidityalarm", "true")
else:
publish(nodes + "/humidityalarm", "false")

# running the Script
# Initial the dht device, with data pin connected to:
Expand Down

0 comments on commit 22824ae

Please sign in to comment.