Controlling Sony TV with Google Home using Google Cloud

We changed our TV to Sony TV A8F series after almost 10 years. It has got voice control to do certain operations, but it is pretty limited unless you have Amazon Alexa (I still have problems connecting it with Alexa).

I thought I would give it a try to control the TV with Google Home and do this Home automation project. What seems to be simple have become complex pretty soon.

Firstly, I had to change few settings in TV so that it accept commands via local network.

One time setup

Turn on your TV
On the TV go to Settings > Network > Home network setup > Remote device/Renderer > On
On the TV go to Settings > Network > Home network setup > IP Control > Authentication > Normal and Pre-Shared Key
On the TV go to Settings > Network > Home network setup > Remote device/Renderer > Enter Pre-Shared Key > 0000 (or whatever you want your PSK Key to be)
On the TV go to Settings > Network > Home network setup > Remote device/Renderer > Simple IP Control > On

I then, built a nodeJS based web service with express framework and Bravia remote control library https://github.com/alanreid/bravia.

I could potentially have this web service hosted on a Raspberry Pi and leave it at home running.

Web service simply accepts command via query parameters (Authentication to be added later or use apigee)

Access from the Internet

Using https://ngrok.com/ I got a tunnel created and exposed the localhost web service on the internet.

Natural Language Processing with Dialogflow

Now I used Google Dialogflow to create an Intent and trained the model with various training data.

Connecting to the Web Service using fulfilment

I have enabled fulfilment to connect to the backend service.

I created a Google Cloud Function so that setup is serverless and created an endpoint based on firebase functions and created appropriate code to trigger the web service call to my localhost via ngrok.

I enabled the Invocation to my app with Google Actions and enabled the intents I require with help of ‘Actions on Google’

https://console.actions.google.com/

I was then able to control the TV with voice on Google Home. I could say things like

Hey Google, Connect to Sony TV, Open Netflix

I haven’t published the app to production as I don’t need it for public and I just wanted it to work on my personal Google Home for my TV.

Setup

Here is a simple architecture diagram of the whole setup.

High level architecture to connect SonyTV to Google Home

I haven’t added all the intents yet, but its a test on how all things work. We can add all the intents for which TV supports

Google Cloud Services Used:

  • Firebase for Cloud Functions
  • Actions on Google
  • Google Dialogflow

Note: most of the code is written for testing purposes only :)