I made something in nodered already for switching between green and trade mode depending on the consumption and solar forecast, it is related to the fact trade mode doesn’t plan for 48 hours which causes grid buy the next day when the battery starts charging to late.