I ordered a bluetooth speaker and tried to get it working with my domoticz raspberry pi. That was a fail but then I used another empty Raspberry Pi and after 15 minutes I had a working bluetooth speaker with PimusicBox (a program that uses Mopidy, MPD and MPC).
I think it can be done with only installing mopidy and maybe even on the same Raspberry Pi as Domoticz but I couldn't get it working correct and after a while mopidy crashed and I couldn't get it working again so thats why I used another Pi.
A How to:
Hardware list:
-Working Domoticz
-another Raspberry Pi (I used an old 256mb version, but every version works)
-Earson - ER151 (cheap bluetooth speaker with good sound and can stand high humidity levels)
-bluetooth dongle ( I bought this one http://eu.banggood.com/Wholesale-Wareho ... 55088.html)
How to install:
Download PiMusicbox from http://www.pimusicbox.com and flash it to the SD card
Open the sd card on the computer and open settings.ini
You can add your wifi credentials here and also your spotify login. Don't forget to enable ssh login here.
Log in with root to Musicbox and do this:
Code: Select all
$ sudo apt-get install bluetooth bluez bluez-utils bluez-alsa
$ hcitool scan ## switch your bluetooth dongle to scan ##
$ bluetooth-agent --adapter hci0 0000 11:22:33:44:55:66 ## <--device you find with the scan and will connect ##
$ bluez-test-device trusted 11:22:33:44:55:66 yes
$ bluez-test-device trusted 11:22:33:44:55:66 ## If trusted, this will confirmed with a 1 ##
$ sudo /etc/init.d/bluetooth restart
Code: Select all
sudo nano /boot/config/settings.ini
Code: Select all
output = alsasink into output = alsasink device=bluetooth
Code: Select all
sudo nano /etc/asound.conf
Code: Select all
pcm.bluetooth {
type bluetooth
device 11:22:33:44:55:66 ##your device##
profile "auto"
}
Remove the file setsound.sh (/opt/musicbox)
Code: Select all
sudo rm /opt/musicbox/setsound.sh
Code: Select all
sudo nano /etc/bluetooth/audio.conf
Code: Select all
[General]
Enable=Source,Sink,Socket
Disable=Media
Then the Raspberry Pi must be connected to Domoticz.
I installed mpc from the wiki: https://www.domoticz.com/wiki/MPD_%26_D ... stallation
then i wrote a simple bash script to load a spotify playlist and play it.
Change it to the Ip address of your Raspberry Pi with Musicbox Image and to the port (default 6600) with lsplaylists you load the known spotify playlists and then you can load it into music box. With random on I shuffle the list and I change the volume to 20 (loud enough). Then I play and again put the volume at 20%, because sometimes the first one would not work.
music.sh
Code: Select all
#!/bin/sh
mpc -h YOUR_IP -p 6600
mpc -h YOUR_IP -p 6600 lsplaylists
mpc -h YOUR_IP -p 6600 load YOUR PLAYLIST
mpc -h YOUR_IP -p 6600 random on
mpc -h YOUR_IP -p 6600 volume 20
mpc -h YOUR_IP -p 6600 play
mpc -h YOUR_IP -p 6600 volume 20
musicstop.sh
Code: Select all
#!/bin/sh
mpc -h YOUR_IP -p 6600
mpc -h YOUR_IP -p 6600 stop
mpc -h YOUR_IP -p 6600 clear
Copy the scripts to the scripts folder from Domoticz and make both scripts executable.
I connected a 433mhz remote controller from kaku to domoticz and put the scripts into the on and off action. I've made two buttons, one for my girlfriend and one for me so we both can listen to our own playlist.
I think the scripts can be much better but it works for now.