mp6z - Raspberry Pi/Linux/etc software to control Monoprice 6-zone Whole House Audio

signal15

Senior Member
I picked up a pi zero w to play with, and figured this would be a neat project.  I whacked this up this morning and it works pretty good.  It's a CLI tool, but it outputs JSON, with the intent of eventually calling it from a web app that would provide connectivity to a phone app and home automation systems.  I'm not a web developer, so if someone wants to use this to make a REST web app that will run on the Pi, that would be awesome.
 
Project is here:
 
https://github.com/signal15/mp6z
 
Code:
usage: mp6z.py mode [zone] [-h] [--verbose] [-v V] [-s S] [-b B] [-t T] [-m M] [-d D]
               [-p P] [--bl bl]
               
 
positional arguments:
  mode        <get|set>
  zone        <11-16,21-26,31-36>
 
optional arguments:
  -h, --help  show this help message and exit
  --verbose   Increase output verbosity
  -v V        Set Volume (0-38)
  -s S        Set Source (1-6)
  -b B        Set Bass (0-7)
  -t T        Set Treble (0-7)
  -m M        Set Mute (0=Off, 1=On)
  -d D        Set Do Not Disturb (0=Off, 1=On)
  -p P        Set Power (0=Off, 1=On)
  --bl BL        Set Balance (0-20, 10=Center)
 
Examples:
$ ./mp6z.py get   --  This will get the settings for all zones and output in JSON format
$ ./mp6z.py get 21 --  This will get the settings for the 1st zone on the second controller (if you have multiples chained)
$ ./mp6z.py set 21 -v 15 -s 6 --  This will set the 1st zone on the second controller to use source 6 and set volume to 15.
                                  Output will be the new settings in JSON format.
 
 
 
pi@pizerow:~/mp6z $ ./mp6z.py get 11
{
  "11": {
    "balance": "10", 
    "bass": "13", 
    "dnd": "00", 
    "keypad": "01", 
    "mute": "00", 
    "name": "Dining Room", 
    "pa": "00", 
    "power": "01", 
    "source": "05", 
    "sourcename": "Empty", 
    "treble": "14", 
    "volume": "11"
  }
}
pi@pizerow:~/mp6z $ ./mp6z.py set 21 -v 5 -s 6
{
  "21": {
    "balance": "10", 
    "bass": "14", 
    "dnd": "00", 
    "keypad": "01", 
    "mute": "00", 
    "name": "Office", 
    "pa": "00", 
    "power": "01", 
    "source": "06", 
    "sourcename": "Sonos", 
    "treble": "13", 
    "volume": "05"
  }
}
 
 
 
I updated the project to provide a REST api on a webserver.  It's quick and dirty, but it works.  You'll need to install Flask to use it.  Now I just need a phone app that works with it.  :)
 
Usage for webapi.py flask app:
 
  • Install flask and get it working with nginx (plenty of tutorials on this)
  • Install shelljob (pip install shelljob)
  • Default path for mp6z.py is /home/pi/mp6z/mp6z.py. You'll need to change this in several places in the webapi.py script
  • Start webserver
 
Examples of URLs: 
http://127.0.0.1:5000/api/v1/zones --- Method: GET - Gets settings for all zones 
http://127.0.0.1/5000/api/v1/zones/11 --- Method: GET - Gets settings for Zone 1 on Controller 1 
http://127.0.0.1/5000/api/v1/zones/11 --- Method: PUT - Updates settings for Zone 1 on Controller 1 and returns new settings. Example below:
 
Code:
pi@pizerow:~ $ curl -i -H "Content-Type: application/json" -X PUT -d '{"volume":"10", "source":"2", "bass":"14", "treble":"13"}' http://localhost:5000/api/v1/zones/21
HTTP/1.0 200 OK
Content-Type: text/plain; charset=utf-8
Connection: close
Server: Werkzeug/0.12.2 Python/2.7.9
Date: Sun, 12 Nov 2017 21:27:46 GMT
 
{
  "21": {
    "balance": "10", 
    "bass": "14", 
    "dnd": "00", 
    "keypad": "01", 
    "mute": "00", 
    "name": "Office", 
    "pa": "00", 
    "power": "01", 
    "source": "02", 
    "sourcename": "Chromecast", 
    "treble": "13", 
    "volume": "10"
  }
}
 
Back
Top