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:
- Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/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:
-r, --rate SECONDS Update rate in seconds (default: 60)
-l, --logging Enable logging
-f, --file PATH Log file location
-a, --no-adjust Monitor only mode (no BCLM adjustments)
-v, --target-voltage VALUE Set target voltage (default: 3.92V)
-d, --deadband VALUE Set voltage deadband (default: 0.02V)
-h, --help Show this help messageMonitor battery with custom voltage target:
./maintain_optimal_voltage.sh --target-voltage 3.85Enable logging with 30-second updates:
./maintain_optimal_voltage.sh --logging --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
- Test thoroughly on your MacBook model
- Submit a pull request with detailed description
- The script requires
battery_functions.shwith core sensor reading functions - Filter algorithms are designed to be modular and switchable
- BCLM adjustment logic prioritizes battery safety over aggressive optimization
[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