Page 1 of 2

Music in the bathroom

Posted: Wednesday 29 July 2015 10:41
by matthijs
I always wanted music in the bathroom when I'm showering. The normal solution of a lowered ceiling with speakers wasn't an option for me because I rent the apartment I live in. The next option was a Sonos but that's a bit expensive for just in the bathroom. So i thought why can't I connect a bluetooth speaker to domoticz and when I touch a switch the music from a spotify playlist is playing?

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
Then open settings.ini again:

Code: Select all

sudo nano /boot/config/settings.ini
and change:

Code: Select all

output = alsasink into output = alsasink device=bluetooth
Put the lines (only) into the file asound.conf (/etc);

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
Put some lines into the file audio.conf (/etc/bluetooth);

Code: Select all

sudo nano /etc/bluetooth/audio.conf

Code: Select all

[General]
Enable=Source,Sink,Socket

Disable=Media
Reboot your Pi and the music must play to your bluetooth speaker.

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
To stop the playlist from playing I made another simple script:

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.

Re: Music in the bathroom

Posted: Wednesday 29 July 2015 20:45
by roblom
You can also install Kodi on the raspberry pi, then you can stream music to it from any network connected device. I use Yatse on my mobile phone to play music from my NAS.
There are also already some connections available between Kodi and Domoticz

Re: Music in the bathroom

Posted: Thursday 30 July 2015 0:53
by Derik
Love you if you where a girll..
Thanks..
Make my family happy with this...


xx

mmm edit...
i thought it was in domticz-with the same rpi...
buy a other pi... for this.
or can they work together, Domoticz and this pimusicbox, or a alternative?

Re: Music in the bathroom

Posted: Thursday 30 July 2015 4:21
by pvm
It should be possible to run a Bluetooth speaker from the same pi. I'm working in this too, got the audio connection running play mp3 file. Google translate audio not yet (My goal). Somehow it requests captcha authentication, but that's off topic. I've written down steps taken, but do not know if things keep working when speaker is disconnected and stuff like that. Too early to share. What helped me was http://www.correderajorge.es/bluetooth- ... streaming/ (without the sudo on the .asound file)

Re: Music in the bathroom

Posted: Thursday 30 July 2015 11:14
by matthijs
It's possible to run a bluetooth speaker from the same Pi. I had this working, but I couldn't get it working with spotify and I messed up the audio configuration. I tried several how to's to connect my bluetooth speaker to Kodi but none of them would work. It was indeed my first try because the simple integration with domoticz. I found PiMusicbox which uses Mopidy as core (That's the application you have to install when you want spotify running on the same Pi as Domoticz) and for playing streaming music it's a very nice program.
I have to clean my Raspberry pi with domoticz running first to try again, so before you try make a current backup of the image.

Re: Music in the bathroom

Posted: Thursday 30 July 2015 11:19
by Derik
Perhaps this version is "alfa" :-)
And when the Stable version there is, every streamingservice will work :-)

I have to wait for my pi..


And i'm happy with this as alternative for the sonos...

Re: Music in the bathroom

Posted: Sunday 02 August 2015 8:37
by Heisenberg
Interesting!
Is it possible to pair with multiple bluetooth speakers too? i.e. bathroom, toilet, study room to play same music stream at the same time?

Re: Music in the bathroom

Posted: Saturday 08 August 2015 8:54
by Heisenberg
pvm wrote:It should be possible to run a Bluetooth speaker from the same pi. I'm working in this too, got the audio connection running play mp3 file. Google translate audio not yet (My goal). Somehow it requests captcha authentication, but that's off topic. I've written down steps taken, but do not know if things keep working when speaker is disconnected and stuff like that. Too early to share. What helped me was http://www.correderajorge.es/bluetooth- ... streaming/ (without the sudo on the .asound file)

The URL is not active anymore?

Re: Music in the bathroom

Posted: Saturday 08 August 2015 10:50
by pvm
I've made some quick notes during my test last week. I will install it on my 'production' Domoticz install coming week and write wiki page for it. I don't have the possibility to test with multiple speakers

