Controlling Kodi with Google Home

As with the last post, this uses a Google Home speaker, If This Then That and a Raspberry Pi to allow voice control of something. This time it’s a Kodi media player. 

My previous post talked about using If This then that to send voice commands to a remote controlled socket via a Raspberry Pi. It covers static addresses etc, so please refer to that to get a Pi connected to the internet in a way that can be used with If This then that.

The Pi I have exposed to the internet isn’t me media player so I use a CGI script to control the media player when commands are sent from If This then that.

Firstly, the ifttt setup. The If part is a Google Assistant trigger of type “Say a phrase with a text ingedient” and the text I gave it was “tell kodi to $” (without the quotes) which means it will take whatever you say in place of $ and pass it on to the That part. I set the response field to “ok telling kodi to $” so now I can say “Ok google. Tell Kodi to pause” and it will reply “OK, telling Kodi to pause.” For added fun you can have Google saying it’s telling Kodi anything, but the script later will ignore most things.

The action on ifttt is a webhook as follows


with a GET method and text/plain encoding. This calls a script on my Raspberry Pi that looks like this

echo -e content-type: text/plain\\n
echo Query String: $myline
PARAM=`echo $myline | cut -d \= -f 2`
echo Param: $PARAM
echo " "
echo " "

if [ "$PARAM" = "play" ]
    wget -qO- --user kodi --password XXXX\{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\"\,\"params\":\{\"playerid\":1\},\"id\":1\}

if [ "$PARAM" = "pause" ]
    wget -qO- --user kodi --password XXXX\{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\"\,\"params\":\{\"playerid\":1\},\"id\":1\}

Replace the IP in the two wget lines with the IP of your Kodi system and the XXXX with youe kodi password. You’ll need to enable the web interface for this to work in the interfaces setting in kodi. You’ll also need to make sure your Kodi box has a fixed IP address.

Most of the code there is debugging stuff to echo back the parameters fed in. You can test this script by putting this into your web browser


Play and Pause are toggles on Kodi, so play and pause in the script do the same thing. Requesting that page should cause your Kodi box to pause.

The two wget lines are the same here as at the time I thought I’d be able to play and pause separately and I’ve still not given up on that. There’s a lot of escaped characters in there, getting them right was one of the hardest bits of developing this.

And that’s all for now. One day I’ll add some seeking, but for now It does the bit I find the most useful.

Leave a Reply

Your email address will not be published.