Show HN: Terminal dashboard that throttles my PC during peak electricity rates

2 months ago 2

WattWise CLI Energy Monitor CLI dashboard showing real-time and historical power draw readings from a Kasa smart plug

The Challenge: Performance vs. Power Costs

High-performance computing often means high electricity bills, especially in regions with time-of-use pricing. Finding the balance between computational power and energy efficiency becomes critical when running resource-intensive workloads.

Understanding Power Usage

I have been setting up a workstation for off-loading compute-intensive LLM workflows from my desktop. The build includes dual Epyc CPUs with plans to add 4 GPUs for up to 128GB VRAM to run multiple agents in parallel. A key constraint was ensuring the system could run comfortably on a standard household 120V outlet.

Since I already use smart plugs throughout my home, I added one to monitor the workstation’s power consumption. However, checking power statistics using the kasa phone app or Home Assistant dashboard proved cumbersome, especially when I already maintain a terminal window with monitoring tools like htop, nvtop, and nload in a 2×2 grid on my secondary display.

TP-link Kasa EP25 Smart Plug TP-link Kasa EP25 Smart Plug

Building a Terminal-Based Solution

After sketching a simple wireframe for what I wanted: a clean, terminal-based UI that would display power consumption data already being collected by my Home Assistant instance through the TP-Link integration. After getting the data access sorted, I spent some time with ‘Claude 3.7 Sonnet Thinking’ iterating on the CLI structure and features.

The result: WattWise, a lightweight CLI tool that pulls power usage data from smart plugs (either directly or through Home Assistant) and presents it in a clean, information-dense dashboard right in the terminal.

WattWise CLI Monitor WattWise Demo

Key Features

Monitoring Features

  • Real-time power monitoring with wattage and current display
  • Color-coded power values (green for low usage, yellow for medium, red for high)
  • Historical consumption charts directly in the terminal
  • While smart plug measurements aren’t lab-grade (typically ±1-3% accuracy), they’re more than sufficient for practical usage monitoring

Power Management Features

  • Automatic CPU/GPU throttling based on time-of-use electricity pricing
  • Configurable power thresholds and performance profiles
  • Simple configuration through an interactive setup process

Deployment Options

  • Direct installation from source code
  • Docker support for containerized deployment
  • Connection options for both direct Kasa smart plug access and Home Assistant integration

Dynamic Power Management

Since my utility provider uses Time of Use (ToU) pricing. Over the years, I’ve built various home automations to minimize electricity usage during peak hours. With my workstation potentially drawing up to 1400W at full load, it made sense to add automatic CPU and GPU throttling during expensive rate periods.

WattWise System Architecture Power Optimizer: System architecture

My testing showed that reducing CPU frequency from 3700MHz to 1500MHz saved approximately 225W under load on my specific setup, though results will vary by hardware. The power optimizer service dynamically adjusts clock speeds based on:

  1. System load (from os.getloadavg())
  2. Current power consumption (from the smart plug)
  3. Time of day (to account for ToU periods)

Time of Use Adaptation Chart Power Optimizer: ToU adaption chart

Adaptive Performance Control

Initially, I explored a full PID (Proportional-Integral-Derivative) controller, but a simpler PI (Proportional-Integral) approach proved more suitable for power management.

The PI controller focuses on two key aspects:

  • Proportional (P) term: Provides immediate, proportional response to current errors
  • Integral (I) term: Accumulates past errors to eliminate long-term steady-state deviations

By removing the Derivative term, we:

  • Simplify the control logic
  • Reduce computational overhead
  • Maintain smooth performance transitions
  • Avoid potential over-optimization from the derivative calculation

For systems with gradual state changes like power management, the derivative term often introduces unnecessary complexity without meaningful benefits.

The controller dynamically adapts system parameters by considering:

  • Current system utilization (CPU/GPU load)
  • Instantaneous power consumption
  • Time-of-use electricity rate periods

This approach ensures energy-efficient transitions without the complexity of a full PID implementation.

Power Optimizer Control Flow Power Optimizer: Control flow (with PID)

Implementation and Limitations

Terminal Interface

The dashboard design is simple with:

  • A large, easy-to-read current wattage display
  • Color-coded elements based on consumption thresholds
  • Real-time updates with configurable refresh intervals
  • Historical graph using Unicode block characters for compatibility across terminals

Data Sources

The tool supports two main data sources:

  1. Direct Kasa Connection: Communicates directly with TP-Link Kasa smart plugs
  2. Home Assistant Integration: Uses the existing HA setup with authentication tokens

The code is modular enough that adding support for other smart plug systems shouldn’t be too difficult.

Current Limitations

This is very much a personal project with some constraints:

  • Currently supports only one smart plug at a time
  • Works only with Kasa smart plugs that have energy monitoring capabilities (Ex: EP25)
  • Requires either direct network access to the plug or Home Assistant integration
  • Power management features require Linux systems with appropriate CPU/GPU frequency control capabilities

How TO Use

Basic setup:

git clone https://github.com/naveenkul/WattWise.git cd WattWise pip install -r requirements.txt pip install .

Basic usage:

# Quick power view (single reading) wattwise # Continuous monitoring with charts wattwise --watch

Future Improvements

  • Support for multiple plugs with aggregated power statistics
  • Additional smart plug brands/models compatibility
  • Enhanced visualization options and exports
  • Integration with other power management tools
  • Better predictive algorithms for consumption forecasting

Final Thoughts

WattWise started as a simple utility to solve my specific need: monitoring a power-hungry workstation from the terminal I already have open. The addition of automatic power management during peak ToU hours has already saved me from manually adjusting system performance throughout the day.

The dashboard part of the project is open-sourced under the MIT license. Documentation and installation instructions are available in the repository. Contributions and feedback are welcome!

Feel free to fork it and adapt it to your specific needs – I’d be curious to see what others build with it.

Read Entire Article