Author Topic: Control your Sony Bravia TV from your Vera  (Read 1945 times)

Offline Tlex

  • Sr. Newbie
  • *
  • Posts: 44
  • Karma: +1/-0
Control your Sony Bravia TV from your Vera
« on: February 24, 2018, 12:20:20 pm »
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 :) )

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=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><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").."]")
end

--PowerOn the tv
SendCommand("AAAAAQAAAAEAAAAuAw")
socket.sleep(8)
--change to HDMI input
SendCommand("AAAAAgAAABoAAABaAw")
socket.sleep(8)
--set volume down
SendCommand("AAAAAQAAAAEAAAATAw")

-------------------
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 :
http://tmolberg.kpolberg.net/wp-content/uploads/2016/02/BRAVIA_B2B_SimpleIPControlProtocol_ForAndroidModels_v0.9.pdf

 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);
tcp:send("*SCPOWR0000000000000000\n");

____________________________________________

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 :)




(IRCC commands)
'Analog': 'AAAAAgAAAHcAAAANAw==',
'Audio': 'AAAAAQAAAAEAAAAXAw==',
'Blue': 'AAAAAgAAAJcAAAAkAw==',
'ChannelDown': 'AAAAAQAAAAEAAAARAw==',
'ChannelUp': 'AAAAAQAAAAEAAAAQAw==',
'Confirm': 'AAAAAQAAAAEAAABlAw==',
'Display': 'AAAAAQAAAAEAAAA6Aw==',
'Down': 'AAAAAQAAAAEAAAB1Aw==',
'EPG': 'AAAAAgAAAKQAAABbAw==',
'Exit': 'AAAAAQAAAAEAAABjAw==',
'Forward': 'AAAAAgAAAJcAAAAcAw==',
'Green': 'AAAAAgAAAJcAAAAmAw==',
'Home': 'AAAAAQAAAAEAAABgAw==',
'Input': 'AAAAAQAAAAEAAAAlAw==',
'Left': 'AAAAAQAAAAEAAAA0Aw==',
'Mute': 'AAAAAQAAAAEAAAAUAw==',
'Next': 'AAAAAgAAAJcAAAA9Aw==',
'Num0': 'AAAAAQAAAAEAAAAJAw==',
'Num1': 'AAAAAQAAAAEAAAAAAw==',
'Num2': 'AAAAAQAAAAEAAAABAw==',
'Num3': 'AAAAAQAAAAEAAAADAw==',
'Num4': 'AAAAAQAAAAEAAAADAw==',
'Num5': 'AAAAAQAAAAEAAAAEAw==',
'Num6': 'AAAAAQAAAAEAAAAFAw==',
'Num7': 'AAAAAQAAAAEAAAAGAw==',
'Num8': 'AAAAAQAAAAEAAAAHAw==',
'Num9': 'AAAAAQAAAAEAAAAIAw==',
'Options': 'AAAAAgAAAJcAAAA2Aw==',
'PAP': 'AAAAAgAAAKQAAAB3Aw==',
'Pause': 'AAAAAgAAAJcAAAAZAw==',
'Play': 'AAAAAgAAAJcAAAAaAw==',
'Prev': 'AAAAAgAAAJcAAAA8Aw==',
'Red': 'AAAAAgAAAJcAAAAlAw==',
'Return': 'AAAAAgAAAJcAAAAjAw==',
'Rewind': 'AAAAAgAAAJcAAAAbAw==',
'Right': 'AAAAAQAAAAEAAAAzAw==',
'Stop': 'AAAAAgAAAJcAAAAYAw==',
'SubTitle': 'AAAAAgAAAJcAAAAoAw==',
'SyncMenu': 'AAAAAgAAABoAAABYAw==',
'Up': 'AAAAAQAAAAEAAAB0Aw==',
'VolumeDown': 'AAAAAQAAAAEAAAATAw==',
'VolumeUp': 'AAAAAQAAAAEAAAASAw==',
'Wide': 'AAAAAgAAAKQAAAA9Aw==',
'Yellow': 'AAAAAgAAAJcAAAAnAw==',
'HDMI1': 'AAAAAgAAABoAAABaAw==',
'HDMI2': 'AAAAAgAAABoAAABbAw==',
'HDMI3': 'AAAAAgAAABoAAABcAw==',
'HDMI4': 'AAAAAgAAABoAAABdAw==',

