19

BT is enabled at startup. This is nice. But it will not autopair/connect to a device, even if it is once paired and get status "trusted". I can connect to a Speaker with the tool by selecting device, and "connect to audio output". How can this done automatically on boot? I can do this also with "bluetoothctl" and than "connect ", but this is interactive, seems not scriptable.

And second step is, that BT becomes default audio sink.
Isn't that all an ordinary use case?

(I found some pages here, most are outdated.) Autoconnecting Bluetooth Devices: load-module module-switch-on-connect doesn't work for me.

I also installed bt-autoconnect. But several issues: - it didn't foun the BT-Adapter - Button Audio-Setting does just nothing - Save and quit doesn't just nothing

Arno
  • 485
  • Agreed this would be very nice. This discussion looks relevant. I'm testing the solution for pulseaudio>1.0. Looking at your answer, I guess you've already seen it... – Gabriel Nov 16 '17 at 08:39
  • Related: https://askubuntu.com/questions/1170809/how-do-i-get-a-bluetooth-speaker-to-auto-connect-at-login – AlikElzin-kilaka May 19 '20 at 17:25

7 Answers7

5

Try bluetoothctl command.

If you then enter help, you'll see the commands to be used.

  • 'list' (devices)
  • 'trust 78:44:aa:bb:cc:dd' (MAC address of device)
  • 'info 78:44:aa:bb:cc:dd' (MAC address of device)
  • 'paired-devices'

Try, it worked for me.

Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
Gabor
  • 95
5

For automatic connect to Audio Sink you can add the following line in /etc/rc.local:

(sleep 6; echo "connect AA:BB:CC:DD:EE:FF\nquit" | bluetoothctl) &

Update the address. You can verify from command line by:

echo -e "devices\nquit" | bluetoothctl

In my case sleep 6 is enough - but maybe on your computer it has to be increased to allow other bluetooth connection steps to be fully completed.

Generally with & sign at the end you will start process which will be executed in 6sec not blocking next processes starting normal bluetooth connection functions. If the rc.local is not existing (it was in my case) you can create it or to initiate at startup with other file.

Eliah Kagan
  • 117,780
Janusz
  • 59
  • 1
  • 2
2

For the second part (auto switch to BT speaker as a sink) I found a solution. Has been already posted here:

# /etc/pulse/default.pa
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
load-module module-switch-on-connect # this is new!
.endif

BUT: How can the BT server automatically pair with the speaker, as soon as it is available? HELP!


Edit: found a (not the best imho) solution for the first question:

echo "connect AA:BB:CC:DD:EE:FF" | bluetoothctl

BUT: Even better would be that this works without this MAC for all ever devices that has been connected and trusted.

Zanna
  • 70,465
Arno
  • 485
1

I wrote a simple script that will keep reconnecting the device when you reboot your PC or when the device toggles bluetooth status or lose a signal for a while.

#!/bin/bash

MAC="E0:CC:F8:E8:87:5D"

powered() { echo "show" | bluetoothctl | grep "Powered" | cut -d " " -f 2 }

connected() { echo "info ${MAC}" | bluetoothctl | grep "Connected" | cut -d " " -f 2 }

while true do sleep 1 if [ $(powered) = yes ] && [ $(connected) = no ]; then echo "connect ${MAC}" | bluetoothctl sleep 5 fi done

  1. Update MAC variable with your device's MAC address. (speaker, smartphone...)
    echo "devices" | bluetoothctl | grep Device
  2. Save the script for example as a ~/.bt-autoconnect.sh
  3. Make it executable chmod +x ~/.bt-autoconnect.sh
  4. Run it at login echo "~/.bt-autoconnect.sh &" >> "~/.xprofile"
BlueManCZ
  • 543
0

In Ubuntu sound-problems are due to installed drivers. If this speaker is the newest and most trendiest hardware, you have no good chances and would have to wait 2 to 8 months until driver is present at Linux Community. But you could try to install following packages in terminal :

sudo apt-get install amarok rhythmbox

reboot

Then switch on bluetooth and see if your speaker is supported :

  • Open the Activities overview and start typing Bluetooth.
  • Click on Bluetooth to open the panel.
  • Set the switch at the top to ON.

Good luck or be patient for at maximum 8 months.

dschinn1001
  • 3,829
  • 2
    His Q was nothing to do with drivers or sound "problems". It was to do with configuring auto-connect. Suggesting waiting for an arbitrary few months hardly the stuff of Stack Exchange. – RichieHH Oct 18 '19 at 16:19
0

In my case this Script works (I tried all setting but not work for me,Step 5 from Here)

Python script on GitHub called bluetooth-autoconnect. It’s a python script that automatically connects to all paired and trusted Bluetooth devices. However, the script is not available to install directly on Flatpak or Apt repository. Hence, we need to manually download and configure the service.

download the zip file from GitHub or use the following command to clone the repository to your home directory.

git clone https://github.com/jrouleau/bluetooth-autoconnect.git

Now that we have the repository downloaded we need to move the service and scripts to their respective location before we start the service. In systemd architecture:-

sudo cp bluetooth-autoconnect/bluetooth-autoconnect.service /etc/systemd/system/

sudo cp bluetooth-autoconnect/bluetooth-autoconnect /usr/bin/

Once, we have successfully copied the service to the respective directories, let’s enable and start the service. To do that, use the following command.

sudo systemctl enable bluetooth-autoconnect.service 
sudo systemctl start bluetooth-autoconnect.service

Now remove and reconnect and Done.

The only caveat with this method is that you won’t be able to pair your Bluetooth device with other systems without switching off your Linux machine’s Bluetooth.

0

For me it was a mouse, I needed to add it as a trusted device using the following command:

bluetoothctl trust device_mac_address

But first I needed the device mac address, after I manually connected the device by going to settings > bluetooth then clicking on the Bluetooth device, that should show the mac address

Waqleh
  • 871