Roon Command Line Control version 2

Excellent. Good sleuthing. Thanks for bringing this to my attention and please continue to report problems/issues/weirdisms either here or in the Gitlab repo issues. It helps me to understand all the things that may go wrong in various user scenarios. I have 4 systems on which I test - a Mac Pro, Ubuntu Linux, Fedora Linux, and Raspbian on a Raspberry Pi. These provide a pretty good, maybe just ok, testing bed but do not nearly cover what should be tested. I appreciate your contribution to this projectā€™s development.

@Etk I didnā€™t mean to ignore your issue with running a Roon command in a Shortcut. I got a bit sidetracked by running down the delay. Anyway, the delay is fixed so that was a good sidetrack and I would like to return to the Shortcut issue you have. Honestly, Iā€™m about out of educated guesses.

I recently created an article detailing voice control of Roon using Siri and Apple Shortcuts. This article includes some references to articles on setting up Shortcuts. Both the article and its references may be useful. The article is in the RoonCommandLine Wiki at Roon Voice Commands with Siri. Itā€™s still a work in progress so let me know how it can be improved.

1 Like

Excellent, thanks Ron. Iā€™ll have a look and see what I can get to work. And donā€™t worry - Iā€™ve been mad busy so not bad a minute to work on it myself!

Just FYI: when calling the python script directly, things work just fine in a Shortcut:

python3 /usr/local/Roon/api/zone_command.py -c playpause -z "HQP4 Dylan" >> works

/usr/local/Roon/bin/roon -c playpause -z "HQP4 Dylan" >> fails

Iā€™m seeing the same thing, if I run the equivalent ssh user@host:port /usr/local/Roon/bin/roon -c playpause -z desk from the command line as the shortcut is doing, I get these errors:

/usr/local/Roon/bin/roon: line 738: set_zone: command not found
/usr/local/Roon/bin/roon: line 871: zone_command: command not found

so it seems that the $PATH isnā€™t set right when directly running a command through ssh or via the shortcut, if I change the shortcut script to set the path, i.e. PATH=$PATH:/usr/local/Roon/bin /usr/local/bin/roon -c playpause -z desk it will run successfully.

Maybe the roon command could be changed to use the full path ($ROON/bin/<command>) when executing sub-commands when $LOCAL=true?

Iā€™m also using zsh, so maybe this doesnā€™t happen if your login shell is bash (however, the proposed fix above should work fine for both shells).

Thanks for catching this error @Scott_Jann

I will add a PATH setting to the roon command. The RoonCommandLine commands should all be linked in /usr/local/bin during installation. They should be found in the userā€™s PATH if that includes /usr/local/bin. Does your initial PATH setting in zsh include /usr/local/bin ?

Regardless, itā€™s a good idea and an oversight on my part not to have verified that /usr/local/bin is in the PATH environment variable and, if not, added it in the roon command. I believe this should be sufficient although I could add /usr/local/Roon/bin instead.

Good debugging. This was starting to irritate the back of my mind.

An updated release of RoonCommandLine with fixes for the PATH issue along with SSH invocation improvements and installation script version detection can be found at RoonCommandLine Version 2.0.3 Release 1

Hi @Ronald_Record , Unfortunately I seem to be going backwards now!

I canā€™t get the Roon Command Line to work at all any more, have tried updating to 2.0.3 but the clone command brings in the 2.0.3 repository but Iā€™m still being asked whether to install 2.0.2

When I try the install various things seem to fail:

patching file site-packages/roonapi/roonapi.py
Hunk #1 FAILED at 398.
Hunk #2 FAILED at 527.
Hunk #3 FAILED at 723.
Hunk #4 FAILED at 736.
Hunk #5 FAILED at 746.
5 out of 5 hunks FAILED -- saving rejects to file site-packages/roonapi/roonapi.py.rej

and then:

RoonCorePort = 9330
Traceback (most recent call last):
  File "/usr/local/Roon/api/get_core_ip.py", line 36, in <module>
    with open(tokenfile, "w") as f:
PermissionError: [Errno 13] Permission denied: '/usr/local/Roon/etc/roontoken.txt'
Traceback (most recent call last):
  File "/usr/local/Roon/api/list_zones.py", line 111, in <module>
    with open(tokenfile, "w") as f:
PermissionError: [Errno 13] Permission denied: '/usr/local/Roon/etc/roontoken.txt'

Iā€™m really not sure what Iā€™m doing wrong now but I seem to be getting further away! Any ideas??

@Etk Thanks for bringing this to my attention. There appear to be a couple of things wrong. One issue is the Mac install script needs to be updated to know whether to patch the roonapi Python package. I updated the Debian and RPM installation scripts earlier but did not update the Mac install script. I will do so today and let you know when it is tested and ready. It should not take much time.

The other problem may be related to the installation patch failure. It appears that permissions did not get set properly in /usr/local/Roon/etc/ The files in that folder should be writeable by the user set as the Roon user during the installation. This permission problem probably goes away when I resolve the installation problem.

