Skip to content

Lets you control you SONOS speakers using a Bluetooth Button

License

Notifications You must be signed in to change notification settings

SvenSommer/BlueSonosButton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlueSonosButton

This script lets you control you SONOS speakers with a Bluetooth Button.

Sending commands from a cheap bluetooth button to a SONOS speaker is achived by using a RaspberryPi.
Once the paired bluetooth button sends a command to the Pi, it's forwarded to an HTTP based Api controlling the Sonos Speakers.

Usage

1. Install the script and dependencies

Clone this repository:

git clone https://github.com/SvenSommer/BlueSonosButton.git

Follow the installation instructions for your OS to get python-evdev.
I tested it with Debian on a RaspberryPi 3 model B using:

sudo apt-get install python-dev python-pip gcc
sudo apt-get install linux-headers-$(uname -r)
sudo pip install evdev

2. Install SONOS HTTP API

The magic controlling the sonos speaker is done with by the amazing SONOS HTTP API bridge by jishi.
(If you're interested, you can choose to install the api on a different host.)

git clone https://github.com/jishi/node-sonos-http-api.git
cd node-sonos-http-api
npm install --production
npm start

Once the SONOS API api is running you should be able to get information about your sonos system by runnig http://insertSonosApiHostIp:5005/

Important: Keep the api running!

3. Pair your bluetooth button

Pair and connect the bluetooth button with your RaspberryPi:

bluetoothctl
agent on
scan on

If you have found the button, use the address to trust, pair and connect to it:

trust 0C:FC:83:1F:28:6F
pair 0C:FC:83:1F:28:6F
connect 0C:FC:83:1F:28:6F

Important: Note the name of your button, it's need for the adjustements of the script.

4. Configure the script.

Open the and edit controlSonos.py in the cloned BlueSonosButton folder to your needs.

Global variables are:

# Modify your variable here
roomname = "Kitchen" # roomname your Sonos Speaker is located
buttonname = "Satechi Media Button" # also tested with "BT-005"
host = "localhost" # when installed on the same host use localhost
port = "5005" #default 5005
key2commandPairs = {"KEY_PLAYPAUSE":"playpause", # edit your button:command pairs
                    "KEY_NEXTSONG":"next",
                    "KEY_PREVIOUSSONG":"previous",
                    "KEY_VOLUMEUP":"volume/+2",
                    "KEY_VOLUMEDOWN":"volume/-2"}
# -------------------------------------------------

In addition you have to configure the buttons and the

5. Run the script

  1. Make sure the SONOS HTTP API is still running
  2. Start the script with python controlSonos.py

If everything is working as exspected you should see something like:

pi@raspberrypi:~/scripts/BlueSonosButton $ python controlSonos.py
Script started. Searching for Satechi Media Button...
Button found: device /dev/input/event1, name "Satechi Media Button", phys "b8:27:eb:63:ee:5f"
Received event KEY_PLAYPAUSE -> Sending command playpause ✓
Received event KEY_VOLUMEUP -> Sending command volume/+2 ✓
Received event KEY_VOLUMEDOWN -> Sending command volume/-2 ✓
Received event KEY_PREVIOUSSONG -> Sending command previous ✓
Received event KEY_NEXTSONG -> Sending command next ✓
Received event KEY_PLAYPAUSE -> Sending command playpause ✓

6. (Optional) Buy me a beer ;-)

If you liked my work, please tell me! And I wouldn't say no, if you'd like to buy me a (virtual) beer.

Further projects I've created are available on my blog www.robstechlog.com.

About

Lets you control you SONOS speakers using a Bluetooth Button

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages