Page 1 of 1

Python : Bose soundtouch Multiroom with domoticz

Posted: Thursday 05 October 2017 13:34
by ayziaa
Hello all!

Just wanted to share a library that I found and use in order to command Bose soundtouch speaker with domoticz.
This library is based on the official API provided by Bose so it's very stable and complete.

Link to lib: https://github.com/CharlesBlonde/libsoundtouch

What you can do with this:

- Multiroom (from any sources, presets or airplay)
- commands like play, pause next song...
- Select presets
- Send music from different sources (URL, Spotify)
- Power on or off


I made a script to go with this lib, I didn't found any tutorial or any real examples of how this should work so I thought I'd share mine.

Code: Select all

#!/usr/bin/python


import libsoundtouch

from libsoundtouch import discover_devices
from libsoundtouch import soundtouch_device
from libsoundtouch.utils import Source, Type

from libsoundtouch.device import NoSlavesException, NoExistingZoneException, \
    Preset, Config, SoundTouchDevice, SoundtouchInvalidUrlException

devices = discover_devices(timeout=5) # look for soundtouch speaker and put them in a list

n_enceintes = len(devices) # how many speaker are available


if n_enceintes == 2:
	enceinte_1, enceinte_2 = devices
	print n_enceintes
	name_enceinte1 = enceinte_1.config.name
	name_enceinte2 = enceinte_2.config.name
	if "Ma chambre" in  name_enceinte1: 
		print ("enceinte Ma chambre:" + name_enceinte1)  
		enceinte_ma_chambre = enceinte_1
		
	if "Salon" in  name_enceinte1:
                print ("enceinte salon:" + name_enceinte1)
		enceinte_salon = enceinte_1

	if "Cuisine" in  name_enceinte1:
                print ("enceinte Cuisine:" + name_enceinte1)
		enceinte_cuisine = enceinte_1
	
	if "Ma chambre" in  name_enceinte2:
                print ("enceinte Ma chambre:" + name_enceinte2)
                enceinte_ma_chambre = enceinte_2

        if "Salon" in  name_enceinte2:
                print ("enceinte salon:" + name_enceinte2)
                enceinte_salon = enceinte_2

        if "Cuisine" in  name_enceinte2:
                print ("enceinte Cuisine:" + name_enceinte2)
                enceinte_cuisine = enceinte_2



if n_enceintes == 3:
	enceinte_1, enceinte_2, enceinte_3 = devices
	print n_enceintes
	name_enceinte1 = enceinte_1.config.name
        name_enceinte2 = enceinte_2.config.name
	name_enceinte3 = enceinte_3.config.name 
        if "Ma chambre" in  name_enceinte1:
                print ("enceinte Ma chambre:" + name_enceinte1)
                enceinte_ma_chambre = enceinte_1

        if "Salon" in  name_enceinte1:
                print ("enceinte salon:" + name_enceinte1)
                enceinte_salon = enceinte_1

        if "Cuisine" in  name_enceinte1:
                print ("enceinte Cuisine:" + name_enceinte1)
                enceinte_cuisine = enceinte_1

        if "Ma chambre" in  name_enceinte2:
                print ("enceinte Ma chambre:" + name_enceinte2)
                enceinte_ma_chambre = enceinte_2

        if "Salon" in  name_enceinte2:
                print ("enceinte salon:" + name_enceinte2)
                enceinte_salon = enceinte_2

        if "Cuisine" in  name_enceinte2:
                print ("enceinte Cuisine:" + name_enceinte2)
                enceinte_cuisine = enceinte_2

	if "Ma chambre" in  name_enceinte3:
                print ("enceinte Ma chambre:" + name_enceinte3)
                enceinte_ma_chambre = enceinte_3

        if "Salon" in  name_enceinte3:
                print ("enceinte salon:" + name_enceinte3)
                enceinte_salon = enceinte_3

        if "Cuisine" in  name_enceinte3:
                print ("enceinte Cuisine:" + name_enceinte3)
                enceinte_cuisine = enceinte_3




enceinte_salon.create_zone([enceinte_cuisine]) # Here "enceinte_salon" is the master "enceinte_cuisine" is the slave


presets = enceinte_salon.presets() #getting presets from master speaker
enceinte_salon.select_preset(presets[0]) # setting preset one one master speaker that will sync with slave/slaves


The way this works is you create zones of multiroom with one device as master and others as slaves. After they are all linked together they stay that way until shutdown or restart. Not only you can multiroom with your presets or sources defined in a python script but you can also connect with airplay to the master speaker which will send music to all slaves and the master at the same time.

Sorry for the poor coding, I don't know anything about python and I just made this work. It works in 2 case; with 2 or 3 speaker. This code is not meant to be used as it is but to be used as an example for you to do your own script. Sorry about the French names.

Don't forget to sudo chmod +x your script before using in a switch. Time I can loose on this things :lol: :lol:

If I can help in any way feel free to ask.

Re: Python : Bose soundtouch Multiroom with domoticz

Posted: Tuesday 06 February 2018 16:15
by Faecon
Can you help me out to get this running ? I am a noob in this :)
I used this tut to start using scripts ... viewtopic.php?t=9921


1. I figured out that i have to use putty. Made a directory outside the domoticz map to place the stript.

How do I save the script ? And what with the library ?

In you script I just have to reply the "ma chambre" name to the name i put on the bose , right ?

Re: Python : Bose soundtouch Multiroom with domoticz

Posted: Monday 05 March 2018 21:23
by jcjames13009
Hi

Is that package can be installed and works on Sinology?

I tried to install it without success. I have error messages:

unable to execute '/usr/local/i686-pc-linux-gnu/bin/i686-pc-linux-gnu-ccache-gcc': No such file or directory
error: command '/usr/local/i686-pc-linux-gnu/bin/i686-pc-linux-gnu-ccache-gcc' failed with exit status 1

and

Failed building wheel for netifaces

Couldn't find something on that...

JC

Re: Python : Bose soundtouch Multiroom with domoticz

Posted: Sunday 02 September 2018 21:54
by najtram

Re: Python : Bose soundtouch Multiroom with domoticz

Posted: Monday 03 September 2018 0:27
by MikeF
Indeed!