Anonymous Anonymous - 2 months ago
473 0

TP-Link HS110 power monitoring with InfluxDB and Grafana

Python

HS110 Python

#!/usr/bin/env python3
from pyHS100 import SmartPlug
from influxdb import InfluxDBClient
from time import sleep
import datetime

plug = SmartPlug("192.168.1.51")
client = InfluxDBClient(database="homelab")
now = datetime.datetime.now()
theMonth = now.month

while True:
        power = plug.get_emeter_realtime()['power']
        monthly_power = plug.get_emeter_monthly()[theMonth]

        client.write_points([{
                "measurement": "power",

                "fields": {
                        "month": theMonth,
                        "current_power": power,
                        "monthly_power": monthly_power
                }
        }])
        sleep(15)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download