Skip to content

Commit

Permalink
Merge pull request auhlig#2 from mineyannik/master
Browse files Browse the repository at this point in the history
Added Power Consumption Meter
  • Loading branch information
auhlig authored Jul 15, 2020
2 parents 2d17891 + ec7581a commit b9b757f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
homematicip ~= 0.10.5
homematicip ~= 0.10.19
prometheus_client >= 0.5.0

0 comments on commit b9b757f

Please sign in to comment.