[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")