//not tested:
'Replay': 'AAAAAgAAAJcAAAB5Aw==',
'Advance': 'AAAAAgAAAJcAAAB4Aw==',
'TopMenu': 'AAAAAgAAABoAAABgAw==',
'PopUpMenu': 'AAAAAgAAABoAAABhAw==',
'Eject': 'AAAAAgAAAJcAAABIAw==',
'Rec': 'AAAAAgAAAJcAAAAgAw==',
'ClosedCaption': 'AAAAAgAAAKQAAAAQAw==',
'Teletext': 'AAAAAQAAAAEAAAA/Aw==',
'GGuide': 'AAAAAQAAAAEAAAAOAw==',
'DOT' : 'AAAAAgAAAJcAAAAdAw==',
'Digital': 'AAAAAgAAAJcAAAAyAw==',
'BS' : 'AAAAAgAAAJcAAAAsAw==',
'CS' : 'AAAAAgAAAJcAAAArAw==',
'BSCS': 'AAAAAgAAAJcAAAAQAw==',
'Ddata': 'AAAAAgAAAJcAAAAVAw==',
'InternetWidgets': 'AAAAAgAAABoAAAB6Aw==',
'InternetVideo': 'AAAAAgAAABoAAAB5Aw==',
'SceneSelect': 'AAAAAgAAABoAAAB4Aw==',
'Mode3D' : 'AAAAAgAAAHcAAABNAw==',
'iManual' : 'AAAAAgAAABoAAAB7Aw==',
'Jump' : 'AAAAAQAAAAEAAAA7Aw==',
'MyEPG': 'AAAAAgAAAHcAAABrAw==',
'ProgramDescription': 'AAAAAgAAAJcAAAAWAw==',
'WriteChapter': 'AAAAAgAAAHcAAABsAw==',
'TrackID' : 'AAAAAgAAABoAAAB+Aw==',
'TenKey': 'AAAAAgAAAJcAAAAMAw==',
'AppliCast': 'AAAAAgAAABoAAABvAw==',
'acTVila': 'AAAAAgAAABoAAAByAw==',
'DeleteVideo': 'AAAAAgAAAHcAAAAfAw==',
'EasyStartUp': 'AAAAAgAAAHcAAABqAw==',
'OneTouchTimeRec': 'AAAAAgAAABoAAABkAw==',
'OneTouchView' : 'AAAAAgAAABoAAABlAw==',
'OneTouchRec' : 'AAAAAgAAABoAAABiAw==',
'OneTouchRecStop' : 'AAAAAgAAABoAAABjAw==',

Offline dalhoj

  • Sr. Newbie
  • *
  • Posts: 30
  • Karma: +2/-0
Re: Control your Sony Bravia TV from your Vera
« Reply #1 on: February 28, 2018, 08:21:14 am »
Cool thank you.

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

Offline crazymags

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Control your Sony Bravia TV from your Vera
« Reply #2 on: March 01, 2018, 08:37:52 pm »
I will try it myself to see if it will work. Thanks for sharing it with us.

Offline ember1205

  • Sr. Member
  • ****
  • Posts: 416
  • Karma: +5/-21
Re: Control your Sony Bravia TV from your Vera
« Reply #3 on: March 09, 2018, 08:07:56 am »
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.  :)

Offline Mobilniy

  • Jr. Member
  • **
  • Posts: 55
  • Karma: +2/-6
Re: Control your Sony Bravia TV from your Vera
« Reply #4 on: March 09, 2018, 08:14:37 am »
Hello, Tlex.
You can catch the replies from the TV using tcp:receive.

For ex.
tcp:send("*SEPOWR################\n");
local response = tcp:receive();
return response

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