#Home Audio API
- [What is this script] (#what-is-this-script)
- Requirements
- Installation
- Endpoint URLs
- Available Zones
- Sending Commands
- Example Commands
- Toggle Power
- Change Sources
- Adjust Audio
In the fall of 2015 I purchased a whole home audio controller from monoprice. I wanted to control it from my phone. I taught myself Swift and released an app called Home Audio. It required a special ethernet -> serial adapter to hookup the monoprice's serial adapter to the network, but it worked great. I had a Raspberry Pi 2 sitting in a box looking for a project, so I decided to create a simple Web API for a cheaper option.
Please be aware, this is not the fastest thing in the world. We're going across a serial port. To refresh the status of everything can take some time. Pushing commands should be pretty quick though, I've gotten responses in 1-2 seconds.
To actually use this script, you need a few things:
- Monoprice Whole Home Audio Controller.
- Raspberry Pi 2 (any computer that can run python will work, this is just what I used)
- USB -> Serial Adapter (not needed if you have a computer with a serial port)
- 10 foot Serial cord
If your computer has a built in serial port, you will have to update line 5 to use the correct serial port. /dev/ttyUSB0
is used when there is a USB serial port.
Aftering hooking everything up and powering it on(I always made sure the Pi was on first before turning on the Monoprice unit) you need to install Python. If you are using a Pi, you should be able to type in these commands to download and install Python.
sudo apt-get update
sudo apt-get install python3-picamera
After that you can use whatever method you want to download the project (homeAudio.py and instructions.tpl) to the Rasperry Pi. Make sure they are both in the same directory!
Open a command prompt and browse to the project directory and run
python homeAudio.py
That should do it!
*Where 0.0.0.0 is the IP address of your Raspberry Pi *
Instructions: http://0.0.0.0/
Get Unit Status: http://0.0.0.0/status
Get Zone Status: replace zone below with a number from below. For example, 11 to get Zone 1 on Unit 1. http://0.0.0.0/status/(zone)
Send Command: http://0.0.0.0/send
Unit 1 | Unit 2 | Unit 3 | |
---|---|---|---|
Zone 1 | 11 | 21 | 31 |
Zone 2 | 12 | 22 | 32 |
Zone 3 | 13 | 23 | 33 |
Zone 4 | 14 | 24 | 34 |
Zone 5 | 15 | 25 | 35 |
Zone 6 | 16 | 26 | 36 |
To send a command you need to send a POST request to the url with a json payload. This payload is pretty simple, for example, to turn on Zone 1, I would send:
{ command:11PR01 }
There are many different ways to send a request. To test it out, you can download a utility called curl and send the commands from a command prompt like this:
curl -d "command=11PR01" http://0.0.0.0/send
###Example Commands
The first number in each command is the unit you are targeting. The master unit is always 1. If you had a 2nd or third slave unit, you would substitute the first 1 with a 2 or 3 depending on which unit you wanted to control.
The second number in each command is the zone you are targeting. You can substitute the 1 for a 2,3,4,5 or 6 to reach all the zones on a particular unit.
In the examples below, I am always targeting Unit 1 Zone 1. If you wanted to target, say, Unit 1 Zone 4, the commands would start with 14 instead of 11.
###Toggle Power
11PR00 - Turn Off Zone 1
11PR01 - Turn On Zone 1
###Change Sources
11CH01 - Change Zone 1 to Source 1
11CH02 - Change Zone 1 to Source 2
11CH03 - Change Zone 1 to Source 3
11CH04 - Change Zone 1 to Source 4
11CH05 - Change Zone 1 to Source 5
11CH06 - Change Zone 1 to Source 6
###Adjust Audio
For audio adjustments, the last two numbers can range from 00 to 09
11VO03 Change Volume to 3
11BS04 Change Bass to 4
11TR06 Change Treble to 6