I was told that one may have in mind when greeting a Gentile that one is greeting Hashem instead. Is that true?

Igro D’Pirko (O.H. 165) mentions that indeed in the above mentioned cases it is permitted to greet and have in mind addressing and saluting Hashem and it is not considered being deceitful. Chida (Shiurei Brocho 148: 6) quotes as an evidence the Talmud (Nedarim 62b) regarding one Talmid Chacham in need stating that he is a servant of the ‘Master of Fire’ when he means Hashem, although the questioning Gentiles interpret it as Avoda Zarah.