You need to ring when you are still some way away, so they have time to react, and if they don't you can slow down and ring a second time. And travel at an appropriate speed for the location.
(I have an ebike, so this is especially important. Mine is a legal one: 25 km/h max, 250 W, etc. If yours is faster, this is even more important.)