πŸš€ Automating Battery Charge Limits on Arch Linux (KDE Plasma)

πŸš€ Automating Battery Charge Limits on Arch Linux (KDE Plasma)

Table of Contents

If you use a laptop with Linux, you probably know that keeping your battery at 100% while plugged into AC power all day is a recipe for premature battery degradation. Most modern laptops support a “Battery Threshold” or “Conservation Mode,” usually capped at 80%.

However, sometimes the native KDE Plasma settings (powerdevil) simply refuse to apply these limits to the hardware. In this guide, we will bypass the GUI and use Systemd Units to force a charge limit of 80% every time you plug in your charger.


The Problem

In KDE Plasma, you might see a setting for “Charge Limit” in the Power Management menu. Under the hood, this writes to powerdevilrc. But if your kernel doesn’t communicate perfectly with Plasma, that setting remains a suggestion rather than a rule.

We want a robust, system-level solution that:

  1. Detects when the AC Adapter is plugged in.

  2. Immediately writes the 80% limit to the kernel’s sysfs interface.

  3. Operates with root privileges automatically.


Step 1: Discover Your Hardware Names

Linux maps hardware to files in /sys/class/power_supply/. These names vary by manufacturer (e.g., Lenovo, Dell, ASUS).

Run this command:

ls /sys/class/power_supply/

Take note of the results:

  • The AC Adapter: Usually named AC, ACAD, ADP1, or AC0.

  • The Battery: Usually named BAT0 or BAT1.

For this guide, we will assume your AC adapter is ACAD and your battery is BAT1. Replace these in the scripts below with your actual names.


Step 2: Create the Systemd Service

This service performs the actual work of writing the “80” value to the battery’s threshold file.

Create the file:

sudo nano /etc/systemd/system/battery-limit-ac.service

Paste the following:

[Unit]
Description=Set Battery Charge Limit to 80%% on AC Power
After=multi-user.target

[Service]
Type=oneshot
# Ensure the battery threshold file exists before running
ConditionPathExists=/sys/class/power_supply/BAT1/charge_control_end_threshold

# 1. Check if AC is actually online (1 = plugged in)
ExecStartPre=/bin/bash -c 'grep -q "1" /sys/class/power_supply/ACAD/online'

# 2. If plugged in, set the limit to 80
ExecStart=/bin/sh -c 'echo "80" > /sys/class/power_supply/BAT1/charge_control_end_threshold'

[Install]
WantedBy=multi-user.target

Step 3: Create the Systemd Path Unit

A “Service” runs once. A “Path Unit” monitors a file for changes. We want to monitor the online status of your AC adapter so the service triggers every time you plug it in.

Create the file:

sudo nano /etc/systemd/system/battery-limit-ac.path

Paste the following:


[Unit]
Description=Monitor AC Power Status to Trigger Battery Limit

[Path]
# Monitor the AC status file for changes (plugging/unplugging)
PathModified=/sys/class/power_supply/ACAD/online

[Install]
WantedBy=multi-user.target

Step 4: Enable and Test

Now, tell the system to start watching for those power events.

# Reload systemd to see the new files
sudo systemctl daemon-reload

# Enable the path unit (this stays active in the background)
sudo systemctl enable --now battery-limit-ac.path

# Manually start the service once to verify it works right now
sudo systemctl start battery-limit-ac.service

Verification

To confirm the limit is active, check the value directly from the kernel:

cat /sys/class/power_supply/BAT1/charge_control_end_threshold

If it returns 80, you are successful!


Troubleshooting

  • Permission Denied: If you try to run the echo command manually as a user, it will fail. This is why we use Systemdβ€”it executes the command as root.

  • File Not Found: If charge_control_end_threshold doesn’t exist, your laptop may use a different name like charge_stop_threshold. Check ls /sys/class/power_supply/BAT1/ to see available files.

  • AC Name: If the service fails with “No such file” for the AC adapter, double-check Step 1. Your charger might be named AC0 or ADP1 instead of ACAD.


Conclusion

By using a Systemd Path unit instead of a standard KDE script, we’ve created a “set and forget” solution. Your battery will now stop charging at 80% every time you plug it in, significantly extending its lifespan.

Tags :
Share :
comments powered by Disqus

Related Posts

KeePassXC

KeePassXC

KeePassXC: The Ultimate Open-Source Key to Digital Security In an age where every online service demands a unique, complex password, managing your digital life can feel like safeguarding a thousand different keys. Thankfully, solutions like KeePassXC offer a robust, secure, and user-centric approach to credential management, putting you back in complete control of your data.

Read More
AppFlowy: The Open-Source, Privacy-Focused Notion Alternative πŸš€

AppFlowy: The Open-Source, Privacy-Focused Notion Alternative πŸš€

AppFlowy is a free and open-source AI collaborative workspace designed as a privacy-first alternative to proprietary productivity tools like Notion. It brings together projects, wikis, tasks, and team collaboration into a unified, customizable environment, giving users complete control over their data.

Read More
Haruna

Haruna

Haruna: The Minimalist Powerhouse Video Player Built for the Modern Desktop In the crowded landscape of media players, finding one that strikes the perfect balance between powerful performance, customizability, and a clean, modern interface can be a challenge. Enter Haruna, an elegant, open-source video player built with the robust libmpv library and backed by the expertise of the KDE community. Haruna is designed for users who want a distraction-free viewing experience without sacrificing advanced control.

Read More