Keyboard shortcuts with triggerhappy

I wasn’t able to easily found a solution for sending terminal commands/control Volumio with keyboard. Most of the solutions that you will find will always require you to run a Gui. And since you shouldn’t need one to run with Volumio I come up with this simple solution.

Long history short about my project:
Since among other things I have 17 buttons and 5 rotary encoders I had to do something different to avoid lacking GPIO pins. So I’ve connected everything to an Adafruit Pro Trinket. The code on the Trinket will detect button press or rotary encoder rotation and will send the correspondent keypress to Pi via the USB connection. The Pi will receive the keypress as a normal Keyboard input and will run the triggerhappy command for that key.

Later on I can make a post with all the information about this solution, but right now and since I didn’t find any tutorial I just want to share how to use your keyboard to play, pause, mute, etc on your volumio build.

Now the solution!

First we need to install triggerhappy:

sudo apt-get install triggerhappy

Then we need to assign terminal commands to keys. We do that by editing triggerhappy config file:

sudo nano /etc/triggerhappy/triggers.d/audio.conf

This is just an example of a config file with some possibilites:

KEY_VOLUMEUP 0 mpc volume +1 KEY_VOLUMEDOWN 0 mpc volume -1 KEY_MIN_INTERESTING 0 mpc volume 0 KEY_PLAYPAUSE 0 mpc play KEY_STOPCD 0 volumio stop KEY_F1 0 mpc clear; mpc add; mpc play KEY_F2 0 mpc clear; mpc add; mpc play KEY_F3 0 mpc clear; mpc add mms://; mpc play KEY_F4 0 mpc clear; mpc add mmsh://; mpc play

Every line of the config file should have three parameters:

KEY_CODE: The code for the key
WHEN: 1 -> pressing a key | 2 -> holding a key | 0 -> releasing a key

Last thing to do is to reload the config file:

sudo /etc/init.d/triggerhappy reload

To check if the config file is ok we should run:

sudo /etc/init.d/triggerhappy status -l

You can see which code represent every key by running the following command:

sudo thd --dump /dev/input/event0

More information about triggerhappy can be found on the github page:

PS: This was only tested with the last build of Volumio. As long as you can install triggerhappy it should work with every build.

1 Like

Is there any bug/issue with Volumio command line?
“volumio stop” it’s working fine.

But when I send “volumio play” nothing happens.
There’s a “Sending play” message but terminal blocks there and nothing happens. Music keeps playing and I need to send Ctrl+C to get terminate.

I know that I can control the player with “mpc” commands but if I do it this way the Web and the iPhone app won’t receive the status change and controls won’t match the current status.

I also try it with urls (?cmd=play) but apparently this was removed from 2.0

Also, I can’t find more info about the Volumio command line tool. Only what’s in the --help.
Is there a way to increment the volume instead of setting it to a certain level?
I would love to send +1 and -1 with the knob cause I’m doing it with mpc and that way clients won’t receive the volume update.

the official documentation is here: … ine_Client

However, there are not that many commands to play with.
As you noticed, start/stop is broken - but not just in the CLI but also other ways. Volumio’s play state is somehow messed up, especially when web streams are involved.

If you want to dive in deeper, you can check out the websocket API ( … p/services)

I’m personally using a similar approach for controlling volumio. Irexec translates infrared commands to command line calls. A custom python script then handles the details of the websocket calls.

Hope that helps.


Thank you for the info.

Btw, can you share your python script? Thanks.

According to the Volumio command line client documentation

volumio stop stops the Volumio service, not playback. So I wouldn’t use that command for a hotkey/remote/etc.
I don’t know if Volumio does have a command to stop playback at all - only pause.

volumio vstop should do the trick

Thanks, I didn’t know about that!

I started to play around with the command line client. Indeed playback commands don’t seem to work at all. Things like ‘status’ and ‘volume’ work as expected, but using ‘volumio play’ or ‘volumio next’ simply does nothing.
Using ‘/volumio/app/plugins/system_controller/volumio_command_line_client/commands/playback.js play’ directly shows the same behavior, so I guess there’s a bug in that file. I’m not able to see it, though :wink:

(there’s also a bugreport on github: )

Happy easter!

I would like to implement a super simple way to have some basic volumio (2) control with a keyboard or similar (joystick?) thing (without soldering/using GPIO pins which are used by the DAC).

My current idea:

  • use a USB numpad
  • maybe use “triggerhappy” as discussed here?
  • use REST API?

Assuming “KEY_1” the correct triggerhappy key for the key “1” I assume then putting something like:

KEY_1 0 curl volumio.local/api/v1/commands/?cmd=playplaylist&name=1stPlaylist

in the config file (as explained above) would make volumio play the playlist named “1stPlaylist”.

Am I right in assuming this works? (Unfortunately I just notice the command “playplaylist” doesn’t seem to be recognized…)

Any idea how this could work? Or a simpler idea?

Hard- and software wise?

(I would like my 3-year old daughter + my wife to be able to press a simple key to play something predefined without starting a bigger programming/engineering project…)

If I understood well, I cannot use mpc commands to play playlists?

Thanks! Florian

Thank you for this useful information!