Give me a little time and I will get back to you with the fix(es).

@Etk I committed the changes to the macInstall script after testing. My recommendation would be to Uninstall any existing RoonCommandLine package as well as the roonapi Python module then reinstall both. To do so:

Pull the latest changes from the RoonCommandLine repo

In a terminal window, change directory to where you cloned RoonCommandLine

cd .../RoonCommandLine
git pull

Uninstall any RoonCommandLine previous install

./Uninstall

Uninstall any previously installed roonapi Python module

sudo python -m pip uninstall roonapi

Install RoonCommandLine

./Install

Let me know if you run into any problems.

NOTE: The current RoonCommandLine repo includes many changes and improvements that have not yet been released. You are getting a development snapshot. Itā€™s pretty well tested, just not ready for release yet as I have to add man pages and other doc while finishing up with testing. There are many new commands and features. Enjoy the preview!

1 Like

thanks again for taking all this time and effort!

So I ran the pull which seemed to work, updating the files.

It took a couple of goes to make this work - does the git pull command have to be run sequentially until we get the most up to date versions?

One Q though, when I come to reinstall I still get asked about v 2.0.2:

rooncommandline % ./Install
Install RoonCommandLine version 2.0.2 ? ('Y'/'N'): y

This seems to work though - the commands are lightning fast now!

Iā€™ll keep on trying with the rest of the config around shortcuts and report back

Curiouser and curiouserā€¦

so I can run the commands from terminal again, that works perfectly and is nice and quick

when I try and call the command from shortcuts, it does some odd things:

  • If I just use the playpause command nothing happens
  • If I add which zone I want to apply this to (eg -z Brooklyn) then it gives the following error:

