Intelligent Octopus automation

Hi All,

I’ve been using this Intelligent Octopus HACS integration to get information about by off peak rates when my EV is plugged in. It works great and I’m really happy with it.

To prevent my EV from charging from my batteries and draw from the grid during off-peak I automated the charging cycles on the solar storage batteries so they match the IO off-peak periods, at least, I thought I did!..

It turns out the that the OI integration sends an array of planned charging periods like so:

[ 
    { start: '2023-11-06T00:00:00+00:00', end: '2023-11-06T00:30:00+00:00' },
    { start: '2023-11-06T01:00:00+00:00', end: '2023-11-06T01:30:00+00:00' },
    { start: '2023-11-06T00:30:00+00:00', end: '2023-11-06T01:00:00+00:00' },
    { start: '2023-11-06T02:00:00+00:00', end: '2023-11-06T02:30:00+00:00' },
    { start: '2023-11-06T01:30:00+00:00', end: '2023-11-06T02:00:00+00:00' },
    { start: '2023-11-06T03:00:00+00:00', end: '2023-11-06T03:30:00+00:00' }
]

I am using a template to grab the first start time and last end time of the array.
My automation to write the charging period to the inverter requires only HH:MM

However, there are a number of scenarios I’ve overlooked and need some help to work out how I can reliably sync the inverter charging with off-peak windows from IO:

1 - Fixed off-peak is 23:30 - 05:30 every night, regardless of EV charging etc… If the EV only needs a small charge, when plugged in IO comes back with something like 0100 - 0400, which means I’ve lost out on a couple of hours of off-peak charging the solar batteries (as 0100-0400 would be written to the inverter. What would be the best way to ensure 2330-0530 is respected if the window falls within those times?

2 - The charging periods are not always concurrent. For example, I was home early today and plugged in with a nearly flat battery. The inverter programmed itself to charge from 1300 - 0700 the next day! However, on closer inspection there were several gaps in the periods (where demand on the grid is high). My logic does not account for this…

Surely someone has trodden this path before I? I would be really interested to hear what approaches others are taking.

Many thanks

Anyone, Pleasssseeeeeeee?