Control your Sony Bravia TV from your Vera

After reading a lot… and testing to, I was able to completely control my Sony Bravia tv from my Vera.
I’m sure everything is already documented elsewhere but I tough this might help.
(Note : I’m not technical, just playing around :slight_smile: )

First, configure your TV to allow remote control :

  1. Enable remote start on your TV: [Settings] → [Network] → [Home Network Setup] → [Remote Start] → [On]

  2. Enable pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Authentication] → [Normal and Pre-Shared Key]

  3. Set pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Pre-Shared Key] → [WhatEveryouWant]

  4. Enable Remote device/Renderer: [Settings] → [Network] → [Home Network Setup] → [Remote device/Renderer] → [Remote device/Renderer] → [On]

  5. Enable Remote device/Renderer: [Settings] → [Network] → [Home Network Setup] → [Remote device/Renderer] → [Remote access control] → [Auto access permission] → [on]

  6. Get you TV a static IP for obvious reasons…

So, the Sony Bravia TVs can be remotely controlled multiple ways… IR, RS232, and IP.
I was more concerned about controlling it by IP.
So there is 2 way to control it by IP. (low level and high level protocol).

I first started with High level protocol that involve sending http post request to the device. (require pre shared key with the TV).
With high level protocol, request is sent to the tv using IRCC commands that mimic IR (see IRCC commands below). Here is a simple lua code for doing so: I had to add some sleep time between commands because the tv wasn’t catching everything:

function SendCommand(Command)
local socket = require 'socket'
local SONY_IP = "Your TV IP here"
local SONY_URL = "http://Your TV IP here/sony/IRCC"
local AUTH_CODE = "Your pre shared key here"
local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local REQUEST = "<?xml version=\"1.0\"?><s:Envelope xmlns:s=\"\" s:encodingStyle=\"\"><s:Body><u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\"><IRCCCode>"..Command.."==</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"

rBody, rCode, rHeaders, rStatus = http.request(
        method = "POST",
        url = SONY_URL,
        headers = {
            ["User-Agent"] = "curl/7.38.0",
            ["Host"] = SONY_IP,
            ["Accept"] = "*/*",
            ["X-Auth-PSK"] = AUTH_CODE,
            ["Content-Type"] = "text/xml; charset=UTF-8",
            ["Content-Length"] = tostring(#REQUEST),
            ["SOAPACTION"] = "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\""
        source = ltn12.source.string(REQUEST),
        sink = ltn12.sink.table(respBody),
        redirect = false
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")

--PowerOn the tv
--change to HDMI input 
--set volume down

This was working fine but since it mimics IR commands, setting the volume to a specific one was a bit of a pain.

Then I switched the Low level protocol to control the device.
Way easier to control… All the codes are here :

The tv respond to tcp port 20060.
Here is a simple lua request to power off the tv :

local socket = require("socket")
local host, port = "Your TV ip here", 20060
local tcp = assert(socket.tcp())

tcp:connect(host, port);

I still need to find a way to catch the replies from the tv and update my Vera accordingly.

Let me know if that helps you and if I can help somehow :slight_smile:

(IRCC commands)
'Analog': 'AAAAAgAAAHcAAAANAw==',
'Blue': 'AAAAAgAAAJcAAAAkAw==',
'ChannelDown': 'AAAAAQAAAAEAAAARAw==',
'Confirm': 'AAAAAQAAAAEAAABlAw==',
'Display': 'AAAAAQAAAAEAAAA6Aw==',
'Forward': 'AAAAAgAAAJcAAAAcAw==',
'Green': 'AAAAAgAAAJcAAAAmAw==',
'Next': 'AAAAAgAAAJcAAAA9Aw==',
'Options': 'AAAAAgAAAJcAAAA2Aw==',
'Pause': 'AAAAAgAAAJcAAAAZAw==',
'Play': 'AAAAAgAAAJcAAAAaAw==',
'Prev': 'AAAAAgAAAJcAAAA8Aw==',
'Red': 'AAAAAgAAAJcAAAAlAw==',
'Return': 'AAAAAgAAAJcAAAAjAw==',
'Rewind': 'AAAAAgAAAJcAAAAbAw==',
'SubTitle': 'AAAAAgAAAJcAAAAoAw==',
'SyncMenu': 'AAAAAgAAABoAAABYAw==',
'Yellow': 'AAAAAgAAAJcAAAAnAw==',

//not tested:
'Replay': 'AAAAAgAAAJcAAAB5Aw==',
'Advance': 'AAAAAgAAAJcAAAB4Aw==',
'TopMenu': 'AAAAAgAAABoAAABgAw==',
'PopUpMenu': 'AAAAAgAAABoAAABhAw==',
'Eject': 'AAAAAgAAAJcAAABIAw==',
'Rec': 'AAAAAgAAAJcAAAAgAw==',
'ClosedCaption': 'AAAAAgAAAKQAAAAQAw==',
'Teletext': 'AAAAAQAAAAEAAAA/Aw==',
'Digital': 'AAAAAgAAAJcAAAAyAw==',
'Ddata': 'AAAAAgAAAJcAAAAVAw==',
'InternetWidgets': 'AAAAAgAAABoAAAB6Aw==',
'InternetVideo': 'AAAAAgAAABoAAAB5Aw==',
'SceneSelect': 'AAAAAgAAABoAAAB4Aw==',
'Mode3D' : 'AAAAAgAAAHcAAABNAw==',
'iManual' : 'AAAAAgAAABoAAAB7Aw==',
'ProgramDescription': 'AAAAAgAAAJcAAAAWAw==',
'WriteChapter': 'AAAAAgAAAHcAAABsAw==',
'TrackID' : 'AAAAAgAAABoAAAB+Aw==',
'AppliCast': 'AAAAAgAAABoAAABvAw==',
'acTVila': 'AAAAAgAAABoAAAByAw==',
'DeleteVideo': 'AAAAAgAAAHcAAAAfAw==',
'EasyStartUp': 'AAAAAgAAAHcAAABqAw==',
'OneTouchTimeRec': 'AAAAAgAAABoAAABkAw==',
'OneTouchView' : 'AAAAAgAAABoAAABlAw==',
'OneTouchRec' : 'AAAAAgAAABoAAABiAw==',
'OneTouchRecStop' : 'AAAAAgAAABoAAABjAw==',

Cool thank you.

Do you know of any way to directly open apps via tcp/ip like ie. Youtube or Plex?

I will try it myself to see if it will work. Thanks for sharing it with us.

One thing to note…

The very first step you outline is to turn on the Remote Start function. There are a lot of Bravia TV owners, myself included, that have had to turn this OFF to prevent the TV from turning on seemingly randomly. Sony has NOT done a good job of setting up the various networking functions in their Android TV’s, and it seems that this function can get triggered by a variety of different devices on a home network.

In other words, while this all looks really great, YMMV. And if your TV comes on in the middle of the night for no apparent reason, it’s like this setting and NOT the Vera causing it. :slight_smile:

Hello, Tlex.
You can catch the replies from the TV using tcp:receive.

For ex.

local response = tcp:receive();
return response

If TV is ON - Code returned: *SAPOWR0000000000000001
If TV is OFF - Code returned: *SAPOWR0000000000000000

I realise this is an older thread, but I am trying to add my Sony kd=55x9005c tv from my Vera - only simple Turn ON and Turn OFF Commands. I have all the settings on the TV as per the above and I can control the TV from an app on the phone.

I have searched numerous threads on this topic but cannot get the TV to either Wake on Lan using a WOL Plugin nor turn on or off using LUA code.

TBH, I thought this would have been very simple to add the HTTP Post code to a LUA script in a scene which could be triggered by a switch or a timer etc.

Any help greatly appreciated. Thanks