7

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?

valerius21
  • 183
  • 1
  • 1
  • 3
  • 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
  • 1
    Which kind of wireless battery is it? Bluetooth? Does it use some proprietary dongle? – andcoz Aug 27 '18 at 13:35

3 Answers3

11

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.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
2

On KDE5 the "Battery and Brightness" systray widget also reports the battery level of connected devices (when it can):

enter image description here

(The M705 is my wireless mouse)

xenoid
  • 8,648
  • 1
  • 24
  • 47
0

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:

  1. Run upower --dump to Get Power Device Information: The upower --dump command provides detailed information about power devices connected to your system.

  2. Filter Information for Mouse Device: Use grep to 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 7 flag tells grep to include 7 lines of context after the matching line for a more complete block of information.

    upower --dump | grep -A 7 "mouse"
    
  3. Extract Battery Percentage Information: Within the extracted block of information, we're interested in the line containing "percentage." This is where grep comes in again.

    upower --dump | grep -A 7 "mouse" | grep "percentage"
    
  4. Print the Battery Percentage: Finally, we'll use awk to isolate the actual percentage value (the second field) from the line. Here, $2 refers 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.