I am just wondering. KDE sends me a notification if there is 10% battery life left on my keyboard, which is wireless. But is there a way to get the whole battery status data?
-
Welcome to Unix Stackexchange! You can [take the tour](http://unix.stackexchange.com/tour) first and then learn [How to Ask a good question](http://unix.stackexchange.com/help/how-to-ask). That makes it easier for us to help you. – andcoz Aug 27 '18 at 13:34
-
1Which kind of wireless battery is it? Bluetooth? Does it use some proprietary dongle? – andcoz Aug 27 '18 at 13:35
3 Answers
Battery information is provided to desktop environments by UPower; this includes the battery information for some keyboards and mice. You can see what your computer knows about its batteries by running
upower --dump
For example, on my desktop with a wireless Logitech mouse, it shows (among other things)
Device: /org/freedesktop/UPower/devices/mouse_0003o046Do101Bx0006
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.2/0003:046D:C52B.0003/0003:046D:101B.0006
vendor: Logitech, Inc.
model: M705
serial: XXXXXXXX
power supply: no
updated: Mon 27 Aug 2018 15:41:36 CEST (106 seconds ago)
has history: yes
has statistics: no
mouse
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 25%
icon-name: 'battery-low-symbolic'
On my laptop, it shows the laptop batteries, and the battery status of connected battery-powered devices.
- 411,918
- 54
- 1,065
- 1,164
On KDE5 the "Battery and Brightness" systray widget also reports the battery level of connected devices (when it can):
(The M705 is my wireless mouse)
- 8,648
- 1
- 24
- 47
-
-
-
@xenod even stranger! There should only be one “Unifying Receiver” in the `lsusb` output (unless you have several obviously), and no M705 device shown there. – Stephen Kitt Aug 27 '18 at 15:28
You can use the upower command to extract and print the battery percentage of a mouse by combining it with other command-line tools like grep, awk. Here's a step-by-step breakdown of the process:
Run
upower --dumpto Get Power Device Information: Theupower --dumpcommand provides detailed information about power devices connected to your system.Filter Information for Mouse Device: Use
grepto narrow down the output to the specific device you're interested in. In this case, we're looking for the mouse device information. The-A 7flag tellsgrepto include 7 lines of context after the matching line for a more complete block of information.upower --dump | grep -A 7 "mouse"Extract Battery Percentage Information: Within the extracted block of information, we're interested in the line containing "percentage." This is where
grepcomes in again.upower --dump | grep -A 7 "mouse" | grep "percentage"Print the Battery Percentage: Finally, we'll use
awkto isolate the actual percentage value (the second field) from the line. Here,$2refers to the second field.upower --dump | grep -A 7 "mouse" | grep "percentage" | awk '{print $2}'
When you run this command in your terminal, it will output the battery percentage of the mouse. Remember that this approach assumes the output format of the upower command remains consistent.
Please note that the exact command might vary based on the output format and the specific device name. Adjust the grep and awk filters accordingly if you encounter any discrepancies in the output.
Remember to run these commands in a terminal on a Linux system where the upower command is available.
- 101
