The Imperfect tense is primarily used for explaining actions that happened regularly in the past or for explaining characteristics and states of things in the past. For example, you would say 'había mucho calor caundo visitó España el año pasado' to say 'it was very hot when I visited Spain last year'. In the present tense, the verb form of había would be hay.
Other uses of the Imperfect tense are:- Talking about age in the past, e.g. When I was younger = Cuando era joven- Actions that triggered another in the past, e.g. 'Leía cuando volvió mi amiga = I was reading when my friend returned- Telling the time in the past, e.g. Eran las siete de la noche = it was 7 o'clock at night
On the other hand, the Preterite tense is used when you know the time frame of the action, and it had an end point For example, if you wanted to say 'Yesterday I visited my Mum', you would say 'Ayer visité a mi madre'.
It's also used when:- Describing an action that formed a chain of events, such as Se levantó, comió y salió de mi casa = She got up, ate and left my house.- Describing the beginning or end of an action, e.g. Empezó a llover a las cinco de la mañana = it started raining at 5 o'clock in the morning.