Toni McQueen
Project

BatteryPowerd

A Linux battery safety workflow built around a shell hibernate checker, a user systemd timer, and discharge graphing so hibernation lands early enough to avoid work loss without firing too soon.

GitHub Repository

What It Does

The live setup polls battery percentage and charging state, then triggers hibernation only when the machine is discharging and has entered a defined low-power window. The same project also includes a terminal status helper and graph tooling for tuning the timer interval from measured discharge data.

Why I Built It

Default low-battery behavior can be vague, late, or machine-dependent. This project was built to make the behavior observable and deliberate: measure the discharge rate, choose a realistic timer cadence, and hibernate before the machine falls off a cliff.

Workflow

How It Works

Live Components

  • `battery_hibernate.sh` checks `/sys/class/power_supply/BAT0/` and runs `systemctl hibernate -i` inside the critical battery window.
  • `battery-hibernate.timer` runs that check on a repeated cadence using user `systemd`.
  • `battery_status.sh` gives a simple terminal watcher for charge state.

Timer Tuning

  • Battery discharge is logged and graphed instead of guessed.
  • The graph shows how quickly charge falls near the danger zone.
  • The timer interval is then tightened or relaxed so hibernation is early enough to be safe but not wasteful.
Stack

Technical Notes

Design Goal

Why The Graph Matters

The critical design point is not just “hibernate on low battery.” It is choosing a polling interval that matches real discharge behavior. Too slow and the battery can die before hibernation completes. Too fast and the machine hibernates earlier than necessary. BatteryPowerd uses measured battery decline to set that interval on purpose.

Visuals

Discharge Examples

Battery Discharge Sample

Example graph generated from real discharge data to show how charge falls over time and where the critical hibernate window sits.

Battery discharge sample graph

Battery Drop Rate Per Minute

Rate-of-drop view used to judge whether the timer should be tighter or looser near the low-battery threshold.

Battery drop rate per minute graph