Re: Music in the bathroom

Posted: Saturday 08 August 2015 12:50
by Heisenberg
Great! Can't wait to read your wiki page. I hope streaming with multiple speakers can be achieved soon. Then it will be a cheap alternative for SONOS

Re: Music in the bathroom

Posted: Saturday 08 August 2015 13:18
by capman
I have a PI in my bathroom with musicbox installed on it. http://www.pimusicbox.com/
It's also connected with a sound board from hifiberry , the amp+. So my
speakers are direct connected to my pi , with great sound output.
https://www.hifiberry.com/ampplus/
Now a would also control al of this with my domoticz. But this is installed on my synology DS414 (more stable then on my first pi).
Is it possible with my configuration to control all of this ? Control happens now with MPD install on my phone and tablet.

Re: Music in the bathroom

Posted: Saturday 08 August 2015 14:48
by Derik
mmm
Can not wait until i get my Pi from China..
And try your great work..

Re: Music in the bathroom

Posted: Monday 10 August 2015 11:01
by matthijs
capman wrote:I have a PI in my bathroom with musicbox installed on it. http://www.pimusicbox.com/
It's also connected with a sound board from hifiberry , the amp+. So my
speakers are direct connected to my pi , with great sound output.
https://www.hifiberry.com/ampplus/
Now a would also control al of this with my domoticz. But this is installed on my synology DS414 (more stable then on my first pi).
Is it possible with my configuration to control all of this ? Control happens now with MPD install on my phone and tablet.
The easiest way to remote control PiMusicbox is mpc. This is what I use in my bash scripts to remotely control the Pi with musicbox. There is only one problem. For what I know you have to bootstrap your NAS to install mpc but maybe I'm wrong.
pvm wrote:I've made some quick notes during my test last week. I will install it on my 'production' Domoticz install coming week and write wiki page for it. I don't have the possibility to test with multiple speakers
I'm interested to see how you got it working.
Heisenberg wrote:Interesting!
Is it possible to pair with multiple bluetooth speakers too? i.e. bathroom, toilet, study room to play same music stream at the same time?
I can't test it because I have only one bluetooth speaker, but I'm afraid it won't work, at least not 'out of the box'. There is not enough bandwidth available in the bluetooth specification to connect two speakers at the same time. That's why it is only possible to connect to one device at the time (at least for most bluetooth devices). There are solutions for this, but then you won't use bluetooth. For example: http://www.amazon.co.uk/dp/B0049CUO56/r ... _M3T1_dp_1 and http://www.amazon.co.uk/Creative-D220W- ... ransmitter as speaker. But I don't know if that can be controlled with a script to implement it into domoticz.

Re: Music in the bathroom

Posted: Monday 10 August 2015 12:34
by pvm
Heisenberg wrote:Great! Can't wait to read your wiki page. I hope streaming with multiple speakers can be achieved soon. Then it will be a cheap alternative for SONOS
I created a wiki page: http://domoticz.com/wiki/BTAudio
(i do not want to steal this topic, please use http://www.domoticz.com/forum/viewtopic.php?f=28&t=7563 for further discussion on this description )

Re: Music in the bathroom

Posted: Sunday 27 December 2015 13:31
by thebeetleuk
How did you get on with this? All working?

Re: Music in the bathroom

Posted: Monday 28 December 2015 20:12
by jarvis
What's going on about your solution?

An other point: Did somebody find a waterproof switch with a dimmer ? :idea:

Re: Music in the bathroom

Posted: Monday 04 January 2016 17:02
by matthijs
It's still working every day. I haven't changed a thing since I installed it, except for one reinstall because of a corrupt sd card (power failure). I thought I wanted more (multi room audio etc.) but that's not the case. The only thing that I maybe want to implement in the future is a morning function. So when I push the play button for the music I get the weather forecast and traffic information for that day before it plays my spotify playlist, but I time is limited and I'm not the best programmer.

Re: Music in the bathroom

Posted: Sunday 10 January 2016 18:39
by BarryT
I think this can be really easy done by making a "Shoutcast" client on the pi.
Just give in a url (playlist/stream/etc) and there you go.
It is also possible to recieve title names, play stop etc on remote, and so on.

I had made this a while ago in a private sauna, at a friend.
When the pi gets powered, the shoutcast was picked up a (local private) stream from the synology nas and get played trough the speakers (line out on the pi).
I used a switch (with rfxcom) to power on and off the musicpi, and from remote site it was possible to turn it on or off / bundled with the lights of the room in domoticz.
It isnt possible to do something with volume, or choose another stream but that was no problem since they only want to hear "relaxing" music (that was downloaded on the nas), and for volume they had a exernal volumeknob on the amplifier.
I also did my sd-card locked, because of its on / off state (sd-cards doesnt like that the pi suddenly poweroff)
Also spotify and another service isnt possible with shoutcast/icecast, but maybe this is at least something to think about!

*1 Another option is to use a wifi radio (with a private "shoutcast" stream, or else) and power it on and off with a switch.
*1 The expensive ones does have support for spotify, etc.

*2 Again another option is really simple, if you are a little bit handy, you can make a RPI fm transmitter (check google how to do) so you have multiroom audio, for free ;-)

