{"id":86,"date":"2017-12-06T20:00:45","date_gmt":"2017-12-06T20:00:45","guid":{"rendered":"http:\/\/www.hoagieshouse.com\/blog\/?p=86"},"modified":"2017-12-03T19:56:09","modified_gmt":"2017-12-03T19:56:09","slug":"controlling-kodi-with-google-home","status":"publish","type":"post","link":"http:\/\/www.hoagieshouse.com\/blog\/pi\/controlling-kodi-with-google-home\/","title":{"rendered":"Controlling Kodi with Google Home"},"content":{"rendered":"<p>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&#8217;s a Kodi media player.\u00a0<!--more--><\/p>\n<p>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.<\/p>\n<p>The Pi I have exposed to the internet isn&#8217;t me media player so I use a CGI script to control the media player when commands are sent from If This then that.<\/p>\n<p>Firstly, the ifttt setup. The If part is a Google Assistant trigger of type &#8220;Say a phrase with a text ingedient&#8221; and the text I gave it was &#8220;tell kodi to $&#8221; (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 &#8220;ok telling kodi to $&#8221; so now I can say &#8220;Ok google. Tell Kodi to pause&#8221; and it will reply &#8220;OK, telling Kodi to pause.&#8221; For added fun you can have Google saying it&#8217;s telling Kodi anything, but the script later will ignore most things.<\/p>\n<p>The action on ifttt is a webhook as follows<\/p>\n<p>http:\/\/YOUR_ADDRESS\/cgi-bin\/mediaplayer.cgi?param={{TextField}}<\/p>\n<p>with a GET method and text\/plain encoding. This calls a script on my Raspberry Pi that looks like this<\/p>\n<pre>#!\/bin\/sh\r\necho -e content-type: text\/plain\\\\n\r\nmyline=$QUERY_STRING\r\necho Query String: $myline\r\nPARAM=`echo $myline | cut -d \\= -f 2`\r\necho Param: $PARAM\r\necho \" \"\r\necho \" \"\r\n\r\nif [ \"$PARAM\" = \"play\" ]\r\nthen\r\n    wget -qO- --user kodi --password XXXX http:\/\/192.168.0.129:8080\/jsonrpc?request=\\{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"Player.PlayPause\\\"\\,\\\"params\\\":\\{\\\"playerid\\\":1\\},\\\"id\\\":1\\}\r\nfi\r\n\r\nif [ \"$PARAM\" = \"pause\" ]\r\nthen\r\n    wget -qO- --user kodi --password XXXX http:\/\/192.168.0.129:8080\/jsonrpc?request=\\{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"Player.PlayPause\\\"\\,\\\"params\\\":\\{\\\"playerid\\\":1\\},\\\"id\\\":1\\}\r\nfi\r\n<\/pre>\n<p>Replace the IP in the two wget lines with the IP of your Kodi system and the XXXX with youe kodi password. You&#8217;ll need to enable the web interface for this to work in the interfaces setting in kodi. You&#8217;ll also need to make sure your Kodi box has a fixed IP address.<\/p>\n<p>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<\/p>\n<p>http:\/\/YOUR_ADDRESS\/cgi-bin\/mediaplayer.cgi?param=pause<\/p>\n<p>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.<\/p>\n<p>The two wget lines are the same here as at the time I thought I&#8217;d be able to play and pause separately and I&#8217;ve still not given up on that. There&#8217;s a lot of escaped characters in there, getting them right was one of the hardest bits of developing this.<\/p>\n<p>And that&#8217;s all for now. One day I&#8217;ll add some seeking, but for now It does the bit I find the most useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s a Kodi media player.\u00a0<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,6,4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/posts\/86"}],"collection":[{"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":1,"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":87,"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions\/87"}],"wp:attachment":[{"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hoagieshouse.com\/blog\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}