Getting closer; the power script fails in special cases where the power is changing but the the on/off flag is off