# HG changeset patch # User Dennis Fink # Date 2020-01-27 20:07:28 # Node ID bfe1467514b9917ee543455f627f34a1f0fe92dd # Parent a0e920df8f3f7ed3b1f327ecc7a3ec27d5028f55 Added barometer handling diff --git a/mqtt2prometheus.py b/mqtt2prometheus.py --- a/mqtt2prometheus.py +++ b/mqtt2prometheus.py @@ -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")