Disconnect Bluetooth before device goes to sleep

Hi
I'm spinning in circles
I want the Bluetooth connection to be disconnected before the device goes to sleep.
It would be great if someone could tell me how to solve the problem.

greetings Stefan