Help creating a template to track energy only over a certain threshold

I have a sensor for solar energy produced " sensor.solax_pv_power_total ".
I would like to use that but if it is a value higher than 3700W to track (as in a meter) how much is produced.

Use case, I have an oversized solar array of around 5500W. If I avoid the storage battery being full, at certain sweet spots in the day I can generate up to that 5500W from my panels. BUT if the battery is full then the inverter maxes out at 3700W. Wasting potentially 1800W of energy.

I am interested to see how much that is over some periods of time. I can then figure out if it is such a small amount that I am not getting the benefit from.

If for example (not often or likely) I could in theory generate 5500W for an hour continuously, but only generate 3700W, I know there was opportunity for 1800W more, or 1,8 kWh. It may be worth spending some time trying to take advantage of this by changing how I charge the storage battery dependant on forecast etc.

It might end up being so small that I just CBA!

Can I get any pointers? If I get a reading then I can add a utility meter helper to it.

Going to be something like If its over 3700 then record the value -3700. If it is under 3700 then record 0.

Think I have cracked it. I have set using 3760 which is my inverter specs.

I have made a package file as have some others. THis once is called oversized_pv_array.yaml.
Includes the sensor, the integration (riemann sum integral) and the utility meter all in one file.

  - sensors:
      pv_power_oversized_array:
        friendly_name: "Power from oversized array"
        value_template: >-
          {% set actual_power = states('sensor.solax_pv_power_total') | float %}
          {% if actual_power < 3760 %}
            0
          {% else %}
            {{ actual_power - 3760 }}
          {% endif %}
        unit_of_measurement: "W"
# All set up 25th April 2024 so readings not recognised before this
sensor:

  - platform: integration
    source: sensor.pv_power_oversized_array
    name: pv_oversized_total
    unit_prefix: k
    round: 2
    method: left


utility_meter:

  pv_oversized_hourly:
    source: sensor.pv_oversized_total
    name: PV Oversized - This Hour
    cycle: hourly

  pv_oversized_daily:
    source: sensor.pv_oversized_total
    name: PV Oversized - Day
    cycle: daily

  pv_oversized_week:
    source: sensor.pv_oversized_total
    name: PV Oversized - Week
    cycle: weekly

  pv_oversized_month:
    source: sensor.pv_oversized_total
    name: PV Oversized - Month
    cycle: monthly

  pv_oversized_year:
    source: sensor.pv_oversized_total
    name: PV Oversized - Year
    cycle: yearly

type or paste code here