Re: Bose Soundtouch control
Posted: Monday 12 November 2018 11:06
This looks as if something is broken in your version of libsoundtouch. Try running 'sudo apt-get update', and then remove / install libsoundtouch, to see if this helps.
Code: Select all
#!/usr/bin/env python3
from libsoundtouch import soundtouch_device
from libsoundtouch.utils import Source, Type
import sys
bose = '192.168.x.x'
device = soundtouch_device(bose)
device.power_on()
presets = device.presets()
# read arg
arg = int(sys.argv[1])
if arg == 0: # power off
device.power_off()
if 1 <= arg <= 6: # presets 1-6
device.select_preset(presets[arg-1])
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 = '192.168.x.x'
volIdx = 'Dimmer IDX like 103'
url = 'http://192.168.x.x:8084/json.htm?type=devices&rid=' + volIdx
oldStatus = ''
device = soundtouch_device(bose)
device.power_on()
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':
device.set_volume(0)
else:
# status = 'On' or 'Set Level: <x> %'
device.set_volume(volume)
oldStatus = status
sleep(0.2)
For those who got this error: check the python version (terminal, python -V). If version 2.7.x, zeroconf might be a high version (terminal, pip show zeroconf). Version 0.20 and higher does not support python 2.7. If you want to use python 2.7, uninstall zerconf (pip uninstall zeroconf) and install version 0.19.1 (pip install zeroconf==0.19.1)hubd wrote: ↑Sunday 11 November 2018 21:25 Hi,
I tried to connect to Soundtouch. I get this error:
File "bose.py", line 7, in <module>
from libsoundtouch import soundtouch_device
File "/usr/local/lib/python2.7/dist-packages/libsoundtouch/__init__.py", line 9, in <module>
from zeroconf import Zeroconf, ServiceBrowser
File "/usr/local/lib/python2.7/dist-packages/zeroconf.py", line 175
def current_time_millis() -> float:
^
SyntaxError: invalid syntax
My Python-version is:
Python 2.7.9
My Python 3-version is:
Python 3.4.2
Latest libsoundtouch, installed with pip
I am on a Raspberry PI 3 running Linux version 4.9.41-v7+ (dc4@dc4-XPS13-9333)
(gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) )
#1023 SMP Tue Aug 8 16:00:15 BST 2017
Hope you can help
Hubd
I read the documentation of the Bose API and I found a different way to activate AUX as libsoundtouch was no more able to do it (probably because of a new firmware)Furiousz23 wrote: ↑Friday 24 August 2018 22:43
Hi
Unfortunately the selector switch didn't work after all, only the volume slider worked. In the Domoticz log there where no errors, but the sound touch didn't respond to the Domoticz selector commands. At the moment I just made a fresh install on my Raspberry, so I will try to get the Bose script working again.
Code: Select all
#!/bin/bash
curl -s -o /dev/null --request POST --header "Content-Type: application/xml" --data '<ContentItem source="PRODUCT" sourceAccount="TV"></ContentItem>' http://IP OF THE BOSE:8090/select
A way better solution than the python script in background ! Bravo and thank youMikeF wrote: ↑Friday 05 October 2018 23:51 I've come up with an alternative solution for controlling Bose volume: instead of using a python script which runs continuously:and reads the json from the device to check for a change of volume, I've created a simple lua script which passes the volume value to an equally simple python script.Code: Select all
while 1: ... sleep(0.2)
Lua script:Python script:Code: Select all
-- Set Bose volume -- change next line to match name of your Bose volume device in Domoticz local bose = 'Bose volume' -- change next line to match location of your python script; keep space at end local py_script = 'python3 /home/pi/devices/bose_vol.py ' commandArray = {} if devicechanged[bose] then boseVolume = otherdevices_svalues[bose] cmd = py_script .. boseVolume os.execute(cmd) end return commandArray
I believe this is a more responsive approach, and better integrated with Domoticz.Code: Select all
#!/usr/bin/env python3 from libsoundtouch import soundtouch_device from libsoundtouch.utils import Source, Type import sys volume = int(sys.argv[1]) # change next line to match url of your Bose bose = '192.168.0.69' device = soundtouch_device(bose) device.power_on() device.set_volume(volume)
Edit: I left out the second import from libsoundtouch in the last script - now added.