My imp file functions and actionlist:
<functions>
function PS3Startup(lul_device)
socket = require("socket")
http = require("socket.http")
local IRDevNum = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1","IODevice",lul_device)
if (IRDevNum == nil) then
luup.log("No IR Blaster selected for PS3 control")
luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1","IODevice","1",lul_device)
end
IRDevIP = luup.devices[tonumber(IRDevNum)].ip
PS3IP = luup.devices[lul_device].ip
if (IRDevIP == nil or IRDevIP == "") then
luup.log("IP Address is required in IR Device Advanced settings")
else
if (PS3IP == nil or PS3IP == "") then
luup.log("IP Address is required in PS3 Device Advanced settings")
else
luup.log("PS3 IP Address is " .. PS3IP .. "; IR IP Address is " .. IRDevIP .. ".")
end
end
end
function SendCode(IRCode,IRRepeat)
local startTime = socket.gettime()
response, status = http.request("http://" .. IRDevIP .. "/docmnd.xml","<docommand repeat= \"" .. IRRepeat .. "\" ir_data=\"" .. IRCode .. "\"/>")
local endTime = socket.gettime()
if (response == nil) then
luup.log("Web request returned no response ProntoCode=" .. IRCode .. " in " .. math.floor((endTime - startTime) * 1000) .. "ms", 1)
end
end
function CheckPowerStatus()
local PingStatus
PingStatus = os.execute("ping -c 1 -W 1 " .. PS3IP)
if (PingStatus == 0) then
luup.log("PS3 is on")
return 1
else
luup.log("PS3 is off")
return 0
end
end
</functions>
<startup>PS3Startup</startup>
<actionList>
<action>
<serviceId>urn:micasaverde-com:serviceId:DiscretePower1</serviceId>
<name>Off</name>
<run>
local PS3Status
PS3Status = CheckPowerStatus()
if (PS3Status == 1) then
SendCode("P8bc4 e625 72b1 b3b1 7a69 46f1 da28 651f 2d47 d68f e61c 2274 001f d848 efce e679 b426 e8ff 85a7 cfba 233c cf99 1090 a06a 1fff 2a6c f7da 5c7e d1ba 155e 93d9 3bde f468 2237 73a9 4c55 6771 bf7b d9da 0193 aec3 cc87 e70c 9f58 b1cf a943 30e8 5213 d68e af8c 548c c6e0 4f81 b918 aa97 a392 ","3")
os.execute("sleep 1")
SendCode("P8bc4 e625 72b1 b3b1 7a69 46f1 da28 651f 2d47 d68f e61c 2274 001f d848 efce e679 b426 e8ff 85a7 cfba 233c cf99 1090 a06a 1fff 2a6c f7da 5c7e d1ba 155e 93d9 3bde f468 2237 73a9 4c55 6771 bf7b d9da 0193 aec3 cc87 e70c 9f58 b1cf a943 30e8 5213 d68e af8c 548c c6e0 4f81 b918 aa97 a392 ","10")
os.execute("sleep 2")
SendCode("Pd47d 909f c488 f243 2c6f 982e 882f 468b 5525 617e b0ca 87b0 4672 f738 3fd6 7621 0e9a dacf 8561 5329 37d5 7f26 e456 386f ddc2 3435 2c62 0ea6 9d25 d28d fb81 7e73 c52a 4b93 03f0 8ea6 91b5 d48d a146 d96a 4123 c470 fa84 1213 af63 27ed c747 8676 31bf 56f2 d616 f626 a09e c4f7 348b 32bc ","0")
os.execute("sleep 2")
SendCode("Pd47d 909f c488 f243 2c6f 982e 882f 468b 5525 617e b0ca 87b0 4672 f738 3fd6 7621 0e9a dacf 8561 5329 37d5 7f26 e456 386f ddc2 3435 2c62 0ea6 9d25 d28d fb81 7e73 c52a 4b93 03f0 8ea6 91b5 d48d a146 d96a 4123 c470 fa84 1213 af63 27ed c747 8676 31bf 56f2 d616 f626 a09e c4f7 348b 32bc ","0")
end
</run>
</action>
<action>
<serviceId>urn:micasaverde-com:serviceId:DiscretePower1</serviceId>
<name>On</name>
<run>
local PS3Status
PS3Status = CheckPowerStatus()
if (PS3Status == 0) then
SendCode("P8bc4 e625 72b1 b3b1 7a69 46f1 da28 651f 2d47 d68f e61c 2274 001f d848 efce e679 b426 e8ff 85a7 cfba 233c cf99 1090 a06a 1fff 2a6c f7da 5c7e d1ba 155e 93d9 3bde f468 2237 73a9 4c55 6771 bf7b d9da 0193 aec3 cc87 e70c 9f58 b1cf a943 30e8 5213 d68e af8c 548c c6e0 4f81 b918 aa97 a392 ","0")
end
</run>
</action>