Home Assistant 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

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.

7 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.

Leave a Reply

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