When to use chord substitutions

I was wondering when is a good time to substitute chords or use inversions. I know how to use them but not the context that it's good for. Like i know secondary dominants can replace dominants but what's the point.