I have Bluetooth speakers which I would like to automatically connect to when I log in to my desktop computer. What is a reliable way to accomplish this on Fedora Workstation 33 please?
I can manually connect to the speakers using GNOME's bluetooth settings GUI or execute
bluetoothctl connect C8:84:47:XX:XX:XX in terminal (with my true MAC address, redacted here). The bluetooth speakers are AC powered and have power-saving features disabled - they are always on and ready to connect.
A systemd user service seems to be one option, however I can't get this method to work yet. Here's what I have tried so far.
I have a file ~/.config/systemd/user/bluetooth-soundbar.service with the following contents:
[Unit] Description=Connect to soundbar at login [Service] Type=oneshot ExecStart=bluetoothctl connect C8:84:47:XX:XX:XX [Install] WantedBy=default.target
I enabled and started the new service with
systemctl --user enable bluetooth-soundbar.service && systemctl --user start bluetooth-soundbar.service
I tried adding BindsTo=bluetooth.service and/or After=bluetooth.target to the [Unit] section as recommended in the documentation, however these do not appear to have any effect. I also tried with ExecStart=/bin/sh -c "bluetoothctl connect C8:84:47:XX:XX:XX" (instead of using the command by itself).
/etc/bluetooth/main.conf has AutoEnable=true by default, and
systemctl status bluetooth shows bluetooth running automatically and by default after login.
The Arch wiki mentions adding "load-module module-switch-on-connect" to /etc/pulse/default.pa, however when I tried this I had no sound or sound settings after rebooting so reverted to the default file.
What am I missing please? Can this be accomplished, and is systemd the correct tool for something like this?