an expression (hoping one exists), for when you think someone is nodding, smiling, waving etc. to you, and you respond--but in fact they were addressing someone just behind you.
I believe that is called, playing second fiddle.
To Play Second Fiddle: to take a subordinate position. (Familiar - the phrase is used in familiar conversation.)
OPEC will be forced to 'play second fiddle' to the US in 2018, analyst says
I'm really sick of playing second fiddle to this ignoramus...
In an orchestra the [musician] who plays second fiddle is normally junior in both skill and seniority to the lead fiddler. The prestige of the position is therefore lower and less desirable.
But if someone does that to another person, you could say they're demoting them, which is to reassign someone to a less important role or position:
He turned around and demoted Melania.
He turned around and treated Melania to a demotion.