Sony TV REST API

So this has been bought over here from the “what did you do with your vera today” thread as think I was annoying a few people over there… but cybrmage was helping me out - so hopefully he will find me here…

I have a curl script which works but want to get into a function

curl --silent -XPOST http://192.168.1.xxx/sony/IRCC -d "<?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>"AAAAAQAAAAEAAAATAw=="</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' -H "Cookie: auth=xxx" -o /dev/null

I have updated the URL in the below as with the original reccomendation i got a 404 and the url below is the one i use in a curl scripts which works

so essentially I want to send commands from my vera to my Sony Bravia 2015 android tv.

[code]local http = require(“socket.http”)
local ltn12 = require(“ltn12”)
local respBody = {}
local SONY_IP = “192.168.1.225”
local AUTH_CODE = “75071BA72588155AD9FABC47EBDD353BA4ED40D7”
local IRCC_CODE = “AAAAAQAAAAEAAAAUAw==”
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">”
REQUEST=REQUEST … IRCC_CODE
REQUEST = REQUEST…“</u:X_SendIRCC></s:Body></s:Envelope>”
local SONY_URL = “http://”…SONY_IP…“/local_api.php?getDeviceList=true”

rBody, rCode, rHeaders, rStatus = http.request(
{
method = “POST”,
url = SONY_URL,
headers = {
[“Content-Type”] = “text/xml; charset=UTF-8”,
[“SOAPACTION”] = “urn:schemas-sony-com:service:IRCC:1#X_SendIRCC”,
[“Cookie”] = “auth=”…AUTH_CODE
},
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”)…“]”)
[/code]

i get the following in the log

[code]0 02/27/16 21:19:12.518 luup_log:0: http response - code [500] html [

xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">


  s:Client
  UPnPError
  
    
      401
      Invalid Action

] <0x71dd2520>
04 02/27/16 21:19:20.209 <0x769d2520>
02 02/27/16 21:19:20.209 Device_Basic::AddPoll 10 poll list ful[/code]

The URL in the script is the original URL from your original request…

You need to update it to point to the IRCC endpoint (the current URL points to a UPnP endpoint)

Also, I’m not sure about the auth header… A quick search shows it should be “X-Auth-PSK”, not “Cookie”. And, looking at the code I wrote for my Samsung TV (which also uses SOAP), the SOAP requests may need more headers (which may have been automatically added by curl command from the command prompt)…

Try:

local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local SONY_IP = "192.168.1.225"
local AUTH_CODE = "75071BA72588155AD9FABC47EBDD353BA4ED40D7"
local IRCC_CODE = "AAAAAQAAAAEAAAAUAw=="
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>"..IRCC_CODE.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"

