My start_charging_time was set as 15.5 as the time to charge time was only 30 mins. Peak was 16 and local_time.hour was 15, so the code never triggered.
I have made the following change on my code so that time to full charge will be a minimum of 1:
time_to_full_charge = max(1, remaining_energy_kWh / max_charge_rate_kW)