{"id":1661,"date":"2022-01-08T23:20:59","date_gmt":"2022-01-08T17:50:59","guid":{"rendered":"https:\/\/smarttech101.com\/?p=1661"},"modified":"2023-09-10T08:48:18","modified_gmt":"2023-09-10T03:18:18","slug":"how-to-set-battery-charging-threshold-limit-the-charging-in-thinkpad-and-other-laptops-in-linux-unix","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/how-to-set-battery-charging-threshold-limit-the-charging-in-thinkpad-and-other-laptops-in-linux-unix\/","title":{"rendered":"How to Set Battery Charging Threshold (Limit the Charging) In Thinkpad and Other Laptops in Linux\/Unix"},"content":{"rendered":"\n
These instructions are primarily based on Thinkpad laptops. However, many users have notified that Asus and other manufacturers’ laptops are starting to support the threshold using almost the same methods. I have mentioned these variations and suggestions as well.<\/p>\n\n\n\n
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.<\/p>\n\n\n\n
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.<\/p>\n\n\n\n
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.<\/p>\n\n\n\n
You can use any file manager such as Nautilus or Dolphin to find a special directory \/sys\/class\/power_supply\/BAT0\/<\/strong> or \/sys\/class\/power_supply\/BAT1\/<\/strong> or \/sys\/class\/power_supply\/BATT\/<\/strong> or \/sys\/class\/power_supply\/BATC\/<\/strong> or something like that.<\/p>\n\n\n\n Or, you can use the following ls <\/strong>commands (or something like that):<\/p>\n\n\n\n A sample Output on my Thinkpad: <\/p>\n\n\n\n Now, check if there are threshold-like words in the above output. If you can find any file like that, your laptop should support setting the threshold, and hence, you can move on to the next step.<\/p>\n\n\n\n \ud83d\udcd4Note<\/strong>: I could not find any such files on the gaming laptop Lenovo Legion 5 in Linux. However, as an ad-hoc arrangement, I was able to set the battery charging threshold using the Lenovo Vantage app preinstalled on the Windows partition. Just enable the conservation mode. These settings are applied in both the Windows and Linux partitions.<\/p>\n\n\n\n Now, you need to write desired thresholds in the two files found above. For ThinkPad laptops, they are \/sys\/class\/power_supply\/BAT0\/charge_control_start_threshold<\/strong> and \/sys\/class\/power_supply\/BAT0\/charge_control_end_threshold<\/strong>. <\/p>\n\n\n\n Lenovo’s Recommendations for these two thresholds:<\/a><\/strong><\/p>\n\n\n\n For other manufacturers, if you cannot find any value on their websites or other places, try these values and see if they work. Please comment below if these values work for your manufacturers.<\/p>\n\n\n\n To write these thresholds, first, get the root privileges using su:<\/strong><\/p>\n\n\n\n Now, you can use any text editor like nano<\/strong> or vim<\/strong>. Or use the following commands directly:<\/p>\n\n\n\n Replace the SART_THRESHOLD, END_THRESHOLD, START_THRESHOLD_FILE, and END_THRESHOLD_FILE with the appropriate files. For example,<\/strong> for ThinkPad laptops:<\/p>\n\n\n\n And you are done. But, these files’ contents are reverted back to the default state on the next reboot and hence you need to make these changes permanent.<\/p>\n\n\n\n To make the changes permanent, your computer needs to write these two limits at every system reboot.<\/p>\n\n\n\n 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<\/strong> using nano or your favorite text editor:<\/p>\n\n\n\n And now, fill the file with the following contents:<\/p>\n\n\n\n Here, you need to replace the YOUR_THRESHOLD_COMMAND<\/strong> in the ExecStart<\/strong> line with the echo command mentioned above. For example<\/strong>, for ThinkPad laptops, this whole line would become<\/p>\n\n\n\n~$ ls --recursive \/sys\/class\/power_supply\/BAT*<\/code><\/pre>\n\n\n\n
Step 2: Set the Battery Charging Threshold.<\/h2>\n\n\n\n
\n
~$ sudo su<\/code><\/pre>\n\n\n\n
# echo START_THRESHOLD > START_THRESHOLD_FILE; echo END_THRESHOLD > END_THRESHOLD_FILE<\/code><\/pre>\n\n\n\n
# echo 85 > \/sys\/class\/power_supply\/BAT0\/charge_control_start_threshold; echo 90 > \/sys\/class\/power_supply\/BAT0\/charge_control_end_threshold<\/code><\/pre>\n\n\n\n
Step 3: Make the Changes Made Under the Previous Step Permanent.<\/h2>\n\n\n\n
~$ sudo nano \/etc\/systemd\/system\/battery-charge-threshold.service<\/code><\/pre>\n\n\n\n
[Unit]\nDescription=Set the battery charge threshold\nAfter=multi-user.target\nStartLimitBurst=0\n\n[Service]\nType=oneshot\nRestart=on-failure\nExecStart=\/bin\/bash -c 'YOUR_THRESHOLD_COMMAND'\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n
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'<\/code><\/pre>\n\n\n\n