Changeset - bfe1467514b9
[Not reviewed]
default
0 1 0
Dennis Fink - 5 years ago 2020-01-27 20:07:28
dennis.fink@c3l.lu
Added barometer handling
1 file changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mqtt2prometheus.py
Show inline comments
 
@@ -32,6 +32,11 @@ temperature = Gauge(
 

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

	
 
barometer = Gauge(
 
    "barometer_hectopascal", "The current air pressure", labelnames=["location"]
 
)
 

	
 

	
 
def on_connect(client, userdata, flags, rc):
 
    client.publish("availability/mqtt2prometheus", "online", 2, True)
 

	
 
@@ -41,6 +46,7 @@ def on_connect(client, userdata, flags, 
 
    client.message_callback_add("availability/#", handle_availability)
 
    client.message_callback_add("sensors/temperature/#", handle_temperature)
 
    client.message_callback_add("sensors/humidity/#", handle_humidity)
 
    client.message_callback_add("sensors/barometer/#", handle_barometer)
 

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

	
 

	
 
def handle_people_now_present(client, userdata, msg):
 
@@ -87,6 +94,13 @@ def handle_humidity(client, userdata, ms
 
    location = "-".join(t[2:])
 
    humidity.labels(location).set(float(msg.payload))
 

	
 

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

	
 

	
 
def main():
 

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