Grtz

Re: Music in the bathroom

Posted: Sunday 10 January 2016 21:16
by Derik
BarryT wrote:I think this can be really easy done by making a "Shoutcast" client on the pi.
Just give in a url (playlist/stream/etc) and there you go.
It is also possible to recieve title names, play stop etc on remote, and so on.

I had made this a while ago in a private sauna, at a friend.
When the pi gets powered, the shoutcast was picked up a (local private) stream from the synology nas and get played trough the speakers (line out on the pi).
I used a switch (with rfxcom) to power on and off the musicpi, and from remote site it was possible to turn it on or off / bundled with the lights of the room in domoticz.
It isnt possible to do something with volume, or choose another stream but that was no problem since they only want to hear "relaxing" music (that was downloaded on the nas), and for volume they had a exernal volumeknob on the amplifier.
I also did my sd-card locked, because of its on / off state (sd-cards doesnt like that the pi suddenly poweroff)
Also spotify and another service isnt possible with shoutcast/icecast, but maybe this is at least something to think about!

*1 Another option is to use a wifi radio (with a private "shoutcast" stream, or else) and power it on and off with a switch.
*1 The expensive ones does have support for spotify, etc.

*2 Again another option is really simple, if you are a little bit handy, you can make a fm transmitter so you have multiroom audio, for free ;-)

Grtz

What speakers do you use???
With Bluetooth or WiFi?

Re: Music in the bathroom

Posted: Sunday 10 January 2016 21:29
by Derik
BarryT wrote:I think this can be really easy done by making a "Shoutcast" client on the pi.
Just give in a url (playlist/stream/etc) and there you go.
It is also possible to recieve title names, play stop etc on remote, and so on.

I had made this a while ago in a private sauna, at a friend.
When the pi gets powered, the shoutcast was picked up a (local private) stream from the synology nas and get played trough the speakers (line out on the pi).
I used a switch (with rfxcom) to power on and off the musicpi, and from remote site it was possible to turn it on or off / bundled with the lights of the room in domoticz.
It isnt possible to do something with volume, or choose another stream but that was no problem since they only want to hear "relaxing" music (that was downloaded on the nas), and for volume they had a exernal volumeknob on the amplifier.
I also did my sd-card locked, because of its on / off state (sd-cards doesnt like that the pi suddenly poweroff)
Also spotify and another service isnt possible with shoutcast/icecast, but maybe this is at least something to think about!

*1 Another option is to use a wifi radio (with a private "shoutcast" stream, or else) and power it on and off with a switch.
*1 The expensive ones does have support for spotify, etc.

*2 Again another option is really simple, if you are a little bit handy, you can make a fm transmitter so you have multiroom audio, for free ;-)

Grtz

What speakers do you use???
With Bluetooth or WiFi?

And how do you set this in Domoticz?