Bose Soundtouch control

MikeF
Posts: 242
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Bose Soundtouch control

Post by MikeF » Monday 12 November 2018 12: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.

jurgen
Posts: 40
Joined: Friday 02 October 2015 19:09
Target OS: NAS (Synology & others)
Domoticz version: stable
Contact:

Re: Bose Soundtouch control

Post by jurgen » Tuesday 27 November 2018 22:43

Hi all,

Last week i tried to install libsoundtouch on synology and tried to controle my bose soundtouch with domoticz. But i had some problems with python version 2 and 3 and i was not able to get everything working. After some troubleshooting with python3 and install libsoundtouch with pip for python 3 it was working for me, so i would like to share it with other people.

In my case:

DSM 6.2.1-23824 Update 1
Python 3.5.1

steps i did to install everything:

ssh to synology

Check which version is installed (when python 3 is not installed, install it with the package manager in synology webinterface)

sudo -i
ls /volume1/@appstore/py3k/usr/local/bin
python3 python3.5 python3.5m

Install PIP for python3 to install libsoundtouch
cd /volume1/@appstore/py3k/usr/local/bin#
./python3 -m ensurepip

Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-7.1.2 setuptools-18.2


Install libsoundtouch with PIP
root@DS411:/volume1/@appstore/py3k/usr/local/bin# ./python3 -m pip install libsoundtouch
Collecting libsoundtouch
Downloading https://files.pythonhosted.org/packages ... ne-any.whl
Collecting websocket-client>=0.40.0 (from libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (200kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 200kB 534kB/s
Collecting zeroconf>=0.19.1 (from libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl
Collecting enum-compat>=0.0.2 (from libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... 0.2.tar.gz
Collecting requests<3,>=2 (from libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (57kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 61kB 1.2MB/s
Collecting six (from websocket-client>=0.40.0->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl
Collecting ifaddr (from zeroconf>=0.19.1->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... -0.1.4.zip
Collecting certifi>=2017.4.17 (from requests<3,>=2->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (146kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 147kB 653kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests<3,>=2->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (133kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 135kB 516kB/s
Collecting urllib3<1.25,>=1.21.1 (from requests<3,>=2->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (118kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 118kB 760kB/s
Collecting idna<2.8,>=2.5 (from requests<3,>=2->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (58kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 61kB 1.2MB/s
Collecting ipaddress (from ifaddr->zeroconf>=0.19.1->libsoundtouch)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl
Installing collected packages: six, websocket-client, ipaddress, ifaddr, zeroconf, enum-compat, certifi, chardet, urllib3, idna, requests, libsoundtouch
Running setup.py install for ifaddr
Running setup.py install for enum-compat
Successfully installed certifi-2018.10.15 chardet-3.0.4 enum-compat-0.0.2 idna-2.7 ifaddr-0.1.4 ipaddress-1.0.22 libsoundtouch-0.8.0 requests-2.20.1 six-1.11.0 urllib3-1.24.1 websocket-client-0.54.0 zeroconf-0.21.3
You are using pip version 7.1.2, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

When everything is installed, try with python3 if you are able to control bose soundtouch using the command line.
Use the following commands but edit the bose IP address to your speaker.

root@DS411:/python3

>>> from libsoundtouch import soundtouch_device
>>> from libsoundtouch.utils import Source, Type
>>> from time import sleep
>>> bose = '192.168.x.x'
>>> device = soundtouch_device(bose)
>>> device.power_on()
>>> print(device.config.name)
Soundtouch 20
>>> device.play()
>>> quit()

If you were able to control your speaker then proceed with the next steps.

mkdir /volume1/@appstore/domoticz/var/scripts/bose
cd /volume1/@appstore/domoticz/var/scripts/bose
nano presets.py

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])
save and exit

change permissions to execute
chmod a+x presets.py

try if this script is working, this will play preset 1 or button 1 on the speaker:
python3 presets.py 1

if the script is working that we can proceed to configure domoticz webinterface to interact with the python script

In domoticz go to settings ->hardware
add Dummy hardware
create virtual swith (selector)
go to devices and make sure that the device is added to switches
edit the switch
Make sure you add something like this (depents on your situation)
bose knoppen.JPG
bose knoppen.JPG (200.9 KiB) Viewed 49 times
If add something like this then you are able to select the presets like this.
eindresultaat.JPG
eindresultaat.JPG (46.34 KiB) Viewed 49 times

If you would like to controle the volume of the speaker with domoticz proceed with the next steps.

cd /volume1/@appstore/domoticz/var/scripts/bose
nano volume.py

Add the following script:
bose IP
Dimmer IDX to control the volume
NAS IP for the url to interact with domoticz

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)
Change the permissions
chmod a+x volume.py

Run the script in background.
python3 /usr/local/domoticz/var/scripts/bose/volume.py &

go to domoticz:
settings ->hardware add virtual switch under the dummy switch which created earlier.
Make sure that the switch is added and change the type to dimmer
dimmer.JPG
dimmer.JPG (191.89 KiB) Viewed 49 times
When everything is working fine then you need to make sure that the volume.py is started when the NAS is rebooted or booted. Create a startup script

cd /usr/local/etc/rc.d
nano bose-volume.sh
python3 /usr/local/domoticz/var/scripts/bose/volume.py &

chmod a+x bose-volume.sh

Done!

@MikeF credits for you for the initial scripts in your first post.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests