Talking to your Sony Bravia TV over HTTP with Google Now, Tasker, XBMC, and Roku

Phil Wolstenholme
3 min readAug 1, 2014

--

Using Tasker, AutoVoice, Yatse and XBMC, I built a custom Google Now (‘OK Google’) command to play/pause media on my Sony Bravia TV. With a few modifications, it now works across all the apps on my Sony Bravia TV, my XBMC (now called Kodi) box, and my NowTV/Roku box too. Take that Siri! Not bad for half an hour’s work…

I followed this tutorial to get the very basics started, and used the ‘Send intent’ action in Tasker to hook into the Yatse API. To prevent Google search results being shown for ‘TV pause’, I added a ‘Go Home’ action to the Tasker task.

Dealing directly with the TV rather than XBMC

It turns out Sony ‘smart TVs’ can be controlled simply by POSTing XML data to the TV. This is how the official Sony remote control Android and iOS apps work, and you can observe their behaviour by packet sniffing the data sent by the official apps.

I didn’t run into any authorisation prompts when experimenting with POSTing data to my TV, but that might have been because I had previously used the Sony TV SideView app as a remote control for my TV, so my phone was authorised to send commands.

Update: If you run into problems with authentication you might be able to authenticate using snippets from this GitHub repo and this supporting blog post.

I’ve amended my Tasker script to send a native pause command to my TV (which will pass it to XBMC/Kodi via CEC on the HDMI port because I’m using a Raspberry Pi). The advantage of this is that it doesn’t require the Yatse app, and that now the pause command will not only pause XBMC, but also the native apps on my Bravia TV such as iPlayer, YouTube, recorded TV, Amazon Instant Video and so on. If your XBMC installation doesn’t listen for CEC commands over HDMI then you would still want to use the Yatse approach.

Here’s the XML data to send to the TV by a HTTP POST request:

Send the data to http://IP-ADDRESS-OF-YOUR-TV/IRCC (e.g. http://192.168.0.3/IRCC). If that doesn’t work you can try http://IP-ADDRESS-OF-YOUR-TV/sony/IRCC.

Here’s a list of other IRCC commands:

Controlling a Roku or NowTV box

I recently got a Sky NowTV box, primarily because there’s no 4oD app for XBMC or my Sony Bravia TV. For £9.99 the NowTV box is a pretty good investment! The NowTV box is a rebranded Roku box, so you can interact with it using the Roku RESTful API. Here’s the command to POST to the Roku box for play/pause:

http://IP-ADDRESS-OF-YOUR-ROKU-BOX:8060/keypress/Play

Other ideas

As well as a novel way to pause your TV, you could use this method to do all sorts of clever things with Tasker and your Android device. A few ideas I’ve had include:

  1. Pausing or muting the television when an incoming call arrives
  2. Parsing calendar entries for text strings that represent channel numbers and then switching the TV to the appropriate channel when that calendar entry (a reminder to watch a programme) starts to take place
  3. Putting your TV on standby just before you disconnect (when the signal gets very weak?) from your home wifi (in case the TV was accidentally left on). Obviously once you left your home network sending a signal to your TV would be difficult, so be careful when planning this task!
  4. Use the codes below to switch between HDMI inputs. Create a task to switch immediately to one input instead of having to use your TV’s remote to scroll through all the available inputs and then select one.
    ‘HDMI1’: ‘AAAAAgAAABoAAABaAw==’, ‘HDMI2’: ‘AAAAAgAAABoAAABbAw==’, ‘HDMI3’: ‘AAAAAgAAABoAAABcAw==’, ‘HDMI4’: ‘AAAAAgAAABoAAABdAw==’

Originally published at wolstenhol.me on August 1, 2014.

--

--

Phil Wolstenholme

I’m an accomplished developer with a wide range of skills, knowledge, and experience, particularly focussed on accessibility and frontend web performance.