Hello,
I am writing a device handler that allows me to control all my home theater devices. For example, when I turn off the home theater, it should turn off the the projector, and the cable box using Global Cache iTach. For some reason, there is an 8 second delay from the time the SmartThings runIn scheduler fires and the time the iTach responds with a parse() callback. This lag time is causing all sorts of problems since the commands need to fire within a certain time period of each other.
I am using the sendhubcommand() using the LAN protocol. I posted the code, the heart of the code is the RunItachCommand() at the bottom:
def ShutdownSystem()
{
log.debug(âShutdownSystemâ);
state.commandqueue = [
[function: "RunMarantzCommand", commandText: "cmd0=PutZone_OnOff%2FOFF", host: "10.0.0.51", port: "80"],
[function: "RunItachCommand", commandText: "sendir,1:1,1,38000,1,1,8,34,8,66,8,29,8,109,8,50,8,50,8,45,8,103,8,497,8,34,8,29,8,29,8,29,8,29,8,109,8,29,8,29,8,3810", host: "10.0.0.247", port: "4998"],
[function: "RunItachCommand", commandText: "sendir,1:3,1,38000,1,1,342,170,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,63,22,63,22,20,22,20,22,20,22,63,22,63,22,63,22,20,22,20,22,63,22,20,22,63,22,20,22,20,22,20,22,63,22,63,22,20,22,63,22,1738", host: "10.0.0.247", port: "4998"],
[function: "RunItachCommand", commandText: "sendir,1:3,1,38000,1,1,342,170,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,20,22,63,22,63,22,20,22,20,22,20,22,63,22,63,22,63,22,20,22,20,22,63,22,20,22,63,22,20,22,20,22,20,22,63,22,63,22,20,22,63,22,1738", host: "10.0.0.247", port: "4998"]
];
state.commandqueueindex = 0;
runIn(0, ExecuteCommandHandler, [overwrite: false])
runIn(0, ExecuteCommandHandler, [overwrite: false])
runIn(1, ExecuteCommandHandler, [overwrite: false])
runIn(2, ExecuteCommandHandler, [overwrite: false])
}
def ExecuteCommandHandler()
{
if(state.commandqueueindex < state.commandqueue.size())
{
def function = state.commandqueue[state.commandqueueindex].function;
def commandText = state.commandqueue[state.commandqueueindex].commandText;
def host = state.commandqueue[state.commandqueueindex].host;
def port = state.commandqueue[state.commandqueueindex].port;
// log.debug(commandText);
"$function"(commandText, host, port);
state.commandqueueindex = state.commandqueueindex + 1;
}
else
{
log.debug("ExecuteComandHandler duplicate run.")
}
}
private def RunItachCommand(commandText, networkIP, networkPort)
{
def hosthex = convertIPtoHex(networkIP);
def porthex = convertPortToHex(networkPort);
device.deviceNetworkId = â$hosthex:$porthexâ;
def hubAction = new physicalgraph.device.HubAction("""$commandText\r\n""", physicalgraph.device.Protocol.LAN, "$device.deviceNetworkId");
return sendHubCommand(hubAction);
}