Sony TV REST API

[quote=“Styxman, post:19, topic:191302”]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]

Is it possible that you haven’t set a static IP for your TV on your LAN in your router settings and the TV is being assigned a new address? Just a thought.

[quote=“Quixote, post:21, topic:191302”][quote=“Styxman, post:19, topic:191302”]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]

Is it possible that you haven’t set a static IP for your TV on your LAN in your router settings and the TV is being assigned a new address? Just a thought.[/quote]

I tend to leave my devices on DHCP and set up the router to assign IP addresses based on that device’s MAC address. It seems some devices prefer DHCP but I prefer to know it’s IP address is the same when connected.

http://www.eventghost.net/forum/viewtopic.php?f=9&t=6067 and
Forums : Sony TV HTTP control have some really good info on the matter.

@conchordian

TY for linking to the eventghost website for this. I wanted to touch base on it a little bit. As we all know the Vera is very handicapped in the resources department so it is always a wise decision to keep the “extras” off of it. Through the use of virtual switches you can use the EventGhost plugin for the Vera EventGhost plugin for the Vera. the virtual switches will create “events” or notifications in EventGhost when it’s status changes on the Vera. because of this you can then point that event to perform some specific task. In this case you would have the EventGhost plugin for Sony Bravia TV’s. installed into EventGhost and you can marry the state change of a virtual switch to a specific remote control function.

I am currently in the process of writing a whole API for the Sony TV’s. this is a very long process as none of the API is really documented. But I do believe I have the most complete API available these TV’s. It does everything right down to getting playing content information turning the TV on properly. as well as starting and stopping Android applications and listing installed applications along with grabbing the applications icon (application features only available on android versions of the TV) If you have a TV and you are familiar with Python and want to help/test please drop a line in my Sony API GitHub repository. This could also help someone if they want to port it over to the Vera as well. The API is not yet complete as there are some things that i wish to change with it. But it does have TV auto discovery supports pre shared keys as well as pin input. automatic grabbing of the MAC address if your TV needs a WOL to turn it on. it will automatically change the WOL setting on the TV if it has to use it and it’s turned off. You can also list and play content on a USB device. Get the station names and playing content of a station. set recording schedules. Honestly i can’t even remember what else. Quite possibly if I get some help with it I would get out of being burnt out with working on it. and it will spark some new ideas on how to solve some issues. Would help to deliver a complete API quicker.

Thanks again and look for an update to this in the coming months

Hi kdschlosser,

Nice to see bright people making progress on things like this.
One thing I would like to point out, though, is that the Vera – as limited as it is – makes a great stand-alone controller for people that take trips and bring their computers with them. For that reason, it would be good to have a plugin that resides solely on the Vera. I fully understand that software solutions like EventGhost and Girder are waaay more powerful and versatile, but when I take off for a couple of weeks, I bring my laptop and leave my Vera and Elk alarm system to look after my place. Granted, television control would be a pretty elaborate method to feign occupancy, it would also be very convincing.
Please take this into consideration and thanks for your much appreciated efforts.

yes the Vera is a standalone controller. But you have to remember it is a standalone ZWave controller not a control your whole house controller. I do have a question tho if you were in another country what would be the purpose to controlling you TV that is at home? Just a question I guess. Because for those users that have no need to do such a thing it would be a complete waste of resources on the Vera to have a plugin that would allow for full control of the TV.

I have 10 security cameras and the Vera can control the security cameras. but if i put anything more then 2 or 3 of them on the Vera . the Vera has a really difficult time. just because you can doesn’t mean you should LOL. the Vera is a ZWave controller and that is what it’s design was for. all the rest of the things it can control it really shouldn’t be doing. it was never designed to handle it. I personally use it as a bridge between ZWave and the rest of my network. I have EventGhost tell the Vera to turn lights on or off and the Vera sends state changes back to EventGhost.

for the willing programmer they could port it over to the Vera if they wanted to. I am more then happy to explain how it works

[quote=“kdschlosser, post:26, topic:191302”]yes the Vera is a standalone controller. But you have to remember it is a standalone ZWave controller not a control your whole house controller. I do have a question tho if you were in another country what would be the purpose to controlling you TV that is at home? Just a question I guess. Because for those users that have no need to do such a thing it would be a complete waste of resources on the Vera to have a plugin that would allow for full control of the TV.

I have 10 security cameras and the Vera can control the security cameras. but if i put anything more then 2 or 3 of them on the Vera . the Vera has a really difficult time. just because you can doesn’t mean you should LOL. the Vera is a ZWave controller and that is what it’s design was for. all the rest of the things it can control it really shouldn’t be doing. it was never designed to handle it. I personally use it as a bridge between ZWave and the rest of my network. I have EventGhost tell the Vera to turn lights on or off and the Vera sends state changes back to EventGhost.

