switch amplifier on/off when volumio plays or not.

I am building a discrete amplifier which iwamtto combine with a raspi + dac + volumio…

I dont mind letting the pi run 24/7 andcontrol itfrom my smartphone…

But the amplifier i am building is a class A amplifier which iwould like to turn on when start some music and turn off if nothing has been pmayed for like 5 mnutes or so…

Hooking it up to a gpio pin shouldnt be too hard hardware wise but how to control it??

Even a basic on/off button on the user interface would be fine. Sadly i lack the programming skills…

Any ideas and/orsugestions ?

You would need to create a script that looks at the play status, look and see if there is something playing or not. If there is nothing playing you could automatically cut the power to the amp.

ccomino also tried to do this, but i think he bailed that project. See: detect-when-something-streaming-t2056.html

I would also recommend to look at this thread: gpio-pins-control-volume-t2219.html
That thread currently has the best how-to on getting the GPIO’s to work.

Currently there is no way to control the GPIO’s via the web-page, you would DIY this if you want that.

I’ve made the request for user-definable buttons, you would be able to use a button to trigger your personal script. I hope this will be implemented, but i dont have influence on that (not a dev, just a mod :wink: )

Hi there im new to volumio and need some help. I have the same goal as the thread opener, i want to switch my amplifier on and off if an airplay signal comes in. I try to use a counter which counts to 10 and an add +1 to “count” if CPU usage is zero. If the count of “count” is greater than 8 the amp goes to sleep. My goal is to have script which can be used with any application PID such as MPD Squeezplayer Shairport etc. Thanks to johneff from raspberry forum i started with his code and modified it further.

#!/bin/bash

# Standby Script to switch an GPIO if an App is running is Playing.

trap "echo \"17\" >/sys/class/gpio/unexport" EXIT
echo "17" >/sys/class/gpio/export
echo "out" >/sys/class/gpio/gpio17/direction

while  :; do
        counter=0

        for i in $(seq 1 10)
        do
                if ['(top -b -p $(pgrep shairport) -n1 | awk 'FNR==8{print $9}'$
                then counter=$counter+1
        fi
        done
if [ $counter -le 8 ];
        then
        echo "1" >/sys/class/gpio/gpio17/value
        sleep 1
        counter=0
   else
        echo "0" >/sys/class/gpio/gpio17/value
        sleep 1
        counter=0
        fi
done

For the Threadopener http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/scripts there are the necessary details how to make the script. Further you need to install the GPIO RPI Module, just google it yourself…

The script is not working as it should, may someone can help me with this. The GPIO ports are working but not the script itself.

hi,
Some time ago, I did that : https://volumio.org/forum/adding-amplifer-input-selector-from-webui-t3133.html
It works, even if it need to be finished…

Ok i tweaked the script and it is now working for me, now my amplifier is switching on if mpd or shairport receives an audio signal.

[code]#!/bin/bash

Turn GPIO 17 automatic on if Music is Playing on MPD or Shairport

trap “echo “17” >/sys/class/gpio/unexport” EXIT
echo “17” >/sys/class/gpio/export
echo “out” >/sys/class/gpio/gpio17/direction

while :; do
noload=0
pid1=pgrep shairport
pid2=cat /var/run/mpd/pid
for i in $(seq 1 10)
do
load1=top -b -p $pid1 -n1 | awk 'FNR==8{print $9}'
load2=top -b -p $pid2 -n1 | awk 'FNR==8{print $9}'
if [ “$load1” = “0.0” ] && [ “$load2” = “0.0” ] ;
then ((noload++))
fi
done
if (( $noload > 8 ));
then echo “0” >/sys/class/gpio/gpio17/value
sleep 0.001
else echo “1” >/sys/class/gpio/gpio17/value
sleep 0.1
fi
done
[/code]

Hi

I want to create simple daemon that will turn off my active speakers (by relay) if no music is played, thus, i need to check what volumio is doing.
How to check if music is currently played or user acts with volumio ? any way by tcp socket, shared mem, named pipes, any other interproc communication ?

how is volumio using mpd ? is mpd working all the time? or maybe run only during actual playback/decoding ?
is it just enough to check if mpd daemon is working ?

Search the forum for “expect” in posts from me.
I did it already.