The problem with the method you're following is that it assumes that LMCE is in complete control of the TV, which is not true in real life. In real life, someone may have come along and turned off the TV while LMCE thought it was on. The next time you try to use it (for example by pressing the 'menu' button on the remote), you want LMCE to recognize it is off, turn it on, and wait for any required delay before proceeding with further commands (changing inputs, etc).
I'm not sure what the TV you're using does, but my Olevia responds to the 'power status' command with a status reply when it's on, but not when it's off. So the correct functionality would be for the on command to:
Send a 'Power Status' command;
while (some_short_timeout)
{
if (TV replies with 'Power Status ON')
{
exit;
}
}
Send 'TV On' command;
Wait_for_timeout_period;
There's a good implementation of a TV GSD here:
http://wiki.linuxmce.org/index.php/LG_42LB5DI'm not very experienced at using ruby, so I still have to figure out how to do the above as a GSD, but I'll be doing so shortly