How to use LUA to Control Sony Bravia TV over IP

I am trying to add my Sony kd=55x9005c tv from my Vera - only simple Turn ON and Turn OFF Commands. I have all the settings on the TV as per other threads and Sony’s instructions and I can control the TV from an app on the phone.

I have searched numerous threads on this topic but cannot get the TV to either Wake on Lan using a WOL Plugin nor turn on or off using LUA code.

TBH, I thought this would have been very simple to add the HTTP Post code to a LUA script in a scene which could be triggered by a switch or a timer etc.

Any help greatly appreciated. Thanks

Can you share the Lua code that you tried?

I have tried this:

os.execute([[curl --silent -XPOST http://192.168.1.104/sony/IRCC -H "X-Auth-PSK:1111" -d "<?xml version=\"1.0\"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="[http://schemas.xmlsoap.org/soap/encoding/ ](http://schemas.xmlsoap.org/soap/encoding/)"><s:Body><u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1">"AAAAAQAAAAEAAAAvAw=="</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"']])

And also the code here:

And this:

local socket = require "socket"
tcp = assert(socket.connect ("192.168.0.30", 20060))
tcp:send "*SCPOWR0000000000000001\n"
luup.sleep(50)
tcp:close()

I believe that part of the problem may be that the post you referenced has incorrectly formatted code, which means that double quotes have been converted to inverted commas, which will cause a syntax error in Lua.

I’'m fixing the formatting of your post, and will go to the referenced thread and try to fix things there.

You need to quote code properly in this new forum for things to work correctly.

Thanks for the response. Before I got home to check what you had suggested I found some code on another site and tried adapting it to control the TV and low and behold it worked!!!

To turn the TV on I used this:

function VeraAlert(host, port, Msg) 
  local socket = require("socket")
  local tcp = socket.tcp()
  tcp:settimeout(3)
  if (tcp:connect(host, port)) then
     if (tcp:send(Msg)) then
     else
	luup.log("Error Sending Msg")
     end
  else
     luup.log("Error Opening Socket")
  end
  tcp:close(socket)
end

VeraAlert("192.168.0.30", 20060, "*SCPOWR0000000000000001\n")
--PowerON

And to turn it off I replaced the VeraAlert Line with a 0 instead of a 1 at the end of the SCPOWR text.

Obviously 192.168.0.30 should be replaced with the IP address of your TV.

Thanks to a forum entry by @RichardTSchaefer
I hope this is useful to others.

Hello @gadgetstar, Do you have also Alexa? If yes I can propose you something easier for this case.

Anyone able to start the netflix app using this?

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy