Immersion heater to run on export power

Hello. Complete noob with HA but I am trying to automate my immersion heater with my export power. I would like to have it automatically turn on and off when export power reaches a certain level. The basic automations are not suitable as I have a sensor for power production and power consumption but not for power export.

I need to work out the difference between the two sensors to calculate the export power. I then need the export power to go above a threshold, say 3kw, before the immersion is turned on. And then I would need the immersion to be turned off if the export power goes below a different threshold, say 0kW. I would also like this automation to only run at certain times in the day. Say between 9:00-16:00 so that it would not interfere with me running the immersion at night if there is Plunge Pricing.

I have tried to create a template to calculate the export power but I do not think this is working as I cannot find the Export_Power sensor (value) any where in HA to use it in an automation.

Please format your config for the forum: