Skip to content

Instantly share code, notes, and snippets.

@mharsch
Created September 21, 2023 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mharsch/c10ae09039ae0ce60017e496eb802305 to your computer and use it in GitHub Desktop.
Save mharsch/c10ae09039ae0ce60017e496eb802305 to your computer and use it in GitHub Desktop.
use kasa smart plug with prometheus / grafana

Uses this container to scrape power data from the reverse-engineered kasa API running on the smart plugs (e.g. HS100).

Docker compose example

compose.yml

version: '3.8'

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_storage:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    ports:
      - 9090:9090
  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    restart: unless-stopped
    ports:
      - 3000:3000
    volumes:
      - grafana_storage:/var/lib/grafana
  kasa-exporter:
    image: fffonion/tplink-plug-exporter:latest
    container_name: kasa-exporter
    restart: unless-stopped
    ports:
      - 9233:9233
volumes:
    prometheus_storage:
    grafana_storage:

prometheus.yml

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "prometheus"
    scrape_interval: 15s
    static_configs:
    - targets: ["localhost:9090"]
  - job_name: 'kasa'
    static_configs:
    - targets:
      # IP of your smart plugs
      - 192.168.1.166
    metrics_path: /scrape
    relabel_configs:
      - source_labels : [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        # IP of the exporter
        replacement: kasa-exporter:9233

# scrape kasa_exporter itself
  - job_name: 'kasa_exporter'
    static_configs:
      - targets:
        # IP of the exporter
        - kasa-exporter:9233

Import grafana dashboard id: 10957 for power dashboard of your smart plug(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment