well it was obvius that they liked each other in the 4th book,and harry said he had an inkling it might start happening and he didnt know it would messup the friendship or be to embarresed if they start snogging (kissing)in public, while in herbology.
Of course he knew. He was perfectly aware of it from Goblet of Fire on. He just thought it was none of his business, or found it weird or was (rightfully) afraid how it might affect their friendship. Plus he was also a little jealous, after all what if the two of them got together and he'd be the fifth (this case third) wheel and he'd be left out and alone.
I think that he kind of knew during the 4th book. because ron got really jelouse, and then she said that next time he should ask her out befor anyone eles so he would not be that jelouse