rBody, rCode, rHeaders, rStatus = http.request(
	{
		method = "POST",
		url = SONY_URL,
		headers = { 
			["Host"] = SONY_IP,
			["Content-Type"] = "text/xml; charset=\"UTF-8\"0",
			["Content-Length"] = tostring(#REQUEST)
			["SOAPACTION"] = "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC",
			["X-Auth-PSK"] = AUTH_CODE,
			["Cookie"] = "auth="..AUTH_CODE
		},
		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").."]")

hmmm, the auth code seems to be a mix between the type of tv. running from curl it works fine with the cookie but never the PSK (pre shared key version)

tried with both as per below commenting out each option and still no joy.

[code]local http = require(“socket.http”)
local ltn12 = require(“ltn12”)
local respBody = {}
local SONY_IP = “192.168.1.225”
local AUTH_CODE1 = “1111”
local AUTH_CODE = “75071BA72588155AD9FABC47EBDD353BA4ED40D7”
local IRCC_CODE = “AAAAAQAAAAEAAAAUAw==”
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">”…IRCC_CODE…“</u:X_SendIRCC></s:Body></s:Envelope>”
local SONY_URL = “http://”…SONY_IP…“/sony/IRCC”

rBody, rCode, rHeaders, rStatus = http.request(
{
method = “POST”,
url = SONY_URL,
headers = {
[“Host”] = SONY_IP,
[“Content-Type”] = “text/xml; charset="UTF-8"0”,
[“Content-Length”] = tostring(#REQUEST),
[“SOAPACTION”] = “urn:schemas-sony-com:service:IRCC:1#X_SendIRCC”,
[“X-Auth-PSK”] = AUTH_CODE1,
–[“Cookie”] = “auth=”…AUTH_CODE
},
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”)…“]”)[/code]
always see the same error in the log

[code]50 02/28/16 20:23:03.974 luup_log:0: http response - code [500] html [

xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">


  s:Client
  UPnPError
  
    
      401
      Invalid Action

] <0x70f85520>[/code]

edit-- so seems like an authorization issue. I have actually just got the PSK to work via curl but it is passed in a different way

-H "X-Auth-PSK:1111" vs -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"'

i dont really understand the construct here but guessing is it something to do with the x-auth not being a defined something or other and just need to send the whole thing as a header - sorry if im not making sense, i made an observation and am guessing…

They was some previous comments a while ago which eluded to another forum.

https://www.domoticz.com/forum/viewtopic.php?t=8301

yeah i saw all this but they just seem to be sending the curl command - i know im close with this, just this slight issue need to get past…

Ok… so… The curl command work… Modify the curl command… change “–silent” to “-v -v”,run the command and post the output… It should show exactly what is going on with the curl command and we can see how it differs from the http.request…

here we are

[code] curl -v -v -XPOST http://192.168.1.225/sony/IRCC -H “X-Auth-PSK:11
11” -d “<?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">"
AAAAAQAAAAEAAAAUAw==“</u:X_SendIRCC></s:Body></s:Envelope>” -H ‘Conte
nt-Type: text/xml; charset=UTF-8’ -H ‘SOAPACTION: “urn:schemas-sony-com:service:
IRCC:1#X_SendIRCC”’

  • About to connect() to 192.168.1.225 port 80 (#0)
  • Trying 192.168.1.225…
  • Adding handle: conn: 0x50570
  • Adding handle: send: 0
  • Adding handle: recv: 0
  • Curl_addHandleToPipeline: length: 1
    • Conn 0 (0x50570) send_pipe: 1, recv_pipe: 0
  • Connected to 192.168.1.225 (192.168.1.225) port 80 (#0)

POST /sony/IRCC HTTP/1.1
User-Agent: curl/7.32.0
Host: 192.168.1.225
Accept: /
X-Auth-PSK:1111
Content-Type: text/xml; charset=UTF-8
SOAPACTION: “urn:schemas-sony-com:service:IRCC:1#X_SendIRCC”
Content-Length: 291

  • upload completely sent off: 291 out of 291 bytes
    < HTTP/1.1 200 OK
    < Content-Type: text/xml; charset=“utf-8”
    < Content-Length: 292
    < Connection: keep-alive
    < Date: Mon, 29 Feb 2016 14:51:30 GMT+00:00
    < Ext:
  • Server Android/5.1.1 UPnP/1.0 IRCC/1.0 is not blacklisted
    < Server: Android/5.1.1 UPnP/1.0 IRCC/1.0
    <
<?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_SendIRCCResponse xmlns:u=“urn:schemas-sony-com:service:IRCC:1”>
</u:X_SendIRCCResponse>
</s:Body>

  • Connection #0 to host 192.168.1.225 left intact
    [/code]

local SONY_IP = "192.168.1.225"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "1111"
local IRCC_CODE = "AAAAAQAAAAEAAAAUAw=="

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\">\"".. IRCC_CODE .. "\"</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"

rBody, rCode, rHeaders, rStatus = http.request(
	{
		method = "POST",
		url = SONY_URL,
		headers = { 
			["User-Agent"] = "curl/7.32.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").."]")

still getting the same error ??? ???

gave up in the end and am just using os.execute

os.execute([[curl --silent -XPOST http://ip.ip.ip.ip/sony/IRCC -H "X-Auth-PSK:****" -d "<?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>"AAAAAQAAAAEAAAAvAw=="</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"']])

I wanted to do the same thing and make a plugin and found this. Did you ever get any farther with it? I’m going to play around with this and see what I can do but I haven’t worked on the vera or with lua before so it’ll be a learning experience. I Have read all the forum post both here and for other HA platforms about doing this and even have the python and bash versions working but I really want this as a plugin to the vera.

Ok it works. There were a couple errors in the local REQUEST string. I’m going to play with this some more and try to figure out a gui and get a plugin hammered out. It’ll probably take me a little while but this function was the meat of the whole thing so thank you @trouty00 and @cybrmage for you work. I would have taken me a long while to figure that out(I couldn’t find any documentation on sending soap request).

[code]local SONY_IP = “10.0.1.5”
local SONY_URL = “http://”…SONY_IP…“/sony/IRCC”
local AUTH_CODE = “2020”
local IRCC = “AAAAAQAAAAEAAAAuAw==”

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">”…IRCC…“</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”)…“]”)[/code]

And here’s the LuaUpnp.log output

08      02/09/17 21:49:39.922   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x71e00520>
08      02/09/17 21:49:39.922   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x71e00520>
08      02/09/17 21:49:39.922   JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x71e00520>
08      02/09/17 21:49:39.923   JobHandler_LuaUPnP::HandleActionRequest argument Code=local SONY_IP = "10.0.1.5"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "2020"
local IRCC = "AAAAAQAAAAEAAAAuAw=="

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>"..IRCC.."</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").."]") <0x71e00520>
50      02/09/17 21:49:39.938   luup_log:0: http response - code [200] html [<?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_SendIRCCResponse xmlns:u="urn:schemas-sony-com:service:IRCC:1">
    </u:X_SendIRCCResponse>
  </s:Body>
</s:Envelope>] <0x71e00520>

And Just to make it easy to send commands

[code]command = {
PowerOff=“AAAAAQAAAAEAAAAvAw==”,
[“PowerOn”]=“AAAAAQAAAAEAAAAuAw==”,
[“VolumeUp”]=“AAAAAQAAAAEAAAASAw==”,
[“VolumeDown”]=“AAAAAQAAAAEAAAATAw==”,
[“Mute”]=“AAAAAQAAAAEAAAAUAw==”,
[“Input”]=“AAAAAQAAAAEAAAAlAw==”,
[“GGuide”]=“AAAAAQAAAAEAAAAOAw==”,
[“EPG”]=“AAAAAgAAAKQAAABbAw==”,
[“Favorites”]=“AAAAAgAAAHcAAAB2Aw==”,
[“Display”]=“AAAAAQAAAAEAAAA6Aw==”,
[“Home”]=“AAAAAQAAAAEAAABgAw==”,
[“Options”]=“AAAAAgAAAJcAAAA2Aw==”,
[“Return”]=“AAAAAgAAAJcAAAAjAw==”,
[“Up”]=“AAAAAQAAAAEAAAB0Aw==”,
[“Down”]=“AAAAAQAAAAEAAAB1Aw==”,
[“Right”]=“AAAAAQAAAAEAAAAzAw==”,
[“Left”]=“AAAAAQAAAAEAAAA0Aw==”,
[“Confirm”]=“AAAAAQAAAAEAAABlAw==”,
[“Red”]=“AAAAAgAAAJcAAAAlAw==”,
[“Green”]=“AAAAAgAAAJcAAAAmAw==”,
[“Yellow”]=“AAAAAgAAAJcAAAAnAw==”,
[“Blue”]=“AAAAAgAAAJcAAAAkAw==”,
[“Num1”]=“AAAAAQAAAAEAAAAAAw==”,
[“Num2”]=“AAAAAQAAAAEAAAABAw==”,
[“Num3”]=“AAAAAQAAAAEAAAACAw==”,
[“Num4”]=“AAAAAQAAAAEAAAADAw==”,
[“Num5”]=“AAAAAQAAAAEAAAAEAw==”,
[“Num6”]=“AAAAAQAAAAEAAAAFAw==”,
[“Num7”]=“AAAAAQAAAAEAAAAGAw==”,
[“Num8”]=“AAAAAQAAAAEAAAAHAw==”,
[“Num9”]=“AAAAAQAAAAEAAAAIAw==”,
[“Num0”]=“AAAAAQAAAAEAAAAJAw==”,
[“Num11”]=“AAAAAQAAAAEAAAAKAw==”,
[“Num12”]=“AAAAAQAAAAEAAAALAw==”,
[“Tv”]=“AAAAAQAAAAEAAAAkAw==”,
[“Hdmi1”]=“AAAAAgAAABoAAABaAw==”,
[“Hdmi2”]=“AAAAAgAAABoAAABbAw==”,
[“Hdmi3”]=“AAAAAgAAABoAAABcAw==”,
[“Hdmi4”]=“AAAAAgAAABoAAABdAw==”,
[“Google”]=“AAAAAgAAAMQAAAA7Aw==”,
[“ActionMenu”]=“AAAAAgAAAMQAAABLAw==”,
[“ChannelUp”]=“AAAAAQAAAAEAAAAQAw==”,
[“ChannelDown”]=“AAAAAQAAAAEAAAARAw==”,
[“SubTitle”]=“AAAAAgAAAJcAAAAoAw==”,
[“ClosedCaption”]=“AAAAAgAAAKQAAAAQAw==”,
[“Enter”]=“AAAAAQAAAAEAAAALAw==”,
[“DOT”]=“AAAAAgAAAJcAAAAdAw==”,
[“Analog”]=“AAAAAgAAAHcAAAANAw==”,
[“Teletext”]=“AAAAAQAAAAEAAAA/Aw==”,
[“Exit”]=“AAAAAQAAAAEAAABjAw==”,
[“Analog2”]=“AAAAAQAAAAEAAAA4Aw==”,
[“AD”]=“AAAAAgAAABoAAAA7Aw==”,
[“Digital”]=“AAAAAgAAAJcAAAAyAw==”,
[“Analog”]=“AAAAAgAAAJcAAAAuAw==”,
[“BS”]=“AAAAAgAAAJcAAAAsAw==”,
[“CS”]=“AAAAAgAAAJcAAAArAw==”,
[“BSCS”]=“AAAAAgAAAJcAAAAQAw==”,
[“Ddata”]=“AAAAAgAAAJcAAAAVAw==”,
[“PicOff”]=“AAAAAQAAAAEAAAA+Aw==”,
[“Tv_Radio”]=“AAAAAgAAABoAAABXAw==”,
[“Theater”]=“AAAAAgAAAHcAAABgAw==”,
[“SEN”]=“AAAAAgAAABoAAAB9Aw==”,
[“InternetWidgets”]=“AAAAAgAAABoAAAB6Aw==”,
[“InternetVideo”]=“AAAAAgAAABoAAAB5Aw==”,
[“Netflix”]=“AAAAAgAAABoAAAB8Aw==”,
[“SceneSelect”]=“AAAAAgAAABoAAAB4Aw==”,
[“Mode3D”]=“AAAAAgAAAHcAAABNAw==”,
[“iManual”]=“AAAAAgAAABoAAAB7Aw==”,
[“Audio”]=“AAAAAQAAAAEAAAAXAw==”,
[“Wide”]=“AAAAAgAAAKQAAAA9Aw==”,
[“Jump”]=“AAAAAQAAAAEAAAA7Aw==”,
[“PAP”]=“AAAAAgAAAKQAAAB3Aw==”,
[“MyEPG”]=“AAAAAgAAAHcAAABrAw==”,
[“ProgramDescription”]=“AAAAAgAAAJcAAAAWAw==”,
[“WriteChapter”]=“AAAAAgAAAHcAAABsAw==”,
[“TrackID”]=“AAAAAgAAABoAAAB+Aw==”,
[“TenKey”]=“AAAAAgAAAJcAAAAMAw==”,
[“AppliCast”]=“AAAAAgAAABoAAABvAw==”,
[“acTVila”]=“AAAAAgAAABoAAAByAw==”,
[“DeleteVideo”]=“AAAAAgAAAHcAAAAfAw==”,
[“PhotoFrame”]=“AAAAAgAAABoAAABVAw==”,
[“TvPause”]=“AAAAAgAAABoAAABnAw==”,
[“KeyPad”]=“AAAAAgAAABoAAAB1Aw==”,
[“Media”]=“AAAAAgAAAJcAAAA4Aw==”,
[“SyncMenu”]=“AAAAAgAAABoAAABYAw==”,
[“Forward”]=“AAAAAgAAAJcAAAAcAw==”,
[“Play”]=“AAAAAgAAAJcAAAAaAw==”,
[“Rewind”]=“AAAAAgAAAJcAAAAbAw==”,
[“Prev”]=“AAAAAgAAAJcAAAA8Aw==”,
[“Stop”]=“AAAAAgAAAJcAAAAYAw==”,
[“Next”]=“AAAAAgAAAJcAAAA9Aw==”,
[“Rec”]=“AAAAAgAAAJcAAAAgAw==”,
[“Pause”]=“AAAAAgAAAJcAAAAZAw==”,
[“Eject”]=“AAAAAgAAAJcAAABIAw==”,
[“FlashPlus”]=“AAAAAgAAAJcAAAB4Aw==”,
[“FlashMinus”]=“AAAAAgAAAJcAAAB5Aw==”,
[“TopMenu”]=“AAAAAgAAABoAAABgAw==”,
[“PopUpMenu”]=“AAAAAgAAABoAAABhAw==”,
[“RakurakuStart”]=“AAAAAgAAAHcAAABqAw==”,
[“OneTouchTimeRec”]=“AAAAAgAAABoAAABkAw==”,
[“OneTouchView”]=“AAAAAgAAABoAAABlAw==”,
[“OneTouchRec”]=“AAAAAgAAABoAAABiAw==”,
[“OneTouchStop”]=“AAAAAgAAABoAAABjAw==”,
[“DUX”]=“AAAAAgAAABoAAABzAw==”,
[“FootballMode”]=“AAAAAgAAABoAAAB2Aw==”,
[“Social”]=“AAAAAgAAABoAAAB0Aw==”}

function SendCommand(Command)
local SONY_IP = “10.0.1.5”
local SONY_URL = “http://”…SONY_IP…“/sony/IRCC”
local AUTH_CODE = “2020”
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">”…Command…“</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

SendCommand(command[“VolumeUp”])[/code]

great work, are you still working on a plugin or just going to use the code. will probbaly look at tweaking my lua code to incorporate this rather tan the os request i was using.

Stu

This looks pretty interesting.
What model TVs will this work with? I have a Sony KDL-55W802A that I was hoping to control over my LAN.

[quote=“Quixote, post:15, topic:191302”]This looks pretty interesting.
What model TVs will this work with? I have a Sony KDL-55W802A that I was hoping to control over my LAN.[/quote]
This should work on all of the current Bravia series that use this protocol. All the way back to the A series in 2013

[quote=“trouty00, post:14, topic:191302”]great work, are you still working on a plugin or just going to use the code. will probbaly look at tweaking my lua code to incorporate this rather tan the os request i was using.

Stu[/quote]

I’ve been working on it some in my spare time but I have a big network project that’s taking up a lot it. I’ve never made a plugin so I’m basing it around the Samsung TV plugin that I use for my other TV. I haven’t worked on anything in a couple weeks. Right now I’m just using the script os.exec way. it actually works well when called from bwsSystems hue bridge via Alexa. I’m only using power and volume commands.

Thanks!
A plugin sure would be a great help, but I’ll see what I can figure out with what’s been shared already. I only need a few functions as well.

Works like a charm! This made my day!

The only thing that I’m ever-so-slightly disappointed about is the time it takes for a command to go through (not practical for volume changes), but that could just be the Vera UI that is causing the delay. I haven’t experimented enough yet, but I’ll test other input methods.

Thanks again!

Don’t know if this thread is still alive…I installed the code provided above and it worked like a charm—for about 24 hours, now it won’t run. Seems like it’s something in Vera. Has anyone had this issue and if so, is there a fix?

Thanks.

[quote=“Styxman”]Don’t know if this thread is still alive…I installed the code provided above and it worked like a charm—for about 24 hours, now it won’t run. Seems like it’s something in Vera. Has anyone had this issue and if so, is there a fix?

Thanks.[/quote]
This is what I’m using in a few scenes.

function SendCommand(Command)
local SONY_IP = "xxx.xxx.xxx.xxx"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "password"
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

SendCommand("AAAAAQAAAAEAAAAuAw")

This is for tv power on. Just substitute your tv’s ip address. You can change the send command with the appropriate code from the array for other functions. I just moved the == to the request and I thought the array was more appropriate for a plugin and just include the command in each scene minus the ==. I don’t know if it matters but I didn’t want to include that huge array I each scene’s lua. This works fine for me using the HA bridge and alexa. It consistently turns the tv on and off and volume up and down.

I have some other functions for checking status and getting other info I can share when I get to my laptop. I can get the tv’s power status. The only thing that sucks is there’s not a function to set volume on my tv when I use curl to get a list of supported functions. E.g. You can’t set volume to a value of 20.