How to Teach Google Assistant to Talk to your TiVo

Why do you need to control your TiVo through Google Assistant?

To that we say, “Why would you NOT?” But in all seriousness, picture this. You’re sitting on the couch. Belly full of dinner, cat on your lap or child sleeping on your shoulder and you need to switch from the Saved by the Bell marathon to the new episode of Game of Thrones that’s about to start. Oh no! The remote is nowhere to be found. Now what? Google to the rescue! Now, all you have to do is say, “Okay, Google. TiVo HBO.” As if by magic, your television cuts off Jessie Spano’s excitement just in time to get caught up on John Snow’s adventures.

Knowledge Needed:
  • Port Forwarding
  • Setting up a Raspberry Pi
    • Installing/configuring apache
    • Installing PHP
    • Installing telnet
  • The Code
  • IFTTT Applet

Difficulty Level: Meh

Before You Get Started

It is important to know before you try to do anything with this, that you need to be able to setup port forwarding on your router. Since there are many different routers and ISPs, I can’t tell you if you can do it. You’ll need to consult Google for this one. Find the make/model of your router and type into google “{make} {model} port forwarding.” This should get you in the right direction. If you can setup port forwarding on your router, then you can teach your Google Assistant to talk to your TiVo! And believe me you, it’s pretty deece.

Step 1: Setting up your Raspberry Pi w/ Apache, PHP & telnet

If you already have your Raspberry Pi initial install, great! If you don’t, go ahead and do that.

Once you are done with that, open a terminal on your Raspberry Pi (ctrl+alt+t). First we need to make sure that we have an updated list of packages. To do this, type in the terminal:

sudo apt-get update

Now that our sources are up-to-date, we can install Apache, PHP, and Telnet.

To install Apache enter the following command:

sudo apt-get install apache2 apache2-utils

Once Apache is installed we can continue by installing PHP. To do that enter this command in that same terminal:

sudo apt-get install libapache2-mod-php5 php5 php-pear php5-xcache php5-mysql php5-curl php5-gd

Now that we have your RPI setup as a webserver, we also need it to be able to talk to other devices via telnet.

sudo apt-get install telnet

Now that we have the fun stuff installed, let’s move on to setting up your router to pass the request from the outside world to your Raspberry Pi on your local network.

Step 2: Setting up port forwarding

The same way you referenced port forwarding on your router should be able to help you here. What you need to know is the local IP address of your Raspberry Pi. To find that, in the terminal type

ifconfig | grep -m 1 "inet addr:192"

This will get you something like this:

ifconfig | grep "inet addr:"
inet addr:127.0.0.1  Mask:255.0.0.0
inet addr:192.168.1.122  Bcast:192.168.1.255  Mask:255.255.255.0

The number you are looking for probably looks like: 192.168.1.xxx

NOTE: if you do not get any results, just do: ifconfig

Copy that into the port forwarding destination.

Step 3: Setting up the apache virtual host

If you’re not familiar with setting up your own site, here’s a great reference from our friends at Digital Ocean.

What I did was set up a virtual host for my apache webserver. This allows me to listen to a specific port for this particular application (great if you have other things your Pi controls via Internet). Here is what my virtual host file looks like:


# I listen on 31339 because that’s the port that the TiVo
# listens on.
Listen 31339
<VirtualHost *:31339>
DocumentRoot "/var/www/google-assistant-tivo.com/public_html/"
ServerName google-assistant-tivo.com
ServerAlias www.google-assistant-tivo.com
<Directory "/var/www/google-assistant-tivo.com/public_html">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# Don’t forget to create this directory
ErrorLog /var/www/google-assistant-tivo.com/logs/error.log
</VirtualHost>

Step 4: The Code

There is a little bit of extra code added here that isn’t necessary to make this work, but what it does do is allow you to say “Okay, Google. TiVo HGTV” ($channelLookup) which will change the channel on the TiVo to, you guessed it, HGTV (you [most likely] need to modify the channel number that goes with the channel name). It also gets you a quick and dirty request log so you can debug your app and figure out what is going on.

So, here it is:

https://bitbucket.org/mdahlke/google-assistant-tivo/

Step 5: IFTTT

Setting up your applet on ifttt.com is as straightforward as it gets. If you’ve set one up before then you’ll have no problems with this step.

  1. Create New Applet
  2. For “this” select “Google Assistant
  3. For your trigger, select “Say a phrase with a text ingredient
  4. In the “What do you want to say” field enter: “TiVo $” (without the quotes)
  5. In the “What do you want the Assistant to say in response?” this is up to you. I have it responding with “Okay, TiVo $” so it echoes back what I said so I know it’s doing the right thing
  6. Click “Create Trigger
  7. Click “that
  8. Select “Maker Webhooks” for the action service
  9. Select “Make a web request
  10. Fill in the fields:
    • URL: This will be your public IP address followed by “/hook.php” and then the port that your virtual host is listening on. In my virtual hosts I have it set to listen on port 31339. So I entered in this field http://192.168.1.122:31339/hook.php (this will also be what the port you forwarded the request to on your router to)NOTE: The IP address I used in the example above is an internal IP that is not publicly accessible. To find your public IP address, ask Google what it is
    • Method: POST
    • Content Type: application/json
    • Body: {“type”:”default”,”command”: “{{TextField}}”}
  11. Double check your inputs and click “Save”

Now you should be able to control your TiVo via your Google Assistant. That in itself is AWESOME!!! But one thing you may have noticed is changing channels via the channel number is not that awesome. Example, you try to say “Okay, Google. TiVo channel six two nine” and it sends the request as “6 – 9” (or that’s what I’ve found in the request.log). So to get around this I made another applet that specifically handles the channel request by accepting only a number. Here’s how to do it:

  1. Create New Applet
  2. For “this” select “Google Assistant
  3. For your trigger, select “Say a phrase with a number ingredient
  4. In the “What do you want to say” field enter: “TiVo channel $” (without the quotes)
  5. In the “What do you want the Assistant to say in response?” field enter: “Okay, changing channel to $”
  6. Click “Create Trigger
  7. Click “that
  8. Select “Maker Webhooks” for the action service
  9. Select “Make a web request
  10. Fill in the fields:
    • URL: This will be your public IP address followed by “/hook.php” and then the port that your virtual host is listening on. In my virtual hosts I have it set to listen on port 31339. So I entered in this field http://192.168.1.122:31339/hook.php (this will also be the port you forwarded the request to on your router to) NOTE: The IP address I used in the example above is an internal IP that is not publicly accessible. To find your public IP address, ask Google what it is
    • Method: POST
    • Content Type: application/json
    • Body: {“type”:”default”,”command”: “{{NumberField}}”}
  11. Double check your inputs and click “Save”
Congratulations

You’re now among the elite TiVo users who can control their watching by the soothing sound of your own voice. Want more geeky & creative ideas? Stay tuned to the musings of the geeks & creatives of wisnet, or hit us up if you have questions on deploying a project. We’ve got you covered to go fearless into the net.

Issues?

If you run into any issues you can submit a an issue via the Bitbucket Repo.