Page 1 of 1

Automatic BT device active

Posted: Thu Nov 27, 2025 7:37 pm
by k.s.deviate
I have this issue where after pairing, connecting, and trusting a bluetooth device I still have to exit to desktop after every boot and manually select the device. After selecting the device, I get the checkmark before the name. If I dont do this I dont get audio.

I have used a script and service file to automate this process to the best of my ability (grok helped) however they arent doing what is expected. No errors after creating and testing the service file.

I would also like the audio to default from 100 to 0 after boot - I havent attempted this yet.

/usr/local/bin/bt-audio-setup.sh

Code: Select all

#!/bin/bash

# Bluetooth device MAC address
DEVICE_MAC="E9:A7:26:03:1E:82"
DEVICE_MAC_UNDERSCORE="${DEVICE_MAC//:/_}"
CARD_NAME="bluez_card.${DEVICE_MAC_UNDERSCORE}"
SINK_NAME="bluez_sink.${DEVICE_MAC_UNDERSCORE}.a2dp_sink"

echo "[$(date)] Starting Bluetooth audio setup for ${DEVICE_MAC}"

# Wait for PipeWire/WirePlumber to be fully active (user services)
for i in {1..40}; do
    if systemctl --user is-active --quiet pipewire pipewire-pulse wireplumber; then
        echo "PipeWire and WirePlumber are active"
        break
    fi
    sleep 1
done

if ! systemctl --user is-active --quiet pipewire; then
    echo "ERROR: PipeWire failed to start"
    exit 1
fi

# Wait for the Bluetooth device to be connected
for i in {1..20}; do
    if bluetoothctl info "${DEVICE_MAC}" 2>/dev/null | grep -q "Connected: yes"; then
        echo "Device ${DEVICE_MAC} is connected"
        break
    fi
    sleep 3
done

if ! bluetoothctl info "${DEVICE_MAC}" | grep -q "Connected: yes"; then
    echo "ERROR: Device ${DEVICE_MAC} not connected after timeout"
    exit 1
fi

# Set A2DP profile
pactl set-card-profile "${CARD_NAME}" a2dp_sink
sleep 2

# Set as default sink
if pactl list sinks short | grep -q "${SINK_NAME}"; then
    pactl set-default-sink "${SINK_NAME}"
    echo "SUCCESS: ${SINK_NAME} is now the default audio output"
else
    echo "ERROR: A2DP sink not available (wrong profile or device issue)"
    exit 1
fi
~/.config/systemd/user/bt-audio-setup.service

Code: Select all

[Unit]
Description=Setup Bluetooth Audio Output After PipeWire
After=pipewire.service pipewire-pulse.service wireplumber.service graphical-session.target
Requires=pipewire.service pipewire-pulse.service wireplumber.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/bt-audio-setup.sh
RemainAfterExit=true
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=default.target
~/.config/systemd/user/bt-audio-setup.timer

Code: Select all

[Unit]
Description=Timer for Bluetooth Audio Setup
Requires=bt-audio-setup.service

[Timer]
OnBootSec=30sec
Persistent=true

[Install]
WantedBy=timers.target
Edit: I absolutely love this, I migrated from openauto pro and although I'm still getting used to it, it is so much smoother and much more intuitive. Thank you

Re: Automatic BT device active

Posted: Thu Nov 27, 2025 8:34 pm
by hudiy
Hello,
Could you please grab the audio graph (in qpwgraph) both before and after you select the device? It looks like PipeWire is sending audio to a different device before you switch to the desired one.

Is DSP audio5.0 V1 some kind of Bluetooth audio receiver (over A2DP)?

Re: Automatic BT device active

Posted: Thu Nov 27, 2025 8:47 pm
by k.s.deviate
Yes, it is a dsp that has Bluetooth input and/or 4 channel analogue input. Bluetooth is over A2DP yes

Edit: changed the picture so everything is included.

Re: Automatic BT device active

Posted: Fri Nov 28, 2025 1:17 am
by hudiy
If you do not have microphone connected, could you please apply changes to hudiy_startup.sh mentioned in this thread viewtopic.php?p=785#p785? Just to make sure echo-cancel does not interfere with the bluez card.

Re: Automatic BT device active

Posted: Fri Nov 28, 2025 7:08 am
by k.s.deviate
Thank you, no I do not have a microphone. I made the changes and the connections seem to be working as expected. No more having to select the output device.

However, now the rotary controller does not adjust the volume at all, in desktop nor Hudiy.

Re: Automatic BT device active

Posted: Fri Nov 28, 2025 9:09 am
by hudiy
Does it work when you replace amixer (default) for XF86_AudioLowerVolume, XF86_AudioRaiseVolume, XF86_AudioMute to pactl?

For replacing amixer to pactl, edit $HOME/.config/labwc/rc.xml file and add

Code: Select all

	<keyboard>
		<keybind key="XF86_AudioLowerVolume">
			<action name="Execute" command="pactl set-sink-volume @DEFAULT_SINK@ -5%" />
		</keybind>
		<keybind key="XF86_AudioRaiseVolume">
			<action name="Execute" command="pactl set-sink-volume @DEFAULT_SINK@ +5%" />
		</keybind>
		<keybind key="XF86_AudioMute">
			<action name="Execute" command="pactl set-sink-mute @DEFAULT_SINK@ toggle " />
		</keybind>
	</keyboard>
between <openbox_config ...></openbox_config>

like:

Code: Select all

<?xml version="1.0"?>
<openbox_config xmlns="http://openbox.org/3.4/rc">
	<touch deviceName="10-0038 generic ft5x06 (79)" mapToOutput="DSI-1" mouseEmulation="no" />
	<keyboard>
		<keybind key="XF86_AudioLowerVolume">
			<action name="Execute" command="pactl set-sink-volume @DEFAULT_SINK@ -5%" />
		</keybind>
		<keybind key="XF86_AudioRaiseVolume">
			<action name="Execute" command="pactl set-sink-volume @DEFAULT_SINK@ +5%" />
		</keybind>
		<keybind key="XF86_AudioMute">
			<action name="Execute" command="pactl set-sink-mute @DEFAULT_SINK@ toggle " />
		</keybind>
	</keyboard>
</openbox_config>
You can also use your device sink name instead of @DEFAULT_SINK@.

Re: Automatic BT device active

Posted: Fri Jan 16, 2026 11:15 pm
by k.s.deviate
Does @DEFAULT_SINK@ get replaced with @sink name@ or just sink name without the @?

Re: Automatic BT device active

Posted: Fri Jan 16, 2026 11:39 pm
by hudiy
It is described in the pactl docs https://manpages.debian.org/stable/puls ... l#COMMANDS. @DEFAULT_SINK@ is special syntax and will be replaced by the name of default sink (e. g. hudiy_equalizer_sink). You can also put exact name of the sink instead of @DEFAULT_SINK@.