I wrote an applet for KDE Plasma 5 which shows the battery percentage based on the /sys
interface (which gets updated instantly and hasn't the delay of UPower daemon or the Battery and Brightness plasmoid).
/sys
is in fact an interface for accessing the kernel data structures at runtime.It resides completely on memory and is a useful source of debugging information.The information that we need here is the exact battery percentage:
$ tree /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:01/PNP0C09:00/PNP0C0A:00/power_supply/BAT0/
.
├── alarm
├── capacity
├── capacity_level
├── cycle_count
├── device -> ../../../PNP0C0A:00
├── energy_full
├── energy_full_design
├── energy_now
├── hwmon1
│ ├── device -> ../../BAT0
│ ├── in0_input
│ ├── name
│ ├── power
│ │ ├── async
│ │ ├── autosuspend_delay_ms
│ │ ├── control
│ │ ├── runtime_active_kids
│ │ ├── runtime_active_time
│ │ ├── runtime_enabled
│ │ ├── runtime_status
│ │ ├── runtime_suspended_time
│ │ └── runtime_usage
│ ├── subsystem -> ../../../../../../../../../../class/hwmon
│ ├── temp1_label
│ ├── temp2_label
│ └── uevent
├── manufacturer
├── model_name
├── power
│ ├── async
│ ├── autosuspend_delay_ms
│ ├── control
│ ├── runtime_active_kids
│ ├── runtime_active_time
│ ├── runtime_enabled
│ ├── runtime_status
│ ├── runtime_suspended_time
│ └── runtime_usage
├── power_now
├── present
├── serial_number
├── status
├── subsystem -> ../../../../../../../../../class/power_supply
├── technology
├── type
├── uevent
├── voltage_min_design
└── voltage_now
For example the number that we're looking for resides under this file(in my system):
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:01/PNP0C09:00/PNP0C0A:00/power_supply/BAT0/capacity
It shows the correct percentage of the battery (BAT0):

The responsibility of this plasmoid is to read that number regularly every three seconds.
Here's the project repository: https://gitlab.com/P.Mousavi/batperc-indicator
And if you wanted to compile and run it, follow the instructions below:
Install the dependencies(explained in README.md) and run:
git clone https://gitlab.com/P.Mousavi/batperc-indicator.git
cd batperc-indicator
mkdir build
cd build
qmake ../plugin/
make
sudo make install
If all goes without any error then you should be able to see the plasmoid Battery percentage indicator in the widgets side-bar in KDE Plasma and you can drag-n-drop it from there.
There are a lot of TODOs like changing the color when the percentage goes below a threshold etc.But for now I'm busy :)
Hope it helps.
sudo acpi -V
return when you "plug in at 10%"?