96

Is it possible to get the battery status of Bluetooth headphones connected to Linux? Android shows it so I was wondering if it was possible.

Zanna
  • 72,312
gabs1bb3
  • 1,093

6 Answers6

91

I am not sure about the state under Ubuntu, but under Arch Linux you do not need to write your own scripts to get bluetooth battery information nowadays.

The bluez package has experimental support for querying bluetooth headset battery data. Simply enable experimental features by editing

/etc/bluetooth/main.conf

and adding the following line to the [General] section

Experimental = true

Then, you just need to restart the bluetooth service using

systemctl restart bluetooth

Reconnect to your device, and

bluetoothctl info

should now also show the battery status. e.g.

Device 28:11:A5:47:6C:6E (public)                                             
Name: Cloud Walker                                                    
Alias: Cloud Walker                                                   
Class: 0x00240418                                                            
Icon: audio-headphones                                                
Paired: yes                                                           
...                               
Battery Percentage: 0x3c (60)                                         

The solution using upower as given by danjjl should also work now.

And now the battery level percentage should show up in Gnome Power settings dialog as well.

Before: Before bluez Experimental option enabled, Cloud Walker bluetooth headset is not displayed in Devices section of Power settings

After: After bluez Experimental option enabled, Cloud Walker bluetooth headset is displayed in Devices section of Power settings

redseven
  • 842
  • 1
  • 8
  • 14
R. Hahnemann
  • 1,011
32

In ubuntu you can go simply to settings->power to see the battery status of system and connected devices.

enter image description here

Yes, I know it's a Microsoft Bluetooth mouse on a Linux System ... but hey, Microsoft is the new cool company now ;)

This is what: systemctl status bluetooth

enter image description here

This is what: bluetoothctl devices shows:

enter image description here

The JBL was disconnected and the Creative speaker is connected with power. So the resulting ones with batteries (Keychron and Mouse) show up in the settings->power dialog.

NOTE: If upower -d not show the device, It's power level may not display in settings .
// I had a mouse shown, but a headphone not.

yurenchen
  • 471
klaas
  • 439
25

I wrote a simple python script that does the job. It uses AT commands to communicate with the device via RFCOMM and prints the battery level if the device is supported.

https://github.com/TheWeirdDev/Bluetooth_Headset_Battery_Level

(You need Python 3.6.0 or newer to run the script)

It might not work with all bluetooth headsets but I've provided a couple of workarounds in the 'Issues' page that might help.

13

upower can be used from a terminal to list power devices, listening to device events and querying history and statistics.

If your device is listed by upower -e you can run upower --dump to retrieve the battery level of your device.

Here is a sample output:

$ upower --dump
...
Device: /org/freedesktop/UPower/devices/mouse_dev_C1_FC_26_13_A9_58
  native-path:          /org/bluez/hci0/dev_C1_FC_26_13_A9_58
  model:                MX Anywhere 2S
  serial:               C1:FC:26:13:A9:58
  power supply:         no
  updated:              Wed 31 Dec 1969 06:00:00 PM CST (1550719462 seconds ago)
  has history:          yes
  has statistics:       no
  mouse
    present:             yes
    rechargeable:        no
    state:               unknown
    warning-level:       none
    percentage:          50%
    icon-name:          'battery-missing-symbolic'
...

src reddit

danjjl
  • 6,573
3

I have developed a GUI application to get the battery level of a bluetooth headset. You can check it on: https://github.com/Coutj/Bluetooth_project.git

Coutj
  • 41
1

For Airpods devices download and run https://github.com/delphiki/AirStatus with:

git clone git@github.com:delphiki/AirStatus.git
cd AirStatus
pip3 install bleak
python3 main.py
morhook
  • 1,671