How to auto pause playback when bluetooth speaker turns off


I have JBL Charge 3 bluetooth speaker wich is paired with Pi 4B.
I made my speaker trusted device (via bluetoothctl utility) so now when I turn the speaker ON it pairs with Pi automatically. At this point I can use Web client (I prefer Iris) to play music on speaker.

Then if I simply turn the speaker off, the playback resets to the beginning and tries to start again infinitely until I click the pause button manually.

I wonder is it a way to pause playback automatically when my bluetooth speaker turns OFF (disconnects from Pi).

Thank in advance!

what kind of setup do you have mopidy installed on ?

I would think that you need some sort of script to react to the system event that the USB has disappeared which launches a pause command ( for example, haven’t tested it). You can use udev rules for that.

A quick search leads me to which might be a bit too complicated on the script side, but has the correct steps with “finding the identifier” etc.