Getting the Battery Status of a Bluetooth Device on Linux

Today while gaming - on Windows - I was alerted that my bluetooth mouse was low on battery. I realised that I didn't have any way of keeping on top of top of it on (Arch) Linux.

It's possible using the dbus-send interface to ask for the battery percentage, following this StackOverflow answer:

mac="DA:DE:0B:1C:2B:0A"
mac="${mac//:/_}"
dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_${mac} org.freedesktop.DBus.Properties.Get string:"org.bluez.Battery1" string:"Percentage"

Unfortunately, this doesn't work out of the box as we receive the following error:

Error org.freedesktop.DBus.Error.UnknownObject: Method "Get" with signature "ss" on interface "org.freedesktop.DBus.Properties" doesn't exist

As noted on the Arch Wiki, we need to enable the experimental mode by tweaking the bluetooth.service configuration to:

-ExecStart=/usr/lib/bluetooth/bluetoothd
+ExecStart=/usr/lib/bluetooth/bluetoothd -E

After a systemctl daemon-reload && systemctl restart bluetooth, we can now correctly get the status of the battery, showing it's at 90%:

   variant       byte 90

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #command-line #bluetooth #linux.

This post was filed under articles.

Related Posts

Other posts you may be interested in:

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.