Check battery level of connected bluetooth device on linux
This might be a bit late to the party but for me this Python project has worked fine:
https://github.com/TheWeirdDev/Bluetooth_Headset_Battery_Level
I only had to change the port in line 57 to 3 for my no-name X5 headset. If it hangs or errors with "connection refused" try a different port.
The Python program uses AT commands via RFCOMM and should work while Pulseaudio is using the A2DP sink (mine reconnects). Python 3 is needed as 2 doesn't have BT-Serial sockets. Windows will probably not work as it lacks bluez. It basically does the same thing as the Pulseaudio hack here: https://stackoverflow.com/a/56390625/920122
If you want to look at the commands as they are exchanged, try my debug fork: https://github.com/clst/Bluetooth_Headset_Battery_Level
Read battery status bluetooth headset linux
Since this pull request by Dmitry Sharshakov, PipeWire has support for reporting battery status (with devices that use Apple HFP AT commands). It uses bluez's Battery Provider API, which is still experimental and is only available if bluetoothd
is started with the -E
flag.
On Arch Linux, it should be enough to run
cp /usr/lib/systemd/system/bluetooth.service /etc/systemd/system/
sed -i -r 's/ExecStart=.+/& -E/' /etc/systemd/system/bluetooth.service
systemctl daemon-reload
systemctl restart bluetooth
And the headset battery level should appear. To get the battery level programatically, you can then use UPower's DBus API.
Related Topics
Passing Main Script Variables into Perl Modules
How to Clear All History in Linux/Ubuntu Terminal or Bash Permanently
How to Know Which of the /Dev/Input/Eventx (X=0..7) Have the Linux Input Stream
Shell Script to Count Files, Then Remove Oldest Files
Does Linux Kill Background Processes If We Close the Terminal from Which It Has Started
How to Give a Linux User Sudo Access
How to Fix Symbol Lookup Error: Undefined Symbol Errors in a Cluster Environment
Linux Makefile Structure and Documentation
Why Do I Get 'Permission Denied' After Using ./File2 in Linux
Diff to Output Only the File Names
Suppress Echo of Command Invocation in Makefile
How to Create a Script to Save and Restore Permissions
Linux: Merging Multiple Files, Each on a New Line
How to Delete a User in Linux When the System Says Its Currently Used in a Process
How to Register Fuse Filesystem Type with Mount(8) and Fstab