Tesla + Zappi + AlphaESS battery + Octopus combo

I’d like to know if anyone has the same hardware as me and if they have automated the “Car drains the battery first when on the cheap tariff” issue.
I know the best solution is to have the charger feed upstream of the battery input, but it’s too late for that now. So I currently have to set the car to only charge at times I know the cheap tariff will be and this misses out on the non-scheduled cheap tariff times.
I’d ideally like to automate the process so that:
(IF the car is charging (controlled by Octopus)
OR the battery SOC < 100%)
AND the tariff is cheap
THEN stop the battery from discharging.
The opposite action would be simpler:
(IF the car is not charging
AND the battery SOC =100%)
OR the tariff is not cheap
THEN allow the battery to discharge.

I anticipate that the logic will be more complicated than that but has anyone implemented similar logic with the same hardware endpoints?