Kodi - Autostart Bluetooth stopped working

DietPi version | 10.6.2
Distro version | trixie
Kernel version | Linux Family 6.12.101+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.101-1 (2026-08-05) x86_64 GNU/Linux
Architecture | amd64
SBC model | Native PC (x86_64)

I’m currently running Dietpi and have Kodi on Autostart and Bluetooth ON
To connect to my BT headphones I put a small script into /var/lib/dietpi/postboot.d/bt-headphoness.sh

sleep 10
echo "connect 88:C9:E8:91:B8:68" |bluetoothctl

Everything worked perfectly for a couple of weeks, even this morning, however when attempting to reconnect later today, the bluetooth connection in Kodi sound devices has disappeared. I rebooted several times but it won’t return.
On reboot I get an audio message through the headphones saying “Bluetooth Connected”, but then nothing
I then ran;

bluetoothctl connect 88:C9:E8:91:B8:68
Attempting to connect to 88:C9:E8:91:B8:68
Connection successful

speaker-test -D bluealsa
speaker-test 1.2.14
Playback device is bluealsa
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
\[2894\] D: bluealsa-pcm.c:1538: Getting BlueALSA PCM: PLAYBACK 00:00:00:00:00:00 a2dp
\[2894\] D: bluealsa-pcm.c:1296: /org/bluealsa/hci0/dev_88_C9_E8_91_B8_68/a2dpsrc/sink: Setting constraints
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 960 to 206158430
Period size range from 480 to 524288
Periods = 4
\[2894\] D: bluealsa-pcm.c:566: /org/bluealsa/hci0/dev_88_C9_E8_91_B8_68/a2dpsrc/sink: Initializing HW
\[2894\] D: bluealsa-pcm.c:612: /org/bluealsa/hci0/dev_88_C9_E8_91_B8_68/a2dpsrc/sink: Couldn't open PCM: Device or resource busy
Unable to set hw params for playback: Device or resource busy
Setting of hwparams failed: Device or resource busy
\[2894\] D: bluealsa-pcm.c:475: /org/bluealsa/hci0/dev_88_C9_E8_91_B8_68/a2dpsrc/sink: Closing

Extract fom Kodi Log

info : Loading skin file: /root/.kodi/addons/script.bluetooth.man/resources/skins/Default/1080i/discover.xml, load type: LOAD_ON_GUI_INIT
info : CAddonMgr::FindAddons: script.bluetooth.delay v1.2.0 installed
info : CAddonMgr::FindAddons: script.bluetooth.man v1.0.6 installed
info : CAddonMgr::FindAddons: service.bluetooth-audio v12.2.0.1 installed
info : CAESinkALSA - Unable to open device "bluealsa" for playback

Can you please help?

Some process is already using bluealsa.

Can you check

fuser -v /dev/snd/*
bluealsa-aplay -l

Thanks
I’ll give it a try in the morning.

dietpi@Family:~$ fuser -v /dev/snd/*
dietpi@Family:~$ aplay -l
aplay: device_list:279: no soundcards found...
dietpi@Family:~$

I then went into dietpi-config and the soundcard displays as intel-sst-dsp

Ok
I think I’ve worked it out.
When booting you must connect at time of boot, if not, the Bluetooth audio device will not appear in Kodi. If I turn off the headphones I can still reconnect at anytime.
I don’t suppose there is anyway of changing this because I have Kodi on Autostart.

This means your Bluetooth sound card does not appear in aplay -l, so it cannot appear in dietpi-config. intel-sst-dsp is not your Bluetooth sound card, but would install firmware for specific Intel chips.

I am no expert with BlueALSA, but did you try the command suggested by Jappe instead?

bluealsa-aplay -l

… let me check the last info I collected about this … does this produce noise through the Bluetooth speakers?

speaker-test -D bluealsa

If so:

echo -e 'pcm.!default bluealsa\nctl.!default bluealsa' | sudo tee /etc/asound.conf
speaker-test

This at least worked some years ago: DietPi-Config | Add native Bluetooth audio (bluealsa) support · Issue #3456 · MichaIng/DietPi · GitHub

EDIT:

That makes sense. Isn’t it possible to do the pairing with a service? You could order it before autostarts are reached. Also, IIRC, that bluealsa audio module is independent of an actually connected Bluetooth speaker. Of course it won’t work before, but if Kodi has a way to select that “bluealsa” card, or use the system default, it might work with above /etc/asound.conf.

Thanks
After further testing it appears something isn’t quite right.
If I turn my headphones off and then reboot the PC and turn the headphones back on at boot, I get the connect message through the headphones. However when checking the audio devices in Kodi, there is no Bluetooth.
So I then left the headphones on and rebooted. Got a disconnected message then Connected message at boot.
Checked Kodi again and the Bluetooth device is there.
Tried this again and no Bluetooth device.
I just noticed the the Bluetooth connected message happens during Kodi startup. Could it be that the connection is happening too late for Kodi to detect the Bluetooth device?

Does it work if you do

echo -e 'pcm.!default bluealsa\nctl.!default bluealsa' | sudo tee /etc/asound.conf

and then not select a specific audio device in Kodi but the system standard? IIRC that is also an option.

No that command did nothing.
I tried this

bluealsa-aplay: [1532] W: aplay.c:1231: Couldn't get BlueALSA PCM list: Rejected send message, 1 matched rules; type="method_call", sender=":1.35" (uid=1001 pid=1532 comm="bluealsa-aplay -l") interface="org.freedesktop.DBus.ObjectManager" member="GetManagedObjects" error name="(unset)" requested_reply="0" destination="org.bluealsa" (uid=0 pid=769 comm="/usr/bin/bluealsa -S -p a2dp-source -p a2dp-sink")

How do I reverse that command?

You can just remove the line from asound.conf.

To test for a timing problem stop the Kodi service, wait a few seconds, connect the Bluetooth device and restart Kodi.

Another interesting test would be:
Reboot,
Stop kodi
Do not connect the BT headphones
Do bluealsa-aplay -l (should output nothing)
Connect the headphones
Do again bluealsa-aplay -l
If you see your device, do speaker-test -D bluealsa -c 2

Thanks
I’ll try those. How do I stop/restart Kodi?
My PC is plugged into a TV and I can only access via ssh and from what I’ve read Kodi won’t start from SSH.

edited to correct false commands:
You can execute these commands to stop and start the Kodi service:

That’s a misunderstanding. The difference is where you start Kodi and where it’s displayed :wink:

You can start and stop Kodi from anywhere, but it’s only displayed on the local HDMI output.

Kodi is not started as systemd service, but just via kodi command from dietpi-login. Hence, it should be:

killall kodi

or

killall kodi.bin

or quitting via its GUI.

And right, just calling kodi --standalone from SSH works, and reveals some console output that is otherwise overlayed by the Kodi GUI.