Pi 3b+ bluetooth autoreconnect

Hey guys,

new to OSMC, but i used kodi in Libreelec before. I was struggling with some setup so i decided to go to OSMC. I installed it last night, and followwed the latest instructions for bluetooth, so it can work with a bit of workaround.
Every time i go and power on my bluetooth speaker, i need to reconnect the Pi via bluetoothctl, and then go to OSMC to switch to alsa or hdmi audio output and then back to alsa autodetection thing to get the sound working.
There is no slutter when working, and no latency or crashes, it can work until i turn off the speaker.

Oh btw, i’m using an external usb dongle for bluetooth only (wich is fine i guess, seems to work better with, i’ve choose this one by default and i think i disable the onboard one ) and i’m on wifi.

What am i missing here ? Is there a way, a script to automate this ?
Thx a lot,

Did you disable it? That would be important to confirm.

Did you pair, trust and connect?

Generally for myself autoconnect quite well. I always keep the audio output on alsa/Bluetooth

Yeah, i add a line in config.txt.
Pair trust connect exactly. but i still need to connect through bluetoothctl, it won’t work via Kodi.

EDIT; Should i let the scan on ? Maybe that’s it.

But even connected, i still need to switch from alsa/bluetooth to something and then back to alsa/bluetooth for sound to pass through. Weird thing.

No need for me.

Really strange. Maybe upload debug logs where we might see something.

Could u point me how to ? i’m a bit unused to linux these days. Thanks
EDIT: My bad, think i got it, brb and thanks
Here they are https://paste.osmc.tv/palefuzece
here the full one https://paste.osmc.tv/sebiricoxi

Not sure what i’m doin ^^

EDIT2: i can’t stop editing. Well it autoreconnect when i’m logged in in a terminal, but still need to switch audio output back and forth for sound to go.
I need to add a line to logg in anybody on startup do i ?

Not sure what you mean by this?

A quick view at the log didn’t reveal anything

yeah my bad, because i read somewhere than pulseaudio won’t start if someone isn’t logged in, and there is no logging in at osmc boot ? Only in the terminal.

I guess i’m stuck with switching back and back each time i want to use it ? for now at least. Do u think i’ll have more luck on raspbian with kodi and some tweaks ? thx anyway

No, pulseaudio is configured to be started when needed.

Well you might have more success but you will have much more work to get the same performance

that what i thought too. Ok for pulseaudio, but i’m asking myself: can’t i tweak it to only output audio with bluetooth ? whil forgetting about hdmi, analog and all ? this could work ?
One last thing while i have you ^^: how can i switch audio output from terminal and is it possible to script to start whenever pulseaudio is started ?

you could do that via json and kodi.
You would need to read up on it as it recently changed.

curl -H “Content-type: application/json” -X POST -d ‘{“jsonrpc”:“2.0”,“method”:“Settings.SetSettingValue”, “params”:{“setting”:“audiooutput.audiodevice”,“value”:“ALSA:pulse”},“id”:1}’

Ok i’ll have a look onto it. Thanks for your help, if i manage to get something up i’ll update this thread. Have a nice day

EDIT: Meh… My bad i guess, here’s what i did, seems to work flawlessly now:

sudo nano /etc/bluetooth/audio.conf

[General]
Enable=Source,Sink,Media,Socket
HFP=true
Class=0x20041C

sudo nano /etc/bluetooth/main.conf

[General]
Name = osmc
Class = 0x20041C

sudo nano /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/settings

[General]
Discoverable=true
Alias=osmc
Class=0x20041C

connmanctl enable bluetooth
sudo hciconfig hci0 up

bluetoothctl

agent on
default-agent
discoverable on
scan on

Don’t know how to make that console text but anyway, that worked out. was it necessary ? apparently.