I approach this slightly differently. Using a 2 minute low pass filtered average of my total inverter output power I subtract my known house base load (450W) and the only other large load, my hot water heater actual power consumption. If the excess is greater than 2.5kW, the “excess_solar_power” template binary sensor turns on.
I then use this binary sensor to switch my ducted heat pump on or off using a “for 10 minutes” state trigger.
Using the inverter power avoids cycling that can possibly happen if monitoring the power returned to the grid (heat pump turns on , so grid return reduces, so heat pump turns off, so grid return increases… repeat).