Home Assistant Bluetooth Speaker

Video unboxing the Xiaomi Motion sensor and adding it to HA, along with pairing and using a Bluetooth speaker!

So there are two things I want to cover in this post. First, I have done a second unboxing video which can be found below. Felt this was slightly better than the first. Will just keep practicing, putting myself out there and hopefully getting more comfortable with this sort of thing.

Secondly, I have managed to get Home Assistant working with a Bluetooth speaker. Why you might ask, well, I had one sat doing nothing and thought it would be nice to announce stuff (like door open, play a doorbell sound etc). At the moment, I do not have an Echo or Google speaker to make us of so this is the next best thing. Anyway, please watch the video below. I am working on my presentation skills.

Home Assistant with Bluetooth Speaker

Read the update at the end!

So, the part you are here for! Configuring Home Assistant to make use of a Bluetooth speaker. I run Home Assistant on ESXi. It works well for me. When I bought a Nokia phone many years ago, I got a free Nokia MD-12 Bluetooth speaker. It’s not a bad little device, works well in our kitchen paired to a phone etc. In terms of additional hardware, I just needed to purchase a USB Bluetooth dongle (thinking about it I think my ASUS PN50 has built in) so that I could pass this device through to the guest.

Now this all seems simple enough so far. But it’s not quite unfortunately. I did a lot of Googling and found lots of people attempting this and it did take a fair bit of trial and error to get things right. There are lots of reference to Bluetooth tracking within HA which isn’t needed. There was one post on Reddit which I found got me like 99% of the way there, thank you to u/barrie_man. So, how did I do it?

It starts with logging on to the console. It MUST be the console, not the Terminal add in within HA and not via SSH. Login with “root” and no password by default

When logged in, at the ha prompt, type login to get to the shell prompt

I can’t screen grab the following as it’s all already done but I used the following commands from the above post:

bluetoothctl
# note no SUDO available on HA VM
list
# Controller XXXXXX mydevice [default]
power on
agent on
default-agent
scan on
# [NEW] Device AA:BB:CC:DD:EE:FF XYZ
# Now I Press the pairing button on the device (disabling bluetooth on any nearby devices)
pair AA:BB:CC:DD:EE:FF
connect AA:BB:CC:DD:EE:FF
trust AA:BB:CC:DD:EE:FF
exit

At this point my speaker was paired to my HA VM. Winning! Except it wasn’t. I tried doing the du command and it couldn’t find a working asound.conf file. The ones thrown up were generated as part of the Docker processes and were empty. I eventually managed to find the file at

/mnt/data/supervisor/audio/asound

Note: the file name is “asound” not asound.conf or anything like that. I made a backup of the file (mv command) and then I edited the contents as follows using “vi”

So that you can copy/paste the code is below:

pcm.!default {
    type plug
    slave.pcm "btreceiver"
}

pcm.btreceiver {
    type plug
    slave {
        pcm {
            type bluealsa
            device AA:BB:CC:DD:EE:FF
            profile "a2dp"
        }
    }
    hint {
        show on
        description "MD-12"
    }
}

ctl.!default {
    type bluealsa
}

At this point the speaker is paired to the VM and the VM is configured to use this as an output for sound. I gave HA a reboot at this point to see if anything would be discovered. Not surprisingly it was nada. This is where I ended up getting a little more creative. I added the “Local VLC” community Add-on. Once installed, I provided a telnet and HTTP password. I was also able to select MD-12 from the output devices (for some reason this isn’t shown below)

I logged in to the http interface and was able to play a MP3 file (homed in the share directory)! Now we are winning! So how do we use it within Home Assistant? Well, HA has a built in VLC Telnet client, so I added the following to my config.yaml file:

media_player:
  platform: vlc_telnet
  name: Local MD-12
  host: 127.0.0.1
  password: HA HA yeah right

Of course, give HA a restart, look through the Entities and you will findone called “Local MD-12” which is a media player! I added a Love Lace card for it and when clicking the 3 dots I can enter “Text to speak” and sure enough that text is read out via the BT speaker

It’s not perfect, I think I need to do some bash scripting on the host to make sure the speaker remains connected and doesn’t go to sleep. I also think it needs a script to connect at start (probably the same script). Something else that needs a little work is that the range doesn’t quite reach to where I want to place the speaker. Somewhere in my box of cables is a USB extension lead that I will dig out so that the BT adapter is then outside of the rack.

