Welcome, Hamish, to the OEM forum.
First, no, you’re not off-topic and I don’t think anyone has asked this particular question before.
I take it you’ve studied the ‘Learn’ articles about the two diverters that are written up there.
What I’m not clear about - and from what you’ve written, I don’t think you are either - is what do you want your diverter to achieve? That’s something only you can answer.
Both MartinR’s and Robin’s diverters aim for zero nett exported energy. Of course, that’s only possible while you are capable of using the energy that would otherwise be exported, and that answers the question “But what happens when the immersion cuts out because the tank is up to max temperature” - you have three choices - either you control the inverter so that you don’t generate the excess (over your present use), you find another use for it, or you export it.
Which brings us to what I think is your primary question: what algorithm should you use? Both published diverters use a very simple algorithm - they attempt to control the power diverted such that the energy balance over a shortish period of time - as determined by something we call the “energy quantum” or “energy bucket” - is zero, there’s neither a nett import nor a nett export and your meter remains static. It seems that the value of this varies between each meter make/type, but is generally around 3600 J.
So what you need to do is increase the proportion diverted when there’s a nett export, and decrease it when there’s a nett import. The rate of increase or decrease can of course itself be proportional to the power flowing, but you must make sure that you can measure the nett power flow quickly enough to avoid instability. The easiest cure for that will be to slow down the rate of change of the diverted power.
Many commercially available diverters deliberately aim for a small nett export.
That depends on what, or what else, you can measure. If you measure everything but that, then do the maths! In reality, it’s far easier and more accurate to put a c.t. on the diverted feed and measure it (which is one of the options Robin offers on his website).