I can get Bluetooth info from the shell with
ioreg
I can get the Bluetooth info for my Apple Mouse from the shell with
ioreg -n BNBMouseDevice
and for my older Apple Keyboard (~2012) with
ioreg -n IOAppleBluetoothHIDDriver
Then we can build a macro around that, like this:
Mouse & Keyboard Battery Charge Level Warning.kmmacros (5.2 KB)
The macro triggers every 3 minutes. It will give you a notification when the level falls below a configurable threshold. The notification will show you the threshold and the current battery levels of mouse and keyboard:
You can set the threshold in the green action.
As said: This works specifically for my Apple Mouse and for my Apple Keyboard from 2012. ATM I’m still trying to make it work for my newer 2016 Keyboard.
So, try it and let me know if it works with your devices.
Source: Mac Bluetooth Keyboard/Mouse Battery Level in Terminal
Update (2018-06-06 10:39 UTC)
I have finally found the key that works with my Magic Keyboard from 2016. It is
AppleDeviceManagementHIDEventService
So, if my macro doesn’t show the battery for your keyboard then replace “IOAppleBluetoothHIDDriver” in the keyboard shell script action with that key.