I know it is not ideal and no one would like to visit a place on a rainy day, but here some ideas on how to spend your time and get to love the place if you have the great "luck" of getting there on a rainy weekend.
instead of heading to Starbucks or similar why not go to have coffee where the local people go? :)
As Hemingway long ago said "To go to bed at night in Madrid marks you as a little queer. [...] Nobody goes to bed in Madrid until they have killed the night. Appointments with a friend are habitually made for after midnight at the cafe" and he was completely right! Madrid is like the city that never sleeps, and even so in a weird way you never feel tired.