[Plugin] GPIO Buttons: Control Volumio 2/ Volumio 3 with buttons

Hello friends
play/pause works great with a button, but I need it to work with a switch (ON - Play, OFF - Pause) Does anyone know how to do this?

I would strongly advise against it. Adding a permanent switch means your pulling a GPIO up or down continuously. Which will end up in defects. (PMIC)

I have been using a switch connected in this way for a long time to turn off my raspberry and have not had any problems. I only use GPIO 26

then you could try something like this. PREV is added to hold the button state and avoid that the code keeps being executed. (code is not tested)

#!/bin/bash
# select pin GND - D0
GPIO0=26
# Print debug lines => 1 is print
debug=1
PREV=0
# Common path for all GPIO access
BASE_GPIO_PATH=/sys/class/gpio

# Utility function to export a pin if not already exported
exportPin()
{
  if [ ! -e $BASE_GPIO_PATH/gpio$1 ]; then
    echo "$1" > $BASE_GPIO_PATH/export
  fi
}

# Utility function to set a pin as an output
setInput()
{
  echo "in" > $BASE_GPIO_PATH/gpio$1/direction
}

exportPin $GPIO0
setInput $GPIO0


# If debug == 1
if [ $debug == 1 ]; then
  echo "---------------------------------------------------"
  printf "GPIO 0: %s\n"  "${GPIO0}"
  printf "STATUS 0: %s\n"  "${STATUS0}"
fi

# continuously monitor current value
while true; do
  sleep 1s
  STATUS0=$(cat $BASE_GPIO_PATH/gpio${GPIO0}/value)
  
  if [ $debug == 1 ]; then
  echo "---------------------------------------------------"
    printf "STATUS 0: %s\n"  "${STATUS0}"
    printf "PREV: %s\n"  "${PREV}"
  fi
  
  if [ "$STATUS0" == 1 ] && [ "$PREV" == 0 ]; then
	#Write here the code what needs to be done:

        PREV=1
  elif [ "$STATUS0" == 0 ] && [ "$PREV" == 1 ]; then
	#Write here the code what needs to be done:

       PREV=0

  fi 

done

when I run the script I get an error

GPIO 0: 26

STATUS 0:

play.sh: line 47: syntax error near unexpected token `do’

play.sh: line 47: ` do something.'Preformatted text

Yeah, that’s is the part where you write the code what the button needs to do…
like:

volumio play
volumio stop
volumio pause
volumio toggle
  if [ "$STATUS0" == 1 ] && [ "$PREV" == 0 ]; then
	volumio play
	PREV=1
  elif [ "$STATUS0" == 0 ] && [ "$PREV" == 1 ]; then
	volumio stop
	PREV=0
  fi