  Environmental effects and intrinsic energy-loss processes lead to
fluctuations in the operational temperature of solar cells, which can
profoundly influence their power conversion efficiency. Here we determine from
first principles the effects of temperature on the band gap and band edges of
the hybrid pervoskite CH$_3$NH$_3$PbI$_3$ by accounting for electron-phonon
coupling and thermal expansion. From $290$ to $380$ K, the computed band gap
change of $40$ meV coincides with the experimental change of $30$-$40$ meV. The
calculation of electron-phonon coupling in CH$_3$NH$_3$PbI$_3$ is particularly
intricate, as the commonly used Allen-Heine-Cardona theory overestimates the
band gap change with temperature, and excellent agreement with experiment is
only obtained when including high-order terms in the electron-phonon
interaction. We also find that spin-orbit coupling enhances the electron-phonon
coupling strength, but that the inclusion of nonlocal correlations using hybrid
functionals has little effect. We reach similar conclusions in the metal-halide
perovskite CsPbI$_3$. Our results unambiguously confirm for the first time the
importance of high-order terms in the electron-phonon coupling by direct
comparison with experiment.
