Several users have posted various ways to use Siri to control Roon. These usually take the form of a fake device in HomeBridge that then communicates with HomeKit and Siri. This seems cool but maybe overkill. I was able to get Siri voice control of Roon working with simple SSH shortcuts that execute Python scripts which utilize the Roon API to control Roon. People don’t seem to know about Apple’s SSH shortcuts. They can be used to execute commands on systems that allow SSH access. I used an Ubuntu 20.10 system recently installed to install the Python Roon API project (pip install roonapi) and quickly cobbled together a Python script based on one of the examples in that project. The Python script accepts an argument specifying an artist name in my Roon library. It then uses the Roon API to play music from my library by that artist. Currently the zone is hard coded in the Python script.
On my iPhone I then created a couple of shortcuts which use the “Run script over SSH” option for Apple Scripting shortcuts. The shortcuts execute a Bash command which is a shell script that executes the Python script with appropriate arguments. It all seems to work. I did run into a few gotchas. It seems with current Python/Pip installs you need to specify an environment variable telling Python where the Pip modules are located. So I needed a login shell to pick that up but I could not figure out how to tell the Apple shortcut to give me an SSH login shell. The Python env variable is set in the shell script the SSH session executes.
Anyway, I easily overcame these small difficulties and have an initial couple of shortcuts that play Jethro Tull and Pink Floyd triggered by Siri voice commands. I have a lot to learn about the Roon API but it seemed fairly easy to get started. Thanks!
Here’s the details.
Example iOS SSH Shortcut command:
bash -l -c “play_artist ‘Pink Floyd’”
Example play_artist shell script (needs to be in your PATH):
#!/bin/bash
ROON=$HOME/Roon
PLAY=play_artist.py
ARTIST=“Deep Purple”
export PYTHONUSERBASE=/home/doctor/Python3
[ -d $ROON ] || exit 1
cd $ROON
[ -f $PLAY ] || exit 2
[ “$1” ] && ARTIST="$1"
python $PLAY -a “$ARTIST”
Example play_artist.py Python script to call Roon API:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-a", “–artist”, help=“artist selection”)
args = parser.parse_args()
if args.artist:
artist = args.artist
else:
artist = “Jethro Tull”
from roonapi import RoonApi
appinfo = {
“extension_id”: “python_roon_test”,
“display_name”: “Python library for Roon”,
“display_version”: “1.0.0”,
“publisher”: “gregd”,
“email”: “mygreat@emailaddress.com”,
}
server = “xxx.xx.xx.xxx” # Set this to your Roon Core server IP
target_zone = “Living Room” # Set this to the name of the zone you want
# Can be None if you don’t yet have a token
token = open(“mytokenfile”).read()
roonapi = RoonApi(appinfo, token, server)
# get target zone output_id
zones = roonapi.zones
output_id = [
output[“zone_id”]
for output in zones.values()
if output[“display_name”] == target_zone
][0]
print(“OUTPUT ID”, output_id)
# Play artist from Library
print(“SINGLE ARTIST”)
items = roonapi.play_media(output_id, [“Library”, “Artists”, artist])
# save the token for next time
with open(“mytokenfile”, “w”) as f:
f.write(roonapi.token)
That’s it. I hope to improve this over time but for now I’m pretty happy to get something working in my free time on a slow Thursday. Hope the code formats ok, I’m new here and haven’t yet figured out how to format these postings properly. Let me know how I should proceed or if there is an easier way to do the same thing.