Author Topic: Sony TV REST API  (Read 9211 times)

Offline kdschlosser

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +2/-5
Re: Sony TV REST API
« Reply #30 on: November 09, 2017, 01:37:42 am »
as I state once again. You are simply looking to turn it on and off. that can be done very simply by sending a WOL packet to turn it on. and a simple web command to turn it off. The vera does not have the capacity to process/store the amount of information that these TV's contain. The API i wrote accesses every last part of it right down to grabbing the Android application icons. It is able to capture the content metadata from the TV as well as the channel listings.. I do not think that there is enough memory on the vera to handle it.

and for < 40 dollars USD a PC can be purchased that would supply more then enough power and resources that would be able to handle these kinds of things.. and it's footprint is not a whole lot bigger then the vera.

I am just making a suggestion because I have seen first hand what happens when the vera gets overloaded. It actually will soft brick on ya causing a whole lot of unneeded work. The vera was purpose built as a zwave controller. the ability to add "extras" came with time. and because of how its plugin and scripting work a lot of people think that it can handle controlling every single device in a house... and this it cannot.. it can't even handle the number of devices that Mios states it can (reliably).

so my suggestion is to let the vera do what it was originally intended to do.. control zwave devices. if you want to add extremely simple things like turning a TV on and off that would be fine. But to use this whole API would surly beat the vera with a rather large stick. I posted about it so if a user that did not have a large number of plugins on their vera and not a huge amount of devices wanted to have the ability to provide a little more functionality for controlling their TV the information is there so it can be used as a guide.

In the end I am simply making a suggestion. and you and anyone else can use the information contained in the API in any fashion they choose. that is the beauty of GNU licensing




Offline mnasri.jamaluddin

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Sony TV REST API
« Reply #31 on: March 04, 2018, 12:06:24 pm »
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.
This is what I'm using in a few scenes.
Code: [Select]
function SendCommand(Command)
local SONY_IP = "xxx.xxx.xxx.xxx"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "together"
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.

Hi Derek! I found your lua code most useful to pause the TV when the doorbell rings (triggered by a z wave button).

I was wondering if you've gotten around sharing your lua code to check status of the TV. I'm looking to just have a virtual switch updated based on the TV on/off status. The idea is to cast the entrance cctv to the TV only if the TV is already switched on. If this check is not done, casting to a TV while it's off will inadvertently turn the TV on.

Really appreciate your guidance on this. Thanks!