Have you ever wanted to pause or skip to the next song, or turn up the volume while your PC is playing your favorite song? Well, now you can do those things from across the room or even across the Internet if you'd like.
I setup my lircrc file on the Pi to call the TRIGGERcmd API using curl commands when I press buttons on the remote. The curl commands trigger commands on my PC over the Internet that pause, skip songs, or turn up the volume, etc.
- I followed this tutorial to get my Pi Zero W on WiFi without even connecting a keyboard and monitor to it.
- I followed this tutorial to get it setup with LIRC to run commands when I press corresponding buttons on an old VCR remote.
- You can use this video to get familiar with how TRIGGERcmd works, and how to install it on your Windows PC. You'll need a TRIGGERcmd agent on your PC.
- This should help you install the TRIGGERcmd agent on your Raspberry Pi, but you don't have to for this. You'll need to store a token in a file though, and when you setup the agent, that happens automatically. The example below assumes you've installed the a Raspberry Pi TRIGGERcmd agent so your token is in this file:
/root/.TRIGGERcmdData/token.tkn
The /etc/lirc/lircrc file maps remote control buttons to commands. My /etc/lirc/lircrc file looks like this. "Downstairs" is the name of my Windows PC in my TRIGGERcmd account.
begin
prog = irexec
button = KEY_PLAY
config = export HOME=/root ; /root/triggertest.sh "Media Play Pause" downstairs
end
begin
prog = irexec
button = KEY_PAUSE
config = export HOME=/root ; /root/triggertest.sh "Media Play Pause" downstairs
end
begin
prog = irexec
button = KEY_RIGHT
config = export HOME=/root ; /root/triggertest.sh "Media Next" downstairs
end
begin
prog = irexec
button = KEY_LEFT
config = export HOME=/root ; /root/triggertest.sh "Media Previous" downstairs
end
begin
prog = irexec
button = KEY_STOP
config = export HOME=/root ; /root/triggertest.sh "Media Stop" downstairs
end
begin
prog = irexec
button = KEY_UP
config = export HOME=/root ; /root/triggertest.sh "Volume Up" downstairs
end
begin
prog = irexec
button = KEY_DOWN
config = export HOME=/root ; /root/triggertest.sh "Volume Down" downstairs
end
My /root/triggertest.sh file looks like this. You can see the curl command uses the token you used when you ran "triggercmdagent" on your Raspberry Pi for the first time.
#!/bin/sh
trigger=$1
computer=$2
token=`cat /root/.TRIGGERcmdData/token.tkn`
curl -X POST https://www.triggercmd.com/api/run/triggerSave \
-H "authorization: Bearer ${token}" \
-H 'content-type: application/json' \
-d "{\"computername\":\"${computer}\",\"triggername\":\"${trigger}\"}"
Installing AutoHotkeyYou'll need to install AutoHotkey on your Windows box to make the play, pause, volume up etc. commands work.
These are the corresponding commands.json entries for my Windows TRIGGERcmd agent config:
{"trigger":"Volume Up","command":"start C:\\autohotkeyscripts\\media.ahk volup","ground":"foreground","voice":"volume up"},
{"trigger":"Volume Down","command":"start C:\\autohotkeyscripts\\media.ahk voldown","ground":"foreground","voice":"volume down"},
{"trigger":"Media Next","command":"start C:\\autohotkeyscripts\\media.ahk next","ground":"foreground","voice":"next"},
{"trigger":"Media Stop","command":"start C:\\autohotkeyscripts\\media.ahk stop","ground":"foreground","voice":"stop"},
{"trigger":"Media Previous","command":"start C:\\autohotkeyscripts\\media.ahk previous","ground":"foreground","voice":"previous"},
{"trigger":"Media Play Pause","command":"start C:\\autohotkeyscripts\\media.ahk pause","ground":"foreground","voice":"pause"},
Note: The last line in your commands.json file should not end with a comma. That would be bad json form, and the Windows TRIGGERcmd agent will throw an error.
This is my c:\autohotkeyscripts\media.ahk AutoHotkey script that the above commands.json entries refer to:
Gosub, %1%
return
next:
Send {Media_Next}
return
previous:
Send {Media_Prev}
return
pause:
Send {Media_Play_Pause}
return
stop:
Send {Media_Stop}
return
volup:
Send {Volume_Up}
return
voldown:
Send {Volume_Down}
return
Warning: I found that some remotes work better than others. For instance, my Window Media Center remote works, but each button alternates between two different IR codes, so it works every other time you press a button. I settled on an old Toshiba VCR remote.
If you try this, congratulations, you're an awesome nerd and I want to talk to you about your experience, so hit me (Russ) up on the TRIGGERcmd forum.
Comments