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