If you are powering the esp from a different source than the fan then yes. You need a common ground as a reference for the pwm signal.
If you are powering the esp from a different source than the fan then yes. You need a common ground as a reference for the pwm signal.