From Domoticz
Jump to: navigation, search

Use a bluetooth speaker

Goal is to use a bluetooth (BT) speaker to let domoticz talk. This setup should also be usable for music purposes, which is the first step to take. I used a 'Mini-X6U' speaker and a brandless usb BT stick

Use this forum topic for support

Install bluetooth support

Update your system

sudo apt-get update
sudo apt-get upgrade

List your attached USB devices (without BT audio stick connected)


Insert BT USB stick


When you compare this to the previous 'lsusb' output you should see your bluetooth stick (mine is 'Bus 001 Device 006: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)')

Install needed packages for bluetooth support (required 156 mb on my system and took 5 minutes on Pi2 and approx. 20 minutes on PiB)

sudo apt-get install bluetooth bluez bluez-utils bluez-alsa

(this also installs printer support etc.)

Set user rights for bluetooth

sudo usermod -a -G lp root

(root might not be needed....)

sudo usermod -a -G lp pi

Edit the bluetooth audio configuration sudo nano /etc/bluetooth/audio.conf Find the [General] section and locate the following:

# If we want to disable support for specific services
# Defaults to supporting all implemented services

Change to:

# If we want to disable support for specific services
# Defaults to supporting all implemented services

reboot the system (from domoticz or 'sudo reboot')

Pair bluetooth speaker and enable audio

(First try without the next step, it was in the instructions I used, but does not seem to be needed, please remove from this instruction when not needed) 'sudo hciconfig hci0 up'

Enable your bluetooth speaker (power-on) and find the speaker

hcitool scan

my result:

Scanning ...
        30:22:10:00:52:5C       Mini-X6U

Start pairing (use your mac address, and your device pincode (in my case 0000 )

bluetooth-agent --adapter hci0 0000 30:22:10:00:52:5C

resulting in "Agent has been released"

bluetooth-agent hci0  30:22:10:00:52:5C

Trust the device for future use

bluez-test-device trusted 30:22:10:00:52:5C yes

Check the trust:

bluez-test-device trusted 30:22:10:00:52:5C

when this returns 1 everything is ok

Create the audio settings file (this file is needed for every user): nano ~/.asoundrc

pcm.bluetooth {
        type bluetooth
        device 30:22:10:00:52:5C # change this MAC address to your speakers address
        profile "auto"

Restart the bluetooth engine

sudo /etc/init.d/bluetooth restart

Install mediaplayer

Install mplayer (64mb, 1 or 2 minutes on Pi2)

sudo apt-get install mplayer

edit the mplayer configuration file to prevent loading lyrics (which is not needed and reports errors on my machine sudo nano /etc/mplayer/mplayer.conf and add (top top)


Play MP3 using mediaplayer

mplayer -ao alsa:device=bluetooth /media/networkshare/BackupPI/TOOL_FORTY_SIX_2_DRUM_COVER_BY_MEYTAL_COHEN.mp3 -softvol -volume 10 -af resample=22100:0:0

This command executes the mplayer, changes output to bluetooth, used the mp3 file specified, specifies to use sofware controlled volume control, sets volume to 10 (=10%) and resamples to avoid filling the buffer

Use from within domoticz

This chapter is still empty