Sometimes the addressee is physically close but inattentive. The speaker may present that lack of attention as a kind of distance and use a particle conventionally suited to someone far away.
يَا صَدِيقِي، انْتَبِهْ
O my friend, pay attention.
If the friend is sitting nearby yet listening poorly, yā may suit the idea of distance in attention. The surrounding situation gives the call its point.
Not every occurrence of yā must be analyzed this way. Inattention is a contextual reading, not an automatic property of the particle.