Nonlinear resonance for dispersive equations with a potential I