Stop/start battery charging through software?
Solution 1:
On Thinkpad devices, you can control the start and stop of the battery charging in Ubuntu. Run these commands in your terminal to install tp-smapi
:
sudo apt-get install tp-smapi-dkms
sudo modprobe tp_smapi
Then write your desired charging thresholds (your own values) to the virtual files in /sys/devices/platform/smapi
:
echo 10 | sudo tee /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 100 | sudo tee /sys/devices/platform/smapi/BAT0/stop_charge_thresh
In the above commands you can change the values 10 and 100 to any value. The first one will help you to choose at what level charging must start and the second value will let you choose at what level charging must stop.
Solution 2:
You can't disable charging using any known software interface from user space. As it is, the battery controls from /sys/class/power_supply/BAT0
are static and dynamic readings as returned from the ACPI _BIF, _BIX and _BST controls, these are read only.
There are no ACPI controls that allow you to disable battery charging and on all the common x86 mobile platforms I've ever worked on the battery controls are not exposed. Normally this data comes from a battery gas gauge and are read using bit-banging i2c usually by an embedded controller. So you realistically have very little chance of reverse engineering this and most won't allow battery charging disabling.
Solution 3:
I could set my threshold to 60% by setting /sys/class/power_supply/BAT0/charge_control_end_threshold
to 60
as su. Ubuntu shows charging icon, but won't charge past 60%. The battery charging indicator LED also turned white, indicating that charging has stopped, much like it's behavior on Windows when Asus' "Battery Lifespan Mode" is activated. Also, the file resets to 100 on every boot, you might want to add a rule to set it to 60 on boot.
Source. I didn't have enough reputation to comment this, so I answered it with my own experience. Do note that most of the people that used this method had Asus laptops and Asus has a similar functionality on Windows by default. I highly doubt if that should make a difference, but one user with an Ideapad said they couldn't find the file. ThinkPad owners should try using TLP's setting for battery threshold.
EDIT: Heads up, this seems to be a very dirty method, has rendered my machine unbootable in certain situations. And this took me a lot of tries to figure it out because it seemed to be working at certain times and unbootable after sleep.
EDIT 2: Seems like this solution is actually documented well on Arch Wiki. In fact, they've provided workarounds for the issue I quoted in my edit, Please refer to the section Persist after hibernation where it provides workarounds for the black screen after sleep issue.