I’m running the Roon core on a Debian headless server. Is there an easy way to detect Roon’s current playback status (i.e. playing or idle) using bash?
There’s an easy way tailing the Roon server log file, but that won’t simply return a status and I am not sure what your purpose is and if this will be well enough for you:
tail -f /var/roon/RoonServer/Logs/RoonServer_log.txt
You could take a look at GitHub - doctorfree/RoonCommandLine: The Roon Command Line project provides Bash and Python scripts to enable command line control of the Roon audio system over a local network.
@Ronald_Record created and maintains it.
Thanks Andreas & Greg! A bash script that exists with status 0 if an audio zone is active (i.e. playing music) would be a good start.
I think that would imply making use of Roon API, and maybe RoonCommandLine as proposed by @GregD will give you what you need. I haven’t checked it out.
Depending on what exactly you have in mind, maybe the following could help.
You can extract an ALSA device’s stream status from…
/proc/asound/x/pcmyp/subz/status
… with the nomenclature depending on installed devices.
If not already streaming via an ALSA device on the core, you can set up a loopback device on startup in \etc\rc.local via following line before the exit 0 line …
#!/bin/sh -e
#rc.local
#This script is executed at the end of each multiuser runlevel.
#Make sure that the script will “exit 0” on success or any other
#value on error.
#In order to enable or disable this script just change the execution
#bits.
#By default this script does nothing.
#Print the IP address
_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” “$_IP”
fi
sudo modprobe snd-aloop
exit 0
… to add as an audio zone and then group with your actual RAAT zone you want to monitor.
Then adapt following executable script to extract stream status and effect whatever you need.
I use this for my roon-dynamic-range-metering-bridge to keep the RPi screen on during play and to turn it off on stop:
#!/bin/bash
DIR=‘/proc/asound/Loopback/pcm1p/sub0/status’
monitoron=‘xset -d :0 dpms 2 2 2’
monitoroff=‘xset -d :0 dpms 1 1 1’
while :
do
content=cat $DIR
if [[ “$content” != ‘closed’ ]]; then
$monitoron
else [[ “$content” = ‘closed’ ]]
$monitoroff
fi
sleep 1
done
Might be a little clumsy, but hope that helps, and you might want to show us what you’re up to!
Recent releases of RoonCommandLine include support for “now playing” but not exactly what you want.
A command like:
roon -n -z Kitchen
Will return the now playing status of Roon zone “Kitchen”. But if nothing is playing in that zone it just returns with no output and exit status 0. If something is playing it returns info on that track, artist, etc and exit status 0. So, the exit status is always 0. I could fix that.
Here is the output right now of roon -n -z "HomePod Max"
in my “HomePod Max” Roon zone:
Now playing in zone: HomePod Max
Track: "Bare Bones"
Artist: "Tyler Bryant & The Shakedown"
Album: "Shake the Roots"
State: playing
You could wrap a command like this in a Bash script:
playing=$(roon -n -z Kitchen)
if [ "${playing}" ]
then
exit 0
else
exit 1
fi
Thanks Marin! I’ll give it a shot. I’m not up to anything too exciting, just trying not to waste energy by putting my server into suspend mode unless it is actively used by roon or some other service. I wake up the headless server using HomeKit via homebridge running on a low Wattage ARM SBC. Prefereably Roon would support WakeOnLAN, but it appears this is a request brought up before and ignored by the developers, which is a pitty.
Thanks Ronald! That’s very helpful indeed! Does your tool allow to show all currently available zones as well? Of course I can adjust your script for multiple zones, but I am wondering about “on the fly” created groups.
@Thomas_Mettler yes, you can query all zones by not specifying any zone on the command line. There are two modes.
Query all zones and report only those playing:
roon -n
Query all zones and report track, artist, etc info as well as state (e.g. paused, playing, stopped):
roon -N
Great! Thanks!