To those wondering - as I understand it,
يا marks that you're using the vocative.
The vocative particle
يا is used when you're directly addressing someone. It might be helpful to compare it to the vocative particle in old English:
"O" (O brother where art thou? O ye of little faith!)
In modern English, we'll often use a pause (usually represented by a comma) to indicate the vocative. Compare
"Let's eat, Grandma" and
"Let's eat Grandma". It's important to be able to distinguish between the two!
You should use it when you need to address someone. For example the phrase "how are you?" does not require "ya" because you did not address someone. But if you change it to "how are you my friend?" then it will require using "ya" because you have specified who you're talking to.