for the willing programmer they could port it over to the Vera if they wanted to. I am more then happy to explain how it works[/quote]

Your question is legit for people that live alone. But, what about when multiple people live in the house and only one is out of the house and has the computer with them? Those that aren’t traveling lose the ability to control the TV with Vera?

How about the people that turn the TV on for pets? What if they want a way to turn it on automatically while they’re away? Or off?

How about someone that travels and wants to be able to turn the TV on and off while they aren’t home for theft deterrence?

You’re being very short-sighted with the assumptions you’re making about why it doesn’t need to be self-contained on the Vera.

Well, it’s a valid question and ember1205 has thought it through even more than I have, but my intention was to treat the TV as another light that would follow my regular schedule and maybe even control the volume so that it is lower after a certain time. Little details like this would fool most potential thieves. Anyone can pick up light timers at the local hardware store but few realize that a TV could be controlled similarly. A system like this would even fool my neighbors into believing I’m home. I’m not willing to buy another laptop just for this functionality.
To send out commands to the TV from the Vera would be a trivial task, resource-wise. It’s no different than controlling an Internet-connected light. Most of us do not live in mansions and control 100s of lights.

You could also use a ZWave outlet in combination with a fake TV…

https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=fake+tv

Just sayin’ :slight_smile:

Well, I’m not about to shell out 90 bucks for a fake TV and a Zwave appliance module when I have everything I need already, aside from the plugin itself. Besides, I’m pretty sure the fake TV doesn’t broadcast TV audio.
Worst case scenario I would just take the time to create scripts instead of using a plugin.

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

[quote=“Derek Macias, post:20, topic:191302”][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 = "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.[/quote]

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!

Hi,

Very good job! Now i can control my new tv Sony KD-65AF8 with Vera!
I make a virtual switch to control On and Off TV.
Now when i go “away” i’m sure the Tv is Off and when i make “Tv mode” all light off and TV On.

Thank you very very mutch

[quote=“mnasri.jamaluddin, post:32, topic:191302”][quote=“Derek Macias, post:20, topic:191302”][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.[/quote]

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![/quote]

Sorry it has been a while since I messed with it. I was messing around with making a plugin using another as a template but this is what I had from the lua file. I didn’t look into it more since I just turn the tv on and off using scenes and lua.

local command = {
    ["Num1"]="AAAAAQAAAAEAAAAAAw",
    ["Num2"]="AAAAAQAAAAEAAAABAw",
    ["Num3"]="AAAAAQAAAAEAAAACAw",
    ["Num4"]="AAAAAQAAAAEAAAADAw",
    ["Num5"]="AAAAAQAAAAEAAAAEAw",
    ["Num6"]="AAAAAQAAAAEAAAAFAw",
    ["Num7"]="AAAAAQAAAAEAAAAGAw",
    ["Num8"]="AAAAAQAAAAEAAAAHAw",
    ["Num9"]="AAAAAQAAAAEAAAAIAw",
    ["Num0"]="AAAAAQAAAAEAAAAJAw",
    ["Num11"]="AAAAAQAAAAEAAAAKAw",
    ["Num12"]="AAAAAQAAAAEAAAALAw",
    ["Enter"]="AAAAAQAAAAEAAAALAw",
    ["GGuide"]="AAAAAQAAAAEAAAAOAw",
    ["ChannelUp"]="AAAAAQAAAAEAAAAQAw",
    ["ChannelDown"]="AAAAAQAAAAEAAAARAw",
    ["VolumeUp"]="AAAAAQAAAAEAAAASAw",
    ["VolumeDown"]="AAAAAQAAAAEAAAATAw",
    ["Mute"]="AAAAAQAAAAEAAAAUAw",
    ["TvPower"]="AAAAAQAAAAEAAAAVAw",
    ["Audio"]="AAAAAQAAAAEAAAAXAw",
    ["MediaAudioTrack"]="AAAAAQAAAAEAAAAXAw",
    ["Tv"]="AAAAAQAAAAEAAAAkAw",
    ["Input"]="AAAAAQAAAAEAAAAlAw",
    ["TvInput"]="AAAAAQAAAAEAAAAlAw",
    ["TvAntennaCable"]="AAAAAQAAAAEAAAAqAw",
    ["WakeUp"]="AAAAAQAAAAEAAAAuAw",
    ["PowerOff"]="AAAAAQAAAAEAAAAvAw",
    ["Sleep"]="AAAAAQAAAAEAAAAvAw",
    ["Right"]="AAAAAQAAAAEAAAAzAw",
    ["Left"]="AAAAAQAAAAEAAAA0Aw",
    ["SleepTimer"]="AAAAAQAAAAEAAAA2Aw",
    ["Analog2"]="AAAAAQAAAAEAAAA4Aw",
    ["TvAnalog"]="AAAAAQAAAAEAAAA4Aw",
    ["Display"]="AAAAAQAAAAEAAAA6Aw",
    ["Jump"]="AAAAAQAAAAEAAAA7Aw",
    ["PicOff"]="AAAAAQAAAAEAAAA+Aw",
    ["PictureOff"]="AAAAAQAAAAEAAAA+Aw",
    ["Teletext"]="AAAAAQAAAAEAAAA/Aw",
    ["Video1"]="AAAAAQAAAAEAAABAAw",
    ["Video2"]="AAAAAQAAAAEAAABBAw",
    ["AnalogRgb1"]="AAAAAQAAAAEAAABDAw",
    ["Home"]="AAAAAQAAAAEAAABgAw",
    ["Exit"]="AAAAAQAAAAEAAABjAw",
    ["PictureMode"]="AAAAAQAAAAEAAABkAw",
    ["Confirm"]="AAAAAQAAAAEAAABlAw",
    ["Up"]="AAAAAQAAAAEAAAB0Aw",
    ["Down"]="AAAAAQAAAAEAAAB1Aw",
    ["ClosedCaption"]="AAAAAgAAAKQAAAAQAw",
    ["Component1"]="AAAAAgAAAKQAAAA2Aw",
    ["Component2"]="AAAAAgAAAKQAAAA3Aw",
    ["Wide"]="AAAAAgAAAKQAAAA9Aw",
    ["EPG"]="AAAAAgAAAKQAAABbAw",
    ["PAP"]="AAAAAgAAAKQAAAB3Aw",
    ["TenKey"]="AAAAAgAAAJcAAAAMAw",
    ["BSCS"]="AAAAAgAAAJcAAAAQAw",
    ["Ddata"]="AAAAAgAAAJcAAAAVAw",
    ["Stop"]="AAAAAgAAAJcAAAAYAw",
    ["Pause"]="AAAAAgAAAJcAAAAZAw",
    ["Play"]="AAAAAgAAAJcAAAAaAw",
    ["Rewind"]="AAAAAgAAAJcAAAAbAw",
    ["Forward"]="AAAAAgAAAJcAAAAcAw",
    ["DOT"]="AAAAAgAAAJcAAAAdAw",
    ["Rec"]="AAAAAgAAAJcAAAAgAw",
    ["Return"]="AAAAAgAAAJcAAAAjAw",
    ["Blue"]="AAAAAgAAAJcAAAAkAw",
    ["Red"]="AAAAAgAAAJcAAAAlAw",
    ["Green"]="AAAAAgAAAJcAAAAmAw",
    ["Yellow"]="AAAAAgAAAJcAAAAnAw",
    ["SubTitle"]="AAAAAgAAAJcAAAAoAw",
    ["CS"]="AAAAAgAAAJcAAAArAw",
    ["BS"]="AAAAAgAAAJcAAAAsAw",
    ["Digital"]="AAAAAgAAAJcAAAAyAw",
    ["Options"]="AAAAAgAAAJcAAAA2Aw",
    ["Media"]="AAAAAgAAAJcAAAA4Aw",
    ["Prev"]="AAAAAgAAAJcAAAA8Aw",
    ["Next"]="AAAAAgAAAJcAAAA9Aw",
    ["DpadCenter"]="AAAAAgAAAJcAAABKAw",
    ["CursorUp"]="AAAAAgAAAJcAAABPAw",
    ["CursorDown"]="AAAAAgAAAJcAAABQAw",
    ["CursorLeft"]="AAAAAgAAAJcAAABNAw",
    ["CursorRight"]="AAAAAgAAAJcAAABOAw",
    ["ShopRemoteControlForcedDynamic"]="AAAAAgAAAJcAAABqAw",
    ["FlashPlus"]="AAAAAgAAAJcAAAB4Aw",
    ["FlashMinus"]="AAAAAgAAAJcAAAB5Aw",
    ["AudioQualityMode"]="AAAAAgAAAJcAAAB7Aw",
    ["DemoMode"]="AAAAAgAAAJcAAAB8Aw",
    ["Analog"]="AAAAAgAAAHcAAAANAw",
    ["Mode3D"]="AAAAAgAAAHcAAABNAw",
    ["DigitalToggle"]="AAAAAgAAAHcAAABSAw",
    ["DemoSurround"]="AAAAAgAAAHcAAAB7Aw",
    ["*AD"]="AAAAAgAAABoAAAA7Aw",
    ["AudioMixUp"]="AAAAAgAAABoAAAA8Aw",
    ["AudioMixDown"]="AAAAAgAAABoAAAA9Aw",
    ["PhotoFrame"]="AAAAAgAAABoAAABVAw",
    ["Tv_Radio"]="AAAAAgAAABoAAABXAw",
    ["SyncMenu"]="AAAAAgAAABoAAABYAw",
    ["Hdmi1"]="AAAAAgAAABoAAABaAw",
    ["Hdmi2"]="AAAAAgAAABoAAABbAw",
    ["Hdmi3"]="AAAAAgAAABoAAABcAw",
    ["Hdmi4"]="AAAAAgAAABoAAABdAw",
    ["TopMenu"]="AAAAAgAAABoAAABgAw",
    ["PopUpMenu"]="AAAAAgAAABoAAABhAw",
    ["OneTouchTimeRec"]="AAAAAgAAABoAAABkAw",
    ["OneTouchView"]="AAAAAgAAABoAAABlAw",
    ["DUX"]="AAAAAgAAABoAAABzAw",
    ["FootballMode"]="AAAAAgAAABoAAAB2Aw",
    ["iManual"]="AAAAAgAAABoAAAB7Aw",
    ["Netflix"]="AAAAAgAAABoAAAB8Aw",
    ["Assists"]="AAAAAgAAAMQAAAA7Aw",
    ["FeaturedApp"]="AAAAAgAAAMQAAABEAw",
    ["FeaturedAppVOD"]="AAAAAgAAAMQAAABFAw",
    ["GooglePlay"]="AAAAAgAAAMQAAABGAw",
    ["ActionMenu"]="AAAAAgAAAMQAAABLAw",
    ["Help"]="AAAAAgAAAMQAAABNAw",
    ["TvSatellite"]="AAAAAgAAAMQAAABOAw",
    ["WirelessSubwoofer"]="AAAAAgAAAMQAAAB+Aw"
}

local SONY_IP = "xx.xx.xx.xx" --luup.devices[lul_device].ip
local AUTH_CODE = "password" --luup.devices[lul_device].authkey

function SendCommand(Command)
    local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
    local http = require("socket.http")
    local ltn12 = require("ltn12")
    local response = {}
    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[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(response),
            redirect = false
        }
    )
    luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(response,"") or "NIL").."]")
end

function SetPower(Status)
    local SONY_URL = "http://"..SONY_IP.."/sony/system"
    local http = require("socket.http")
    local ltn12 = require("ltn12")
    local respBody = {}
    local REQUEST = '{"method":"setPowerStatus","version":"1.0","params":[{"status":'..Status..'}],"id":102}'

    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"] = "application/json",
                ["Content-Length"] = tostring(#REQUEST),
            },
            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

function GetPowerStatus()
    local SONY_URL = "http://"..SONY_IP.."/sony/system"
    local http = require("socket.http")
    local ltn12 = require("ltn12")
    local respBody = {}
    local REQUEST =  '{"id":20,"method":"getPowerStatus","version":"1.0","params":[]}'

    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
        }
    )
    response = (table.concat(respBody,"") or "NIL")
    luup.log("http response - code ["..(rCode or "NIL").."] html ["..response.."]")

    if string.find(response, '{"status":"active"}') then
        return 'active'
    elseif string.find(response, '{"status":"standby"}') then
        return 'standby'
    else
        return 'unknown'
    end
end

This is directly from a scene to turn the tv off


local SONY_IP = "xxx.xxx.xxx.xxx" --luup.devices[lul_device].ip
local AUTH_CODE = "password" --luup.devices[lul_device].authkey

function SetPower(Status)
    local SONY_URL = "http://"..SONY_IP.."/sony/system"
    local http = require("socket.http")
    local ltn12 = require("ltn12")
    local respBody = {}
    local REQUEST = '{"method":"setPowerStatus","version":"1.0","params":[{"status":'..Status..'}],"id":102}'

    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"] = "application/json",
                ["Content-Length"] = tostring(#REQUEST),
            },
            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

SetPower("false")

A plugin would be pretty kick-ass!
It would be very useful to set variables that track the state of the television, including power/display state, input, volume, channel, etc. We could then use our IR equipment to watch for remote signals and adjust the variables accordingly. I used to use a similar method years ago when I was relying on Girder to do the heavy lifting in my automation setup. It rarely had issues.
Thanks for helping us out with this stuff. Wish I was capable of contributing. :confused: