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

Offline asdf1nit

  • Newbie
  • *
  • Posts: 14
  • Karma: +2/-0
Re: Sony TV REST API
« Reply #15 on: March 19, 2017, 05:20:39 pm »
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.
This should work on all of the current Bravia series that use this protocol. All the way back to the A series in 2013

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

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.

Offline Quixote

  • Full Member
  • ***
  • Posts: 241
  • Karma: +8/-32
Re: Sony TV REST API
« Reply #16 on: March 20, 2017, 12:16:24 am »
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.
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline Quixote

  • Full Member
  • ***
  • Posts: 241
  • Karma: +8/-32
Re: Sony TV REST API
« Reply #17 on: March 21, 2017, 04:31:25 pm »
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!

My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline Styxman

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-2
Re: Sony TV REST API
« Reply #18 on: June 29, 2017, 05:46:38 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.

Offline Derek Macias

  • Sr. Newbie
  • *
  • Posts: 35
  • Karma: +4/-0
Re: Sony TV REST API
« Reply #19 on: June 30, 2017, 05:50:51 am »
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.

Offline Quixote

  • Full Member
  • ***
  • Posts: 241
  • Karma: +8/-32
Re: Sony TV REST API
« Reply #20 on: August 05, 2017, 01:39:14 am »
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.

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.
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 799
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: Sony TV REST API
« Reply #21 on: August 05, 2017, 12:24:21 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.

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.

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.
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline conchordian

  • Sr. Member
  • ****
  • Posts: 304
  • Karma: +4/-1