diff --git a/mqtt2prometheus.py b/mqtt2prometheus.py --- a/mqtt2prometheus.py +++ b/mqtt2prometheus.py @@ -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")