Amplifier switch with Logitech media server

Hi all, I have a raspberry pi 3b+ with Justboom amp. I use Amplifier switch plugin that work very well with Volumio to turn on/off the amplifier with raspberry gpio.
I also use Saiyato’s plugin Squeezlite player and Logitech media server for multiroom purpose and it works very well (in the squeezlite player in extra parameters I put -C 3 so I avoid Alsa errors)
I want to thanks the plugins creators. The Plugins are awesome but I find a little problem mixing these two plugins. The amplifier switch works only with Volumio so when I play something with logitech media server the amplifier don’t turn on/off.
I want to share a script I made to solve this problem, maybe it’s not perfect but it woks well for me

The script works with expect and telnet so you have to install it

sudo apt-get update sudo apt-get install expect sudo apt-get install telnet

To start the script on boot you can put it in the /etc/rc.local file something like this
/home/volumio/Script/Ampli.sh “192.168.1.21” &
(where 192.168.1.21 is the IP address of logitech media server and Ampli.sh is the following script)

This is the script, to lauch it you have to pass the Logitech media server’s IP as parameter. Put the script and make it executable in your device. SSH must be enable to change GPIO pin. You have to change SSH password in the script (set justboom_psw “ssh_password”)

#!/usr/bin/env expect


set ip_server [lindex $argv 0]
#### Uncomment if you want to put mac-address manually, you have to change ":" in mac-address to "%3A"
#### set mac "b8%3A27%3Aeb%3Aba%3A40%3Ac1" 
set justboom_usr "volumio"
set justboom_ip "127.0.0.1"
set justboom_psw "ssh_password"
set prompt "\\$ "

spawn ssh  -o "StrictHostKeyChecking no" $justboom_usr@$justboom_ip
set sshID $spawn_id
expect -i $sshID "assword:"
send -i $sshID "$justboom_psw\r"
expect -i $sshID $prompt

##### Get mac-address' Raspberry. Comment if you want to put mac address manually
send  -i $sshID "ifconfig -a | grep eth0 | awk -F' ' 'NR==1{ print \$5 }' | awk -F':' 'NR==1{ print \$1 \"%3A\" \$2 \"%3A\" \$3 \"%3A\" \$4 \"%3A\" \$5 \"%3A\" \$6}'\r "
#send  -i $sshID "ifconfig -a\r"
expect -i $sshID $prompt
set resp $expect_out(buffer)
set mac [split $resp "\r"]
set mac [lindex $mac end-1]
set mac [string trim $mac "\n"]
puts "===>$mac<==="
#####


while true {
spawn telnet $ip_server 9090
set telnetID $spawn_id
 
set timeout 60; # 1 min.

send -i $telnetID "listen 1\r"

expect {
  "listen 1" {
    send_user "Telnet on server done\r"
    break
  }
  timeout {sleep 5;}
  eof {sleep 5;}
  -re "refuse" {sleep 5;}
 }
}

# -----------------------------------------------------------------------------
# tolgo il timeout
set timeout -1
send_user "Wait for play\r"
set prova ""
while true {

expect {
   -re "\n.*pause 1|\n.*stop" {
# Pause could come from another player. I must check if it is grouped with the one connected to amplifier. I get mac-address
    set resp $expect_out(0,string)
    set mac_pausa [split $resp "\r"]
    set mac_pausa [lindex $mac_pausa end]
    set mac_pausa [string trim $mac_pausa "\n"]
    set mac_pausa [string range $mac_pausa 0 26]
    
    puts "\n-->$mac_pausa<--"  
    send -i $telnetID "$mac_pausa sync \?\r"
    expect "$mac_pausa sync"
    set timeout 1
    expect {
           "$mac" {
# modify it is another GPIO command
                   send  -i $sshID "gpio write 3 0\r"
                   expect -i $sshID $prompt
                   puts "Mute"
                  }
            timeout {
                     puts "Do nothing"
                    }
           }
     set timeout -1
  }

   -re "\n.*pause 0|\n.*play " { 
# Play could come from another player. I must check if it is grouped with the one connected to amplifier, so I get mac-address
    set resp $expect_out(0,string)
    set mac_pausa [split $resp "\r"]
    set mac_pausa [lindex $mac_pausa end]
    set mac_pausa [string trim $mac_pausa "\n"]
    set mac_pausa [string range $mac_pausa 0 26]
    puts "\n-->$mac_pausa<--"  
    send -i $telnetID "$mac_pausa sync \?\r"
    expect "$mac_pausa sync"
    set timeout 1
    expect {
           "$mac" {
# modify it is another GPIO command
                   send  -i $sshID "gpio write 3 1\r"
                   expect -i $sshID $prompt
                   puts "Unmute" 
                  }
            timeout {
                     puts "Do nothing"
                    }
           }
     set timeout -1
  }
 }
}

Basically the script telnet to Logitech media server’s IP and check command line output. If play or pause is pressed it modify locally gpio pin, it works also if play/pause is pressed from a player that is grouped with it.
You can also monitor logitech media server from a device and change GPIO pin value to another device (change IP 127.0.0.1)
I hope that this could help someone, sorry for explanation…maybe too complicated :unamused: :unamused: