I’ve been deep into collecting and displaying metrics in my new job, and I decided to do some metrics collection about some of my smart devices and the computers in our network.

Windows Machines

My wife and I both game on Windows PCs, so I used Windows_Exporter to collect metrics:

Windows Exporter Dashboard in Grafana

I have the application running at boot so I get these metrics whenever my computer turns on. It’s pretty useful from the default dashboard I grabbed from Grafana.

Homebridge

Homebridge Dashboard in Grafana
'''
    Homebridge Data Sync
    Eric Turner
    30 Jun 2022

    Pulls accessories from Homebridge, Loads into InfluxDB for Grafana
'''
import requests
import json
from influxdb_client import InfluxDBClient, Point, WriteOptions

root_url = "http://*:8581/api"

def login():
    key = requests.post(root_url + '/auth/login', json = {"username": "*", "password": "*"}).text
    key = json.loads(key)
    return key["access_token"]

def accessories(key):
    data = requests.get(root_url + '/accessories', headers = {"Authorization": "Bearer " + key}).text
    #print(data)
    data = json.loads(data)
    if 'statusCode' in data :
        if data['statusCode']== 401:
            key = login()
            accessories(key)
    else:
        return data

def send_data(data_point, name, value, capture_time):
    with InfluxDBClient(url="http://localhost:8086", org="home") as _client:
         with _client.write_api(write_options=WriteOptions(batch_size=500,
                                                      flush_interval=10_000,
                                                      jitter_interval=2_000,
                                                      retry_interval=5_000,
                                                      max_retries=5,
                                                      max_retry_delay=30_000,
                                                      exponential_base=2)) as _write_client:
            _write_client.write(bucket="home",record=Point(data_point).field(name, value).time(capture_time))


def parse(data):
    # varibles
    ring_status = {0:"Home", 1: "Away", 3: "Disarmed"}
    ring_uuid = "0000007E-0000-1000-8000-0026BB765291"

    nest_status = {0: "Off", 1:"Heating", 2: "Cooling", 3:"Auto"}
    nest_uuid = "0000004A-0000-1000-8000-0026BB765291"
    nest_eco_uuid = "00000049-0000-1000-8000-0026BB765291"
    
    for accessory in data:
        if accessory['uuid'] == ring_uuid:
            ring_current_status = accessory['values']['SecuritySystemCurrentState']
        elif accessory['uuid'] == nest_uuid:
            # convert celsius to fahrenheit
            if accessory['values']['TemperatureDisplayUnits'] == 1:
                nest_current_temp = 9.0/5.0*(accessory['values']['CurrentTemperature']) + 32
                nest_target_temp = 9.0/5.0*(accessory['values']['TargetTemperature']) + 32
            else:
                nest_current_temp = accessory['values']['CurrentTemperature']
                nest_target_temp = accessory['values']['TargetTemperature']
            nest_humidity = accessory['values']['CurrentRelativeHumidity']
            nest_current_status = accessory['values']['CurrentHeatingCoolingState']
        elif accessory['uuid'] == nest_eco_uuid and accessory['serviceName'] == 'Eco Mode':
            nest_eco_mode = accessory['values']['On']

    print("Ring Status: {}".format(ring_status[ring_current_status]))
    print("Nest Status: {}".format(nest_status[nest_current_status]))
    print("Nest Current Temp: {}".format(nest_current_temp))
    print("Nest Target Temp: {}".format(nest_target_temp))
    print("Nest Eco Mode: {}".format(nest_eco_mode))

    from datetime import datetime
    current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
    print(current_time)

    send_data("ring", "status", ring_current_status, current_time)
    send_data("nest", "status", nest_current_status, current_time)
    send_data("nest", "current_temp", nest_current_temp, current_time)
    send_data("nest", "target_temp", nest_target_temp, current_time)
    send_data("nest", "eco_mode", nest_eco_mode, current_time)

    #with open('data.json', 'w') as f:
        #json.dump(data, f, indent=4)

parse(accessories(login()))

I wrote some custom python code to communicate with the Homebridge server and grab some metrics about my Nest Thermostat and my Ring security system. May look into grabbing more info later.

Linux Server

Linux Server with Node Exporter

After my wife and I upgraded our machines, I had enough leftover parts to slap together another server. The CPU and MOBO are from 2014 though and I remember the CPU had overheating issues at the time, which is why I upgraded. This dashboard is to help monitor the system.

This system is also the one running Prometheus, Grafana and the custom python code to communicate with Homebridge (on a 1min crontab job).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.