Automatically schedule switch active time upfront

Hello,

I’m trying to solve this puzzle of aligning spot electricity prices with scheduled car charging. I have an integration that updates a sensor approximately 24 hours in advance with spot electricity prices. Using this data, combined with the current percentage of car battery charge and the set charge limit of the car, I can compute the number of minutes the car should charge in each hour to reach the set limit within a predetermined number of hours.

My primary challenge is setting up a binary switch entity’s schedule in advance. This switch would then control the car charger. Is there a method to schedule the switch in advance with precision down to minutes?

For illustration: If I need to charge 15kWh and with my charging rate of roughly 10kW, it equates to about 1 hour and 30 minutes of charging. As electricity prices vary throughout the day, with the most economical prices between 4 am to 5 am, and the next best from 1 am to 2 am. Given this, I need a schedule that turns on the charger from 1:00 am to 1:30 am and then from 4:00 am to 5:00 am. This plan has to be recalculated each time the car connects to the home charger (I can detect this).

Any ideas on how to approach switch scheduling within Home Assistant?

Thank you!

I was managing this manually by calculating appropriate times for charging in an automation and toggling the charger on/off whenever the price changed. However, I’m currently looking at this, which seems promising: GitHub - jonasbkarlsson/ev_smart_charging: Electric vehicle smart charging for Home Assistant.