Frequent charging and discharging loops lead to degradation in the battery. Therefore, to promote the battery’s lifespan, you need to reduce this loop. And if your work environment involves sitting at a table all the time, your laptop should stay connected to the electric outlet all the time.
But, that will put your laptop always at 100% charged level which is another cause of battery degradation. Hence, many manufacturers (like Lenovo, and Asus) ask you to set charging limit/threshold. Unfortunately, these manufacturers provide their tools only for Windows and not for Linux. Hence, through this article, I would like to assist you in how to set the battery charging threshold on Linux. Just follow these steps and you are done. Step 1: Check if Your Laptop Supports Setting the Battery Charging Threshold.
You can use any file manager such as Nautilus or Dolphin to find a special directory /sys/class/power_supply/BAT0/ or /sys/class/power_supply/BAT1/ or /sys/class/power_supply/BATT/ or /sys/class/power_supply/BATC/ or something like that. Or, you can use the following ls commands (or something like that) :
ls --recursive /sys/class/power_supply/BAT* Step 2: Set the Battery Charging Threshold.
Now, you need to write desired thresholds in the two files found above. For ThinkPad laptops, they /sys/class/power_supply/BAT0/charge_control_start_threshold and /sys/class/power_supply/BAT0/charge_control_end_threshold.
To write these thresholds, first, get the root privileges using su: echo START_THRESHOLD > START_THRESHOLD_FILE; echo END_THRESHOLD > END_THRESHOLD_FILE
Replace the SART_THRESHOLD, END_THRESHOLD, START_THRESHOLD_FILE, and END_THRESHOLD_FILE with the appropriate files. For example, for ThinkPad laptops :
echo 85 > /sys/class/power_supply/BAT0/charge_control_start_threshold; echo 90 > /sys/class/power_supply/BAT0/charge_control_end_threshold Step 3: Make the Changes Made Under the Previous Step Permanent.
For this purpose, you will need to create a systemd-service. To create this service, create a file /etc/systemd/system/battery-charge-threshold.service using nano or your favorite text editor :
sudo nano /etc/systemd/system/battery-charge-threshold.service
And now, fill the file with the following contents :
[Unit] Description=Set the battery charge threshold After=multi-user.target StartLimitBurst=0 [Service] Type=oneshot Restart=on-failure ExecStart=/bin/bash -c 'YOUR_THRESHOLD_COMMAND' [Install] WantedBy=multi-user.target
Here, you need to replace the YOUR_THRESHOLD_COMMAND in the ExecStart line with the echo command mentioned above. For example, for ThinkPad laptops, this whole line would become :
ExecStart=/bin/bash -c 'echo 85 > /sys/class/power_supply/BAT0/charge_control_start_threshold; echo 90 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
Now, save the file and enable the above systemd service using the following systemctl command :
sudo systemctl enable battery-charge-threshold.service
On the other hand, systemd can keep banging on until the directory is created. The Restart=on-failure line in the file /etc/systemd/system/battery-charge-threshold.service makes sure this. That’s all about setting your battery charging thresholds. Thank you for staying till this point. If there is any recommendation or I have committed any mistakes, point them out in the comment section below.
And please mention your variations, if any, for your non-ThinkPad laptops. It will help the Linux community.
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
ArchivesCategories
All
|