Chaotic dynamics and hysteresis in thermal convection