29 thoughts on “Home Assistant Bluetooth Speaker

  1. how do you get to the prompt if it’s on an RPi docker image? just like stick a monitor on there? or can logging in through the docker container be good enough?

    1. You can use the Terminal & SSH plugin to run the commands for Bluetoothctl. I’ve certainly done this after a reboot to reconnect the speaker. For editing the config files on a Pi, I don’t know, what prompt do you have if you connect a display to the Pi?

  2. Thank you for this tutorial. Based on this I could connect my Anker SoundCore 2 to my Raspberry Pi running HA operating system.

  3. Hello, Did you have any problems with the sound quality? It seems that it is working on my Hassio on RPI, but it behaves like it is nearly out of range even, when the bluetooth speaker is close to the RPI.

    1. I had my BT Speaker next to a microwave. I sometimes found after using the microwave, it would sound a bit like it’s underwater, distorted. I would reboot the speaker and re-pair it and it would fix it until next time we used the microwave.

  4. This is GREAT! I’m going to try to run through later and update some of the many forum posts with a link to this method. If you’re looking for another video to post, this would be it. Bravo, Mark.

  5. Hi Mark. Good to know Bluetooth audio is possible with home assistant OS on a VM. Myself I use home assistant (in a container, on a VM), and set up a audio system around snapcast, which generates the audio on the home assistant VM. The audio is played back on a different raspberry pi which plays on local speakers as well as a Bluetooth connected speaker. I still need to put in some time to create a home assistant add-on for snapcast. I did do a write-up of my set up if you’re interested: https://www.thouters.be/HassMultiRoomAudio.html
    The added advantage of using snapcast is that you can have synchronized playback on multiple devices (pi’s, laptop’s, android devices…)

  6. list shows nothing for me. I passed through my Bluetooth USB dongle.
    Perhaps it’s not supported…………..

  7. I am having the same problem with the speaker not showing up in the list of entities.

    The Bluetooth speaker is paired and connected, but it does not show up at all in vlc or home assistant.

  8. Looks like on HA OS v8 we can’t connect to the Bluetooth speaker anymore.
    Getting the below error:
    Failed to connect: org.bluez.ErrorNotAvailable br-connection-profile-unavailable

    Any hint?
    Thanks.

    1. Am just taking a look, I get a Failed br-connection-create-socket error when attempting to connect using bluetoothctl. The service status for bluetooth is reporting kernel lacks bnep-protocol support. Will update if I get anywhere

        1. Not yet, it looks like something has massively changed and I can no longer get my BT Speaker paired. Will update when I figure it out.

  9. Hi, I read your interesting blog, and I managed to pair, connect and trust the device with bluetoothctl.
    I did it in V 2022.9. My home assistant is on a RPI 4, and I cannot edit the asound-file I fond: /etc/asound.conf (readonly sustem)
    I do not find any other asound file without extention, there is only an empty /proc/asound directory

    Can you tell me where your asound file is located in v.2022.9 ?

    1. On the console of my VM I can find the file located at:
      /mnt/data/supervisor/audio/asound

      Note that is a file not a folder, there is no file extension

  10. No /mnt/data/supervisor/audio folder on my Rpi-4 system. And no asound file.
    SO there seems no option at the moment to get it running on a Home Assistant on Rpi

  11. In hassio the folder is /usr/share/hassio/sound for me. The other steps are perfect.

  12. I just installed Homeassistant Os on my raspberry Pi 4. I ma not able to find the path /usr/share/hassio/sound. There is no folder hassio under /user/share. Kindly help

  13. Great work, Followed your instructions and it worked.
    Using RPI2 with a bluetooth dongle.
    Regarding the bash scripting you mentioned, I added shell commands for connecting/disconnecting the speeker from the homeassistant

    shell_command:
    bt_speeker_connect: bluetoothctl connect AB:CD:EF:AB:CD:EF
    bt_speeker_disconnect: bluetoothctl disconnect

  14. 3-3-2023

    thank you!

    on latest HA and bt speaker working (lg soundbar)

    install vlc
    run bluetoothctl on host – connect device(type list / help)
    add to confg.yaml under default_config section:
    media_player:
    platform: vlc_telnet
    host: 127.0.0.1
    some restarts
    should be able to select vlc_telnet from media sources and play sounds
    for it to work the bt device needs to be connected – inside bluetoothctl – run “connect xx:xx:xx:xx:xx:xx” (your device mac)

    seems to disco fairly fast – as vuly says – you probably want to automate the bt connect –

Leave a Reply

Your email address will not be published. Required fields are marked *