Closed cre8dojo closed 8 years ago
Also, can we specific a variable in the run_this parameters to be able to pass connection info? e.g.
run_this_before_play_begins = "/usr/bin/shairport_sync_script.sh before $X-Apple-Client-Name"
So I can pass the action 'before' and the name of the source device connected?
play_begins/ends are triggered on connect/disconnect (but normally client disconnects after abouts 3s after pause).
Actual status of chosen shairport-sync instance could be saved somwhere (in a file maybe?) using play_begins/ends scripts.
And You can get connection info using https://github.com/mikebrady/shairport-sync-metadata-reader althought metadata format seems to be a bit unreliable. So connection info in before/after scripts as variables looks like a nice idea.
Thank you! I'll take a look at metadata-reader. And I implemented your suggestion for keeping track with files:
run_this_before_play_begins = "/usr/bin/shairport_before_after.sh before HW1_Stereo"; run_this_after_play_ends = "/usr/bin/shairport_before_after.sh after HW1_Stereo";
shairport_before_after.sh: (simplified because I have both amps on one relay for now)
'#!/bin/bash
logfile=/tmp/test_shair.log gpioDir=/sys/class/gpio inUseFile=/tmp/amp_inuse
echo $1 >> ${logfile} echo $2 >> ${logfile}
pwd
>> ${logfile}amp1="HW2_Stereo HW2_Left HW2_Right" amp2="HW1_Stereo HW1_Left HW1_Right"
if [ ! -d /sys/class/gpio/gpio2 ]
then
echo "need to export pin" >> ${logfile}
echo 2 > ${gpioDir}/export
while [ ! -f ${gpioDir}/gpio2/direction ]
do
echo "sleep until pin exported" >> ${logfile}
sleep 0.1
done
while [[ ! ls -l ${gpioDir}/gpio2/direction
=~ "root gpio" ]]
do
echo "sleep until permissions set on pin" >> ${logfile}
sleep 0.5
done
echo "setting direction of pin" >> ${logfile}
echo out > ${gpioDir}/gpio2/direction
fi
if [ ${1} == "before" ] then
touch ${inUseFile}$2
echo "turning amp on" >> ${logfile}
echo 0 > ${gpioDir}/gpio2/value
elif [ ${1} == "after" ] then
if [ -f ${inUseFile}$2 ]; then rm -f ${inUseFile}$2; fi
sleep 10
if [ `ls -l ${inUseFile}* | wc -l` == 0 ]
then
echo "turning amp off" >> ${logfile}
echo 1 > ${gpioDir}/gpio2/value
fi
fi echo '------------------' >> ${logfile} echo '' >> ${logfile} echo '' >> ${logfile}
Thanks again for this wonderful project!
Hi there. I'm closing this issue, if that's okay. Please feel free to reopen it if there are any developments.
Also wanted to turn off my 6 zone amp only when no streams were running, this worked for me. It checks if a shairport instance is running one of the top 3 cpu loads and if so runs my expect script. Depending on what you have running on your system you might need to increase the 3 to something higher. In my case shairport always has the highest cpu load when receiving a stream (approx 10% cpu on RASPI 3) otherwise all instances are idle.
echo "Standby script ran at $(date)" >> /etc/Denon_on_off.txt sleep 40s if top -b -n 1 | head | grep -A 3 PID | grep shairport > /dev/null
then echo "shairport running will turn NOT off AMP power" >> /etc/Denon_on_off.txt else echo "shairport NOT running will turn off AMP power" >> /etc/Denon_on_off.txt expect -d /etc/Denon_standby.exp echo "Denon turned to Standby at $(date)" >> /etc/Denon_on_off.txt fi
Thank you! Works perfectly! Incorporated it so Librespot also uses this script to determine whether it should turn off the amp or not. Great!
I have several instances running on startup of my raspberry pi:
`pi@raspberrypi:/sys/class/gpio/gpio3 $ ps ax | grep shair 453 ? Ssl 0:00 /usr/local/bin/shairport-sync -c /etc/shairport-syncZone_HW2_Right.conf 455 ? Ssl 0:00 /usr/local/bin/shairport-sync -c /etc/shairport-syncZone_HW2.conf 456 ? Ssl 0:00 /usr/local/bin/shairport-sync -c /etc/shairport-syncZone_HW1_Left.conf 460 ? Ssl 0:00 /usr/local/bin/shairport-sync -c /etc/shairport-syncZone_HW0.conf 461 ? Ssl 0:00 /usr/local/bin/shairport-sync -c /etc/shairport-syncZone_HW2_Left.conf 465 ? Ssl 0:00 /usr/local/bin/shairport-sync -c /etc/shairport-syncZone_HW1_Right.conf 3551 pts/0 S+ 0:00 grep --color=auto shair
pi@raspberrypi:/sys/class/gpio/gpio3 $ systemctl |grep Zone shairport-sync@Zone_HW0.service - loaded active running ShairportSync AirTunes receiver Zone_HW0 shairport-sync@Zone_HW1_Left.service - loaded active running ShairportSync AirTunes receiver Zone_HW1_Left shairport-sync@Zone_HW1_Right.service - loaded active running ShairportSync AirTunes receiver Zone_HW1_Right shairport-sync@Zone_HW2.service - loaded active running ShairportSync AirTunes receiver Zone_HW2 shairport-sync@Zone_HW2_Left.service - loaded active running ShairportSync AirTunes receiver Zone_HW2_Left shairport-sync@Zone_HW2_Right.service - loaded active running ShairportSync AirTunes receiver Zone_HW2_Right`
I want to start using the run_this_before_play_begins and run_this_after_play_ends parameters in the conf files to turn amps on/off when needed. I need to check status of specific shairport-sync instances to determine if/when to switch amps on/off in the case where instances share an amp.
How can I determine from a script that instanceB of shairport-sync is active/connected/playing when user stops playing via instanceA?
Also, are these parameters for when a users plays/stops/pauses or connects/disconnects?
Thanks, Rey