If I try running the full command suggested above (ie sticking python3 before the path/command I get the following:

% python3 /usr/local/bin/roon -c playpause -z Brooklyn
  File "/usr/local/bin/roon", line 24
    artist=
           ^
SyntaxError: invalid syntax

Am I making a mess of this somehow? Like maybe trying to run two different versions here??

Running the shortcut to list zones looks like this:

@Etk looks like some progress and some more issues. Thanks for hanging in there. I think I can help resolve a couple of things quickly and we can tackle the others after getting you setup properly. First, the issue with the version mismatch seems to indicate you do not yet have the current RoonCommandLine repository. That is, your git pull did not seem to retrieve the repo correctly. This can be caused by a number of things, often a pull fails due to modifications on the receiving end. I suggest you re-clone the repository. To do this:

Change directory to your src directory, backup, and clone

cd $HOME/src
mv RoonCommandLine RoonCommandLine.bak
git clone https://gitlab.com/doctorfree/RoonCommandLine.git

If you are able to successfully clone the RoonCommandLine project, then change directory into RoonCommandLine, Uninstall your previous installation, and reinstall:

Uninstall any RoonCommandLine previous install

cd $HOME/src/RoonCommandLine
./Uninstall

Uninstall any previously installed roonapi Python module (maybe not necessary)

sudo python -m pip uninstall roonapi

Install RoonCommandLine

./Install

This should display version 2.0.3 at the Install prompt. If it does not, what does the contents of the file VERSION say?

If all goes well that should solve your version mismatch problem. The other thing I can help correct right away is the direct command line invocation of a RoonCommandLine script via Python. You are attempting to execute the /usr/local/bin/roon script using Python but roon is a Bash shell script. Normal use would be to simply invoke roon ... from a shell or via SSH. The roon shell script figures out what you want to do and ends up running a Python script to communicate with the Roon Core.

So, to bypass roon and run the Python script directly you need to know which script to run and how to invoke it. In the example you provide above you are trying to run the ā€˜playpauseā€™ command in the ā€˜Brooklynā€™ zone. To do this with Python, execute the command:

python3 /usr/local/Roon/api/zone_command.py -c playpause -z Brooklyn

All of the Python scripts in /usr/local/Roon/api/ have usage messages to help get their arguments right. Any of them can be invoked with the -h argument to display the usage message. For example, to see what arguments the play_album.py Python script accepts, run:

python /usr/local/Roon/api/play_album.py -h

Once you have reinstalled, have the right version installed, and can execute Python scripts directly, letā€™s tackle the Shortcut issues. It looks like your Shortcut is executing but the zone listing is only showing the portion from the shell script and not the output from the Python script. Which would maybe explain why it thinks ā€˜Brooklynā€™ is not a valid zone. Or, maybe you need to modify the RoonCommandLine configuration files /usr/local/Roon/etc/pyroonconf and /usr/local/Roon/etc/roon_api.ini. We can take a look when you are cleanly setup.

Also, this is good for me to learn the stumbling blocks getting setup. It helps me to improve the project and make it more user friendly. I hope it is not too frustrating for you ā€” ā€œWhy does he keep asking me to reinstall? What is wrong with this guy?ā€ :slight_smile:

1 Like

Perfect! Iā€™ll get on it when I get home later. Donā€™t worry about me persevering - I like stuff like this and want the functionality back that Bluesound robbed me of!

Thank you for the time and effort making this work :slight_smile:

Right, weā€™re getting somewhere!

Iā€™ve removed the old directory and done a clean install as per your instructions. All went well and now Iā€™m definitely on 2.0.3 with the latest RoonAPI version.

direct terminal commands work fine, so does accessing the python scripts themselves. shortcuts are still throwing up that same problemā€¦

Something Iā€™ve noticed is that if I want to use the python command to run a script, I have to type python3 - could that have anything to do with it???

@Etk progress is good. If I understand you correctly, you can successfully run the command /usr/local/bin/roon -c playpause -z Brooklyn in a terminal on the system where RoonCommandLine is installed. But the same command in an SSH Shortcut returns ā€œNo zone matching Brooklynā€. Is that the situation?

How does the Shortcut behave if you replace

/usr/local/bin/roon -c playpause -z Brooklyn

with

python3 /usr/local/Roon/api/zone_command.py -c playpause -z Brooklyn

Another user has reported his Shortcut fails when using the roon command but succeeds when invoking the Python script directly. I have not yet figured out why this would be so but it is worth a try and may give us further clues.

The RoonCommandLine commands should work on a system with both Python 2 and Python 3 installed. The scripts all check if python3 is in your PATH and if so they use it rather than python. Make sure python3 is in your userā€™s PATH. To verify this, in a terminal window logged in as that user run the command type python3.

Another area to examine are the two RoonCommandLine configuration files:

/usr/local/Roon/etc/pyroonconf

and

/usr/local/Roon/etc/roon_api.ini

In a terminal window, what does the command roon -l zones return? Is the Brooklyn zone listed in one of the Zones returned by that command?

Ok so here we go, if I replace the roon command with the python3 call I get the following error:

If I replace it with just a python command I get the following (and I didnā€™t expect this to work as I get the same error if I donā€™t use python3 in terminal):

When I do type python3 I get python3 is /usr/bin/python3

roon -l zones 

gives me the list of zones including Brooklyn so that seems strange - also it works happily locally so not sure why it canā€™t find the zone when called remotely

@Etk Thatā€™s a clue. First, it is expected that Python 2 would not find the configparser module as it was named configParser in Python 2. So we can ignore that. But Python 3 is not finding the roonapi module and that is probably the source of the problem. If I understand you correctly, when executing the zone_command.py Python script in a terminal window logged in as your Roon user, it succeds BUT the same command when executed in an SSH Shortcut fails with this roonapi module not found error. Correct?

If that is so, I suspect there is something about being logged in that alters where Python 3 is looking for modules. Where is the roonapi module installed ? You can find out where the roonapi module is installed by running the command:

pip show roonapi

Or, in your case since you appear to have Python 2 as your default Python and Python 3 also installed, try:

pip3 show roonapi

Which leads me to guess that either roonapi got installed in Python 2 module packages OR it got installed in a Python user directory. Anyway, if you can get me the location of your roonapi module I may be able to finally track this down.

Thanks!

thatā€™s right, exactly.

hereā€™s the output of pip3 show roonapi:

Name: roonapi
Version: 0.1.1
Summary: Provides a python interface to interact with Roon
Home-page: https://github.com/pavoni/pyroon
Author: Marcel van der Veldt
Author-email: 
License: Apache-2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: ifaddr, requests, six, websocket_client
Required-by: 

Does that help at all?

Your pip3 show roonapi command indicates the roonapi Python module is installed correctly so that did not give us any further clues. If you run the same command, pip3 show roonapi in your Shortcut, what does it return?

Another approach would be to run your Shortcut commands in a login shell. You can do this by prefacing the command you wish to run with bash -l -c ...

For example, to run the Python command python3 /usr/local/Roon/api/zone_command ... in a login shell, configure the Shortcut command to be something like:

bash -l -c "python3 /usr/local/Roon/api/zone_command.py -c playpause -z Brooklyn"

This can get tricky as sometimes when adding quotes to the command, you need to escape the quote so it gets passed through correctly. But start with the above SSH command in your Shortcut and see what that returns. The idea here is that one difference between running the command in a terminal window and running it over SSH is the terminal window is executing in a login shell which sets up additional stuff in your environment.

Another guess as to why you are seeing different behavior in the Shortcut than in a terminal window would be your Shortcut is misconfigured and you are running the command on a different system in the Shortcut than in a terminal window. To verify your Shortcut is correctly configured, get the username and IP address in the terminal window on your Mac:

This will give you the username to use in your Shortcut
id -u -n

This will give you the IP address to use in the Shortcut
ipconfig getifaddr en0

Edit the Shortcut on your iOS device and verify the user and host settings match those from your terminal window. This is probably not the problem, I expect you have these configured properly, this is just verifying that.

I have not yet been able to replicate this issue in my environment. You are not the only person to report this. Thanks for your assistance.