Python : Bose soundtouch Multiroom with domoticz

Python and python framework

Moderator: leecollings

Post Reply
ayziaa
Posts: 4
Joined: Wednesday 21 September 2016 20:45
Target OS: -
Domoticz version:
Contact:

Python : Bose soundtouch Multiroom with domoticz

Post 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.
Faecon
Posts: 2
Joined: Thursday 28 December 2017 8:49
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python : Bose soundtouch Multiroom with domoticz

Post 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 ?
User avatar
jcjames13009
Posts: 33
Joined: Monday 09 March 2015 15:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France / Marseille
Contact:

Re: Python : Bose soundtouch Multiroom with domoticz

Post 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
User avatar
najtram
Posts: 62
Joined: Wednesday 26 April 2017 11:50
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.9700
Location: Netherlands
Contact:

Re: Python : Bose soundtouch Multiroom with domoticz

Post by najtram »

RFLink Gateway → 433Mhz/KAKU switches
Z-Wave → Z-Stick Gen5+
ZigBee → ConBee II
Bluetooth → Soma Smart Shades
Opentherm Gateway → Remeha iSense - Tzerra boiler
ESP8266+CC1101 → ITHO ecofan RFT
P1 cable → DSMR 2.2+ Landys +gyr E350
LAN → Enphase Envoy
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Python : Bose soundtouch Multiroom with domoticz

Post by MikeF »

Indeed!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest