Author Topic: Sony TV REST API  (Read 6898 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: 249
  • Karma: +9/-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: 249
  • Karma: +9/-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

  • Sr. Newbie
  • *
  • Posts: 25
  • Karma: +1/-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: 36
  • 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: 249
  • Karma: +9/-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: 937
  • Karma: +20/-18
    • 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: 307
  • Karma: +4/-1

Offline kdschlosser

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +2/-4
Re: Sony TV REST API
« Reply #23 on: October 03, 2017, 01:49:44 pm »
@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

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Sony TV REST API
« Reply #24 on: October 04, 2017, 08:42:34 pm »
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.
 
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 kdschlosser

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +2/-4
Re: Sony TV REST API
« Reply #25 on: October 05, 2017, 11:49:09 am »
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

Offline ember1205

  • Sr. Member
  • ****
  • Posts: 386
  • Karma: +5/-21
Re: Sony TV REST API
« Reply #26 on: October 05, 2017, 01:28:35 pm »
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

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.

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Sony TV REST API
« Reply #27 on: October 15, 2017, 07:08:48 pm »
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.
« Last Edit: October 16, 2017, 12:01:42 am by Quixote »
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 ember1205

  • Sr. Member
  • ****
  • Posts: 386
  • Karma: +5/-21
Re: Sony TV REST API
« Reply #28 on: October 16, 2017, 08:10:36 am »
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'  :)

Offline Quixote

  • Full Member
  • ***
  • Posts: 249
  • Karma: +9/-32
Re: Sony TV REST API
« Reply #29 on: October 17, 2017, 03:15:18 am »
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.
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.