[GUIDE] 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 http://analogbubblebath.housejunkie.ca:8000/deepershades; mpc play KEY_F2 0 mpc clear; mpc add http://7719.live.streamtheworld.com:3690/OCEANPACIFIC_SC; mpc play KEY_F3 0 mpc clear; mpc add mms://195.245.168.21/antena3; mpc play KEY_F4 0 mpc clear; mpc add mmsh://emdirecto.tsf.pt/tsfdirecto?MSWMExt=.asf; mpc play

Every line of the config file should have three parameters:
[KEY_CODE] [WHEN] [COMMAND]

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:
https://github.com/wertarbyte/triggerhappy

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

2 Likes

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.

Hey,
the official documentation is here: volumio.github.io/docs/Good_to_ … 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 (github.com/volumio/Volumio2-UI/ … 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.

Jochen

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: github.com/volumio/Volumio2/issues/952 )

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!

hello,

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?
Regards

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

https://youtu.be/83Q9bihbmcI

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

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:

#VOLUMIO TRIGGERHAPPY CONFIGURATION FILE

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

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

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

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

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

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

#CLEAR QUEUE
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:
KEY_UP
KEY_DOWN
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

#VOLUMIO REMOTE TRIGGERHAPPY CONFIGURATION FILE

#MUTE TOGGLE
KEY_HOME 1 /usr/local/bin/volumio volume toggle

#VOLUME UP
KEY_VOLUMEUP 1 /usr/local/bin/volumio volume plus

#VOLUME DOWN
KEY_VOLUMEDOWN 1 /usr/local/bin/volumio volume minus

#PLAY PAUSE TOGGLE
KEY_ENTER 1 /usr/local/bin/volumio toggle

#FAST FORWARD 10 SECONDS
KEY_UP 1 /usr/local/bin/volumio seek plus

#REWIND 10 SECONDS
KEY_DOWN 1 /usr/local/bin/volumio seek minus

#NEXT SONG
KEY_RIGHT 1 /usr/local/bin/volumio next

#PREVIOUS SONG
KEY_LEFT 1 /usr/local/bin/volumio previous

#TOGGLE RANDOM
KEY_COMPOSE 1 /usr/local/bin/volumio random

#TOGGLE REPEAT
KEY_ESC 1 /usr/local/bin/volumio repeat

#CLEAR CURRENT QUEUE
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
1 Like

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

#RADIO PARADISE
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": "https://stream.radioparadise.com/aac-320",  "albumart": "https://radioparadise.com/graphics/logo_flat_350x103.png"}' 

#RADIO PARADISE ROCK
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": "https://stream.radioparadise.com/rock-320",  "albumart": "https://radioparadise.com/graphics/logo_flat_350x103.png"}' 

#RADIO EGOFM
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": "http://mp3ad.egofm.c.nmdn.net/ps-egofm_192/livestream.mp3",  "albumart": "https://www.egofm.de/images/site/logo.svg"}' 

#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

#SPOTIFY RELEASERADAR
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": "https://newjams-images.scdn.co/v3/release-radar/ab6761610000e5ebda012e44f73353016e419282/en/large", "uri": "spotify:user:spotify:playlist:37i9dQZEVXboZS2Bc5o5qH"}' 

#SPOTIFY DISCOVER WEEKLY
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": "https://newjams-images.scdn.co/v3/discover-weekly/aAbca4VNfzWuUCQ_FGiEFA==/bmVuZW5lbmVuZW5lbmVuZQ==/default", "uri": "spotify:user:spotify:playlist:37i9dQZEVXcKMQKnTB7OVv"}'

found this via:

Does this work with other USB wireless remotes/airmouses (like the ones on Aliexpress)?

It should as long as it shows up as a standard input device (USB HID mode)

And it works so far with the default Playback options. But I would like to assign some keys to my Music Library Network Shares Folders. Like pressing button 1: starts the playback of the first folder, pressing button 2 : starts playback of the the second folder, etc… (This remote has may keys). How can I specify this in the triggerhappy config file? Thanks!

Edit: So the be more clear: If I want start the playback from my NAS (SMB) Share like the folder called (i.e.) “Remixes” what should I type in the config line?

1 Like

I have already solved both the Playlist and the Radio playback with this method on Volumio v.2.917. But will this triggerhappy “workaround” also work with the new v.3.x, just like it was with v.2.917? Anyone here had tried it so far? (I will only update to v.3.x if I can make it work again flawlessly, as the remote controller is essential for me).

I have configured Volumio (3.179 on RPi4) for the OSMC remote control. image
here is my /etc/triggerhappy/tiggers.d/audio.conf

#VOLUMIO TRIGGERHAPPY CONFIGURATION FILE

#MUTE TOGGLE
KEY_ENTER 1 /usr/local/bin/volumio volume toggle

#VOLUME UP
KEY_EQUAL 1 /usr/local/bin/volumio volume plus
KEY_EQUAL 2 /usr/local/bin/volumio volume plus

#VOLUME DOWN
KEY_MINUS 1 /usr/local/bin/volumio volume minus
KEY_MINUS 2 /usr/local/bin/volumio volume minus

#PLAY PAUSE TOGGLE
KEY_PLAYPAUSE 1 /usr/local/bin/volumio toggle

#STOP
KEY_STOP 1 /usr/local/bin/volumio stop

#CLEAR
KEY_ESC 1 /usr/local/bin/volumio clear

#NEXT
KEY_RIGHT 1 /usr/local/bin/volumio next

#PREVIOUS
KEY_LEFT 1 /usr/local/bin/volumio previous

#SEEK FORWARD
KEY_UP 1 /usr/local/bin/volumio seek plus

#SEEK BACKWARD
KEY_DOWN 1 /usr/local/bin/volumio seek minus

#REPEAT
KEY_C 1 /usr/local/bin/volumio repeat

#RANDOM
KEY_I 1 /usr/local/bin/volumio random

A couple of points I learned that are not in this thread:
to restart the service in V3 you need to run:

sudo systemctl restart triggerhappy

Not all events are on event0 so if you want to see all the button codes you need to run

sudo thd --dump /dev/input/event*

The volume control uses the step defied in the regular settings menu. If you use my config you should set the stepsize to 1 so that a single click on the volume up or down changes the volume by one increment, but pressing and holding gives a smooth increase or decrease for as long as it is held.

2 Likes