is it possible to run a command instantly whenever volumio plays something or even pauses/stops playing something?
Like I am looking at running a command (for e.g. stop blinking led) that instantly would trigger whenever volumio plays and stops/pauses.
Thanks!
EDIT: More clarification:
I want to control two different gpio pins (these two pins will be set as OUTPUT) through volumio. Whenever I press play or is playing a song on volumio, I want a led (wired into the gpio) to turn on and whenever its not playing (either stopped or paused) - it turns off.
I want to control two different gpio pins (these two pins will be set as OUTPUT) through volumio. Whenever I press play or is playing a song on volumio, I want a led (wired into the gpio) to turn on and whenever its not playing (either stopped or paused) - it turns off.
You can use python to monitor the output (better use a websocket, as volumio already send a communication on play/stop/… )
This is untested, so please modify to your needs:
import os
import subprocess
import json
from time import sleep
import RPi.GPIO as GPIO
# Which GPIO
led =23
GPIO.setmode(GPIO.BCM)
GPIO.setup(led,GPIO.OUT)
while True:
process = subprocess.Popen("volumio status".split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
pythonObj = json.loads(output)
status = pythonObj['status']
if (status == "play") :
# Execute code for play
GPIO.output(led,GPIO.HIGH)
if (status == "stop") :
# Execute code for stop
GPIO.output(led,GPIO.LOW)
sleep(2)
I have installed volumio 2 - just so I could access the older plugins.
I got my fingers dipped into the GPIO control plugin, however, it turns out I need to essentially turn a GPIO pin high and then low with a delay of 1 second in between. I am trying to simulate a button press…
Example:
I click play on song
GPIO Control turns GPIO pin 10 high
delay 1 second
GPIO Control turns GPIO pin 10 low
Check out the ampswitch plugin, I added a delay function to it a while back…
But it would seem what you seek is a toggle function, this is also included via a pulse for latching relays.
import os
import subprocess
import json
from time import sleep
import RPi.GPIO as GPIO
# Which GPIO
leda =23
ledb =24
# Set active state to avoid loop
playing = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(leda,GPIO.OUT)
GPIO.setup(ledb,GPIO.OUT)
while True:
process = subprocess.Popen("volumio status".split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
pythonObj = json.loads(output)
status = pythonObj['status']
if ((status == "play") and (playing == 0)) :
# Execute code for play
GPIO.output(leda,GPIO.HIGH)
sleep(1)
GPIO.output(leda,GPIO.LOW)
playing = 1
if ((status == "stop") and (playing == 1)) :
# Execute code for stop
GPIO.output(ledb,GPIO.HIGH)
sleep(1)
GPIO.output(ledb,GPIO.LOW)
playing = 0
sleep(0.3) # To avoid CPU overload
import os
import subprocess
import json
from time import sleep
import RPi.GPIO as GPIO
# Which GPIO
leda =24
ledb =23
# Set active state to avoid loop
playing = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(leda,GPIO.OUT)
GPIO.setup(ledb,GPIO.OUT)
while True:
process = subprocess.Popen("volumio status".split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
pythonObj = json.loads(output)
status = pythonObj['status']
if ((status == "play") and (playing == 0)) :
# Execute code for play
GPIO.output(leda,GPIO.HIGH)
sleep(1)
GPIO.output(leda,GPIO.LOW)
playing = 1
if ((status == "stop") or (status == "pause") and (playing == 1)) :
# Execute code for stop
GPIO.output(ledb,GPIO.HIGH)
sleep(0.5)
GPIO.output(ledb,GPIO.LOW)
playing = 0
sleep(0.3) # To avoid CPU overload
This worked brilliantly, thanks!
I slightly modified it to include the “pause” status however, I was wondering if there is a way to add like a type of delay in which the script sees the “pause” status in volumio then waits five seconds just to see if the status changes and if it doesnt - it blinks the led but if it does, nothing happens.
something like:
if ((status == "stop") or (status == "pause" for 5 seconds) and (playing == 1)) :
....