Setting battery charge thresholds stops your laptop from sitting at 100% on AC power, which extends the battery lifespan. Here is how to keep those thresholds applied across reboots using a custom systemd unit.
Step 1: Create the Service File
Create the systemd unit file:
sudo nano /etc/systemd/system/battery-threshold.service
This opens a text editor. You should see a blank file.
Step 2: Paste the Service Configuration
Copy and paste this entire block into the editor. This configuration sets the start threshold to 70% and the stop threshold to 80%.
[Unit]
Description=Set battery charge thresholds
After=default.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo 70 > /sys/class/power_supply/BAT0/charge_control_start_threshold && echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
RemainAfterExit=yes
[Install]
WantedBy=default.target
Step 3: Save and Exit
Press Ctrl + O (the letter O), then press Enter to confirm the filename, then press Ctrl + X to exit nano. You should be back at your terminal prompt.
Step 4: Enable the Service
Run this command to enable it to start automatically on boot:
sudo systemctl enable battery-threshold.service
Step 5: Start the Service Now
Run this to activate the thresholds immediately (without rebooting):
sudo systemctl start battery-threshold.service
Step 6: Verify It's Running
Check that everything worked:
sudo systemctl status battery-threshold.service
You should see output saying it's active (exited) or enabled.
Also verify the thresholds are set by reading the system files:
cat /sys/class/power_supply/BAT0/charge_control_start_threshold
cat /sys/class/power_supply/BAT0/charge_control_end_threshold
Both should return your set values (70 and 80).
Your battery will now cap at 80% and start charging at 70% automatically every time you boot your laptop. You're all set.
If you ever need to modify the thresholds in the future, just edit the service file again with
sudo nano /etc/systemd/system/battery-threshold.service, make your changes, save, and run sudo systemctl restart battery-threshold.service.