Controlling a Sony Bravia TV with Google Home

Continuing on the theme of ‘controlling everything with my voice’, I’ve successfully integrated yet another appliance into my setup – this time my TV!

I’ve owned a Sony Bravia 2015 TV for around 18 months now, and while the interface does slow to a crawl at times, overall I’m very impressed with the Android TV integration, and have gone as far as to switch from using a dedicated Kodi machine to running a Plex server and using the native Plex Android TV App. However, at the time of writing this, there isn’t a way of controlling low-level functions of the TV (power, volume etc) from Google Home, you can only use the Chromecast integration. While I’ll agree it’s not entirely practical to navigate media entries on the TV with your voice, I find myself wanting to switch the TV on/off from another room, or pause playback with my voice rather than scrambling for a remote when my phone rings.

Unfortunately it doesn’t appear that the Bravia TV offers any direct API for issuing commands over the network, so instead I looked for a device that could emulate the remote control. After a bit of searching I came across the Broadlink RM Mini 3 (Amazon link) – I was initially a bit sceptical given the low price point and very foreign documentation, however I was pleasantly surprised by how easy the setup was, although the Android application leaves a lot to be desired. Next step was to find a way of issuing commands to the Broadlink device over my network. While there is a handy Python library, and even an extension for the RM Mini 3 capable of issuing IR commands, neither of these would allow commands to be sent over a HTTP connection.

Given the easiest method of integrating with the Google Assistant/Google Home is through their IFTTT channel, this HTTP interface was going to save a lot of effort, so I set about creating one myself! The resulting code is a fork of the BlackBeanControl repository mentioned above, but with an additional Python script using to expose an interface for sending commands over a HTTP request. I’ve then placed this script behind my home Apache proxy (sufficiently secured to prevent the entire internet being able to turn my TV on and off), and used the IFTTT Webhook channel to make the appropriate requests when triggered.

I’m somehow becoming even lazier than I ever imagined – now I don’t even have to reach for the remote to continue my binge-watching!

Unable to load on Kodi

As part of a complete re-vamp of my home media setup (blog post coming soon on that!), I found myself trying to connect a Sony TV to an Intel NUC running Kodi v16 via one of PulseEight‘s brilliant USB-CEC Adapters. However, no matter what I tried (combinations of cables, all the settings on the TV, different ports on the NUC etc) I could not get Kodi to recognise the adapter. Despite the Kodi Wiki page on CEC suggesting that this should plug-and-play, I did not get any suggestion from either the TV or Kodi that the CEC dongle was being recognised.

After quite a lot of searching in the wrong place (at first I was convinced that my fresh install of Kodibuntu wouldn’t be the root cause), I found a couple of log lines that finally pointed me in the right direction:

DEBUG: Loading:
ERROR: Unable to load, reason: cannot open shared object file: No such file or directory

Turns out that Kodi is built against, however the version in the repository (I believe that was bundled or at least suggested by Kodibuntu) is 3.1. Kodi should (theoretically) be built against (note the missing .0), which the appropriate symlinks would have taken care of, however it seems there are some changes between 3.0 and 3.1 that Kodi doesn’t like, so some simple switching of the links (I tried creating /usr/local/lib/ -> /usr/local/lib/, which in hindsight isn’t a great idea) caused various crashes that I wasn’t prepared to start debugging – so instead I used the suggestion in this forum thread:

$ apt-get install --reinstall libcec3=3.0.1-1~trusty

Which will put the old version of libcec on your machine. After a quick reboot, Kodi instantly recognised the CEC dongle as promised, and it has been working beautifully ever since!