Ok, I finally found how to automatically switch to the HFP audio profile, which will then also automatically set the headset microphone as input device.
There are multiple approaches around, but the only way to do this automatically when connecting the bluetooth headset seems to be to create a udev
rule which runs a script when the headset is connected. There is a very nice blog post that describes this in-depth which I used to achieve what I wanted and where most of the code below is originally from.
These are the essential steps:
Find out card name and profile using pactl list
.
The output contains two lines that you will need:
...
Card #20
Name: bluez_card.70_BF_92_C9_F5_D0
...
Profiles:
a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 40, available: yes)
handsfree_head_unit: Handsfree Head Unit (HFP) (sinks: 1, sources: 1, priority: 30, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
...
In this example, the card name is bluez_card.70_BF_92_C9_F5_D0
and the profile name is handsfree_head_unit
.
With that, create a script ~/.config/auto-pactl.sh
to switch the headset to the HFP profile:
#!/bin/bash
sleep 2 # wait for the headset to fully connect
sudo -u '#1000' XDG_RUNTIME_DIR=/run/user/1000 \
pactl set-card-profile bluez_card.70_BF_92_C9_F5_D0 handsfree_head_unit
logger "Switched Jabra headset to HFP profile"
Find out input name of headset using udevadm monitor
and then connecting the BT headset. The output should be something like:
...
UDEV [54588.946048] add /devices/virtual/input/input112 (input)
...
Find out subsytem, vendor, and product using udevadm info -ap /devices/virtual/input/input112
(replacing the device with whatever the previous command's output was)
With this information, create a udev rule to execute the above script and store it in /etc/udev/rules.d/52-jabra-headset.rules
, inserting the values for your card and your username in the appropriate places:
ACTION=="add", SUBSYSTEM=="input", ATTR{id/vendor}=="0067", ATTR{id/product}=="24a7", RUN+="/home/<myUsername>/.config/auto-pactl.sh"
That worked like a charm for me!