I've been having problems with my Track Pad 2 and the Keyboard losing their connection to the iMac. (Never had this problem with the wired variety...
They just worked! What a concept!)
I soon discovered that the problem is not unusual. I've also connected and unpaired the keyboard with my Apple TV which should be well outside the normal 30 foot range with the three walls also involved, just to be sure...
OSX Daily had a somewhat hidden method of resetting the
Bluetooth Hardware Module. The article dates from Dec 2015, but it still seems to work, at least for the resetting part.
Here are the steps. Be advised that you will temporarily lose control of your Mac if all you have are Bluetooth mice/keyboards. Assuming the Reset works, you should regain control when the OS again 'sees' your Bluetooth devices. I'd suggest you have wired backups for the mouse/keyboard before attempting this Reset... just to keep Murphy away from your Mac.
Open the System Prefs->Bluetooth window so you can see what is happening and what is connected. While you have that Pref open, make sure you have "Show Bluetooth in menu bar" enabled. And, obviously, have Bluetooth turned ON...
When you are ready to Reset your Bluetooth Hardware Module:
- shift-option click the Bluetooth icon in the Menu Bar, noting that there is now a "Debug" item
- Select the Debug item and look for the item
- If you don't see your devices connecting, a reboot may be needed (use the manual power button method if you don't have a wired mouse)
I did not need a re-boot when I used this method.
Another site mentioned using the Bluetooth Setup Assistant (HD/System/Library/Core Services/). Unfortunately, at least in
macOS 10.13 High Sierra, that app is basically not set up for user use. It seems to date from 2017 and may be reduced to System Only activities.