Skip to content

Instantly share code, notes, and snippets.

@i3130002
Last active March 9, 2025 16:23
Show Gist options
  • Save i3130002/39f9f24c8b44849f96211d5a3fd4a8c8 to your computer and use it in GitHub Desktop.
Save i3130002/39f9f24c8b44849f96211d5a3fd4a8c8 to your computer and use it in GitHub Desktop.
Linux Battery Charge Limiter Service

Linux Battery Charge Limiter Service

I have a project to control the battery but at the end of the day I needed something that just works. As I'm using auto-cpufreq I removed the TLP and therefore needed this battery limiter. Help planet and your pocket by preserving your laptop battery life.

Create the service

Create systemd service file (/etc/systemd/system/battery-threshold.service) to run as root:

sudo nano /etc/systemd/system/battery-threshold.service

Content:

[Unit]
Description=Set Battery Charge Limit
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo 53 > /sys/class/power_supply/BAT1/charge_control_end_threshold'
User=root

[Install]
WantedBy=multi-user.target

๐Ÿ”„ Reload and Enable the Service

sudo systemctl daemon-reload
sudo systemctl enable battery-threshold.service
sudo systemctl start battery-threshold.service

(I knew what I wanted and gpt did the rest.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment