Event or background?
English often uses one form, the simple past (“I lived”, “it rained”), for both. French has two past tenses and makes you choose. The choice does not depend on when something happened, but on how you see it: as an event or as background.
Passé composé - what happened
A finished event, even with a stated length of time: hier, pendant deux ans
A chain of events, one after another: d’abord, puis, ensuite
A sudden event: soudain, tout à coup
Hier, je suis allé au cinéma.
Yesterday I went to the cinema.
Il a ouvert la porte et il est entré.
He opened the door and went in.
Soudain, le téléphone a sonné.
Suddenly the phone rang.
Imparfait - what it was like
Description and state: weather, place, person, time, feeling
Habit, repetition (“used to”): toujours, souvent, d’habitude, chaque jour
Background of a scene (“was doing”): what was going on when something happened
Il faisait beau.
The weather was nice.
J’avais faim.
I was hungry.
Le dimanche, nous mangions chez mes grands-parents.
On Sundays we used to eat at my grandparents’.
Same verb, different view
Imparfait (background)
Quand j’étais jeune, j’habitais à Lyon.
When I was young, I lived in Lyon.
Passé composé (event)
J’ai habité à Lyon pendant deux ans.
I lived in Lyon for two years.
Telling a story: scene and action
In a story, the imparfait sets the scene and the passé composé moves the action forward. Often an event (passé composé) interrupts what was going on (imparfait).
Il faisait beau et Marie était dans le jardin.
The weather was nice and Marie was in the garden.
faisait / était = background (imparfait)
Soudain, elle a entendu un bruit et elle a ouvert la porte.
Suddenly she heard a noise and opened the door.
a entendu / a ouvert = events (passé composé)
Pendant que je lisais, le téléphone a sonné.
While I was reading, the phone rang.
lisais = what was going on (imparfait), a sonné = what interrupted it (passé composé)