Changeset - a0e920df8f3f
[Not reviewed]
default
0 1 0
Dennis Fink - 5 years ago 2020-01-27 20:07:18
dennis.fink@c3l.lu
Handle humidity
1 file changed with 8 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mqtt2prometheus.py
Show inline comments
 
@@ -30,6 +30,7 @@ temperature = Gauge(
 
    "temperature_celsius", "The current temperature", labelnames=["location"]
 
)
 

	
 
humidity = Gauge("humidity_percent", "The current humidity", labelnames=["location"])
 

	
 
def on_connect(client, userdata, flags, rc):
 
    client.publish("availability/mqtt2prometheus", "online", 2, True)
 
@@ -39,6 +40,7 @@ def on_connect(client, userdata, flags, 
 
    client.message_callback_add("space/member_count", handle_member_count)
 
    client.message_callback_add("availability/#", handle_availability)
 
    client.message_callback_add("sensors/temperature/#", handle_temperature)
 
    client.message_callback_add("sensors/humidity/#", handle_humidity)
 

	
 
    client.subscribe("sensors/people_now_present")
 
    client.subscribe("space/status")
 
@@ -46,6 +48,7 @@ def on_connect(client, userdata, flags, 
 
    client.subscribe("availability/+")
 
    client.subscribe("availability/shutdown/+")
 
    client.subscribe("sensors/temperature/#")
 
    client.subscribe("sensors/humidity/#")
 

	
 

	
 
def handle_people_now_present(client, userdata, msg):
 
@@ -79,6 +82,11 @@ def handle_temperature(client, userdata,
 
    temperature.labels(location).set(float(msg.payload))
 

	
 

	
 
def handle_humidity(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    humidity.labels(location).set(float(msg.payload))
 

	
 
def main():
 

	
 
    client = mqtt.Client("mqtt2prometheus")
0 comments (0 inline, 0 general)