  We report modifications of the ferroelectric and electrocaloric properties of
BaTiO$_3$ by defects. For this purpose, we have combined \textit{ab
initio}-based molecular dynamics simulations with a simple model for defects.
We find that different kinds of defects modify the ferroelectric transition
temperatures and polarization, reduce the thermal hysteresis of the transition
and are no obstacle for a large caloric response. For a locally reduced
polarization the ferroelectric transition temperature and the adiabatic
response are slightly reduced. For polar defects an intriguing picture emerges.
The transition temperature is increased by polar defects and the temperature
range of the large caloric response is broadened. Even more remarkable, we find
an inverse caloric effect in a broad temperature range.