i did try triggerhappy with some controllers it act great but some of keys doest work. is it normal? is there anything to make it work?

thanks working!

KEY_VOLUMEUP 1 /usr/local/bin/volumio volume $((($(/usr/local/bin/volumio volume)) + 1))

KEY_VOLUMEUP 2 /usr/local/bin/volumio volume $((($(/usr/local/bin/volumio volume)) + 3))

KEY_VOLUMEDOWN 1 /usr/local/bin/volumio volume $((($(/usr/local/bin/volumio volume)) - 1))

KEY_VOLUMEDOWN 2 /usr/local/bin/volumio volume $((($(/usr/local/bin/volumio volume)) - 3))

KEY_PLAYPAUSE 0 /usr/local/bin/volumio toggle

KEY_NEXTSONG 0 /usr/local/bin/volumio next

KEY_PREVIOUSSONG 0 /usr/local/bin/volumio previous

Very interesting project. Thanks for sharing.
Could you post your Arduino sketch?

Thanks, wow! This way I was able to use the wireless remote control with USB dongle offered by HiFiBerry. Very good deal, lightweight and good quality clickable buttons.
I programmed these keys:


KEY_VOLUMEUP 1 curl "http://volumio.local:3000/api/v1/commands/?cmd=volume&volume=plus"

KEY_VOLUMEDOWN 1 curl "http://volumio.local:3000/api/v1/commands/?cmd=volume&volume=minus"

KEY_ENTER 1 curl "volumio.local:3000/api/v1/commands/?cmd=toggle"

KEY_RIGHT 1 curl "volumio.local:3000/api/v1/commands/?cmd=next"

KEY_LEFT 1 curl "volumio.local:3000/api/v1/commands/?cmd=prev"

KEY_ESC 1 curl "volumio.local:3000/api/v1/commands/?cmd=stop"

KEY_COMPOSE 1 curl "volumio.local:3000/api/v1/commands/?cmd=clear"

So the following keys excluded, because they were not recognised or there was no use for them:
The on/off key does not work
The home key does not work
The pointer key does not work

1 Like

Here’s an updated config file for triggerhappy with extended functionality that works with the hifiberry USB remote and the current build of Volumio (2.861). Here are the contents of /etc/triggerhappy/triggers.d/audio.conf


KEY_HOME 1 /usr/local/bin/volumio volume toggle

KEY_VOLUMEUP 1 /usr/local/bin/volumio volume plus

KEY_VOLUMEDOWN 1 /usr/local/bin/volumio volume minus

KEY_ENTER 1 /usr/local/bin/volumio toggle

KEY_UP 1 /usr/local/bin/volumio seek plus

KEY_DOWN 1 /usr/local/bin/volumio seek minus

KEY_RIGHT 1 /usr/local/bin/volumio next

KEY_LEFT 1 /usr/local/bin/volumio previous

KEY_COMPOSE 1 /usr/local/bin/volumio random

KEY_ESC 1 /usr/local/bin/volumio repeat

KEY_POWER 1 /usr/local/bin/volumio clear

After editing, you must restart the service with

sudo /etc/init.d/triggerhappy reload

Functions of each key are listed in the comments above the command.

IMPORTANT NOTE: This remote has a mouse control button in the upper right of the control. This button toggles mouse mode and totally messes up the mapping, making the remote almost useless. Don’t push it, don’t map it, and the keys above will work just fine.

After editing, you must restart the service with

sudo /etc/init.d/triggerhappy reload

Quite good hint here! This is actually really powerfull, you can even add whole spotify playlists or radio Urls:

KEY_1 1 /usr/bin/curl -i --header "Content-Type: application/json" localhost:3000/api/v1/replaceAndPlay --data '{  "service": "webradio",  "type": "webradio",  "title": "RadioParadise",  "uri": "",  "albumart": ""}' 

KEY_2 1 /usr/bin/curl -i --header "Content-Type: application/json" localhost:3000/api/v1/replaceAndPlay --data '{  "service": "webradio",  "type": "webradio",  "title": "RadioParadiseRock",  "uri": "",  "albumart": ""}' 

KEY_3 1 /usr/bin/curl -i --header "Content-Type: application/json" localhost:3000/api/v1/replaceAndPlay --data '{  "service": "webradio",  "type": "webradio",  "title": "EgoFM",  "uri": "",  "albumart": ""}' 

#GET MORE SPOTIFY PLAYLISTS VIA REST command (install a REST plugin for your browser is recommended): http://volumio.local/api/v1/browse?uri=spotify/playlists

KEY_4 1 /usr/bin/curl -i --header "Content-Type: application/json" localhost:3000/api/v1/replaceAndPlay --data '{  "service": "spop", "type": "playlist", "title": "Release Radar", "albumart": "", "uri": "spotify:user:spotify:playlist:37i9dQZEVXboZS2Bc5o5qH"}' 

KEY_5 1 /usr/bin/curl -i --header "Content-Type: application/json" localhost:3000/api/v1/replaceAndPlay --data '{ "service": "spop", "type": "playlist", "title": "Discover Weekly", "albumart": "", "uri": "spotify:user:spotify:playlist:37i9dQZEVXcKMQKnTB7OVv"}'

found this via: