From 2651fa5464221f2dbbef9be9724bf5f6f949dd3a Mon Sep 17 00:00:00 2001 From: yannikhenke Date: Wed, 15 Jul 2020 21:26:35 +0200 Subject: [PATCH 1/2] updated homematicip requirement --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9d9304e..b03d104 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -homematicip ~= 0.10.5 +homematicip ~= 0.10.19 prometheus_client >= 0.5.0 From ec7581a693839a675f4d9ec0888d4790bb777ff1 Mon Sep 17 00:00:00 2001 From: yannikhenke Date: Wed, 15 Jul 2020 21:39:57 +0200 Subject: [PATCH 2/2] added power consumption meter --- exporter.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/exporter.py b/exporter.py index 1317507..91452f9 100755 --- a/exporter.py +++ b/exporter.py @@ -5,8 +5,9 @@ import homematicip import prometheus_client from homematicip.home import Home, EventType -from homematicip.device import WallMountedThermostatPro, TemperatureHumiditySensorWithoutDisplay,\ - TemperatureHumiditySensorOutdoor, TemperatureHumiditySensorDisplay, ShutterContact, HeatingThermostat +from homematicip.device import WallMountedThermostatPro, TemperatureHumiditySensorWithoutDisplay, \ + TemperatureHumiditySensorOutdoor, TemperatureHumiditySensorDisplay, ShutterContact, HeatingThermostat, \ + PlugableSwitchMeasuring logging.basicConfig(level=logging.INFO, format='%(asctime)-15s %(message)s', datefmt="%Y-%m-%d %H:%M:%S") @@ -130,6 +131,12 @@ def __init_metrics(self): labelnames=labelnames+detail_labelnames, namespace=namespace ) + self.metric_power_consumption = prometheus_client.Gauge( + name='power_consumption', + documentation='Power consumption', + labelnames=labelnames, + namespace=namespace + ) self.metric_device_event = prometheus_client.Counter( name='device_event', documentation='events triggered by a device', @@ -207,6 +214,18 @@ def __collect_device_info_metrics(self,room, device): device_label=device.label ).set(device.lastStatusUpdate.timestamp()) + def __collect_power_metrics(self, room, device): + logging.info( + "found device: room: {}, label: {}, device_type: {}, firmware_version: {}, last_status_update: {}, permanently_reachable: {}" + .format(room, device.label, device.deviceType.lower(), device.firmwareVersion, device.lastStatusUpdate, + device.permanentlyReachable) + ) + # general device info metric + logging.info(device.currentPowerConsumption) + self.metric_power_consumption.labels( + room=room, + device_label=device.label + ).set(device.currentPowerConsumption) def __collect_event_metrics(self, eventList): for event in eventList: @@ -247,6 +266,9 @@ def collect(self): elif isinstance(d, HeatingThermostat): logging.info("Device of type heating") self.__collect_heating_metrics(g.label, d) + elif isinstance(d, PlugableSwitchMeasuring): + logging.info("Device of type PlugableSwitchMeasuring") + self.__collect_power_metrics(g.label, d) except Exception as e: logging.warning(