Changeset - 55df66067104
[Not reviewed]
default
0 1 0
Dennis Fink - 5 years ago 2020-02-10 21:12:15
dennis.fink@c3l.lu
Handle energy consumption
1 file changed with 17 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mqtt2prometheus.py
Show inline comments
 
@@ -44,6 +44,13 @@ co2_emission = Gauge(
 
    "co2_emission_kilogramm", "The CO2 emission in kilogramm", labelnames=["location"]
 
)
 

	
 
energy_consumption = Gauge(
 
    "energy_consumption_kilowatthour",
 
    "The energy consumption in kilowatthour",
 
    labelnames=["location"],
 
)
 

	
 

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

	
 
@@ -56,6 +63,9 @@ def on_connect(client, userdata, flags, 
 
    client.message_callback_add("sensors/barometer/#", handle_barometer)
 
    client.message_callback_add("sensors/power_consumption/#", handle_power_consumption)
 
    client.message_callback_add("sensors/co2_emission/#", handle_co2_emission)
 
    client.message_callback_add(
 
        "sensors/energy_consumption/#", handle_energy_consumption
 
    )
 

	
 
    client.subscribe("sensors/people_now_present")
 
    client.subscribe("space/status")
 
@@ -67,6 +77,7 @@ def on_connect(client, userdata, flags, 
 
    client.subscribe("sensors/barometer/#")
 
    client.subscribe("sensors/power_consumption/#")
 
    client.subscribe("sensors/co2_emission/#")
 
    client.subscribe("sensors/energy_consumption/#")
 

	
 

	
 
def handle_people_now_present(client, userdata, msg):
 
@@ -124,6 +135,12 @@ def handle_co2_emission(client, userdata
 
    co2_emission.labels(location).set(float(msg.payload))
 

	
 

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

	
 

	
 
def main():
 

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