Bose Soundtouch control

Post Reply
Posts: 182
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: UK

Bose Soundtouch control

Post by MikeF » Saturday 24 February 2018 13:31

I have a Bose Soundtouch 20 Series II (wifi version), and I recently came across this python library for accessing and controlling it.

I have created two simple (i.e., can be improved!) python scripts: selector and volume control.

This script uses a Domoticz selector switch to select from the 6 stored presets; I have extended it to add two streaming URLs, as well as the Soundtouch's AUX input:
(I'm using 10 levels - 0 to 90 - but this can be extended / reduced as required.)

The code (see later) takes a single argument (0 to 9), corresponding to the above levels, and the selector actions have been set up as follows:
Obviously, change this to correspond to the names for your presets!

Spoiler: show

Code: Select all

#!/usr/bin/env python

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

bose = '<your Soundtouch wifi address>'
# put your stream URLs here			
url1 = '' 			
url2 = ''

device = soundtouch_device(bose)
presets = device.presets()

# read arg
arg = int(sys.argv[1])
print arg

if arg == 0: # power off
if 1 <= arg <= 6: # presets 1-6

if arg == 7: # HTTP URL (not HTTPS)

if arg == 8: # HTTP URL (not HTTPS)
if arg == 9: # AUX
Save this with the name and location specified in the selector actions (I used /home/pi/devices/

Volume control
Set up a dummy switch in Domoticz, and change it to type 'dimmer' (0 - 100%).

This uses the following python script:
Spoiler: show

Code: Select all

#!/usr/bin/env python

from libsoundtouch import soundtouch_device
from libsoundtouch.utils import Source, Type
from time import sleep
import requests
import json

bose = '<your Soundtouch wifi address>'
volIdx = '<Domoticz idx for dimmer switch>'
url = 'http://<domoticz url:port>/json.htm?type=devices&rid=' + volIdx
oldStatus = ''

device = soundtouch_device(bose)

def domoticzread(var):
	response = requests.get(url)
	jsonData = json.loads(response.text)
	result = jsonData['result'][0][var]
	return result

while 1:
	volume = domoticzread('Level')
	status = domoticzread('Status')
	if status != oldStatus: 
		#print volume, status
		if status == 'Off':
			# status = 'On' or 'Set Level: <x> %'
	oldStatus = status
This needs to be run in background, e.g.,

Code: Select all

python /home/pi/devices/ &
or started on boot in crontab.

(In both scripts, insert your own values in angle brackets: <...>)

I'm interested in any comments / suggestions for improvement.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests