Filter sensors and the zero value

Okay. So…How do I get round this please?

I have tried using a time_pattern trigger but I can’t work out how to incorporate filters into the code:

template:
  - trigger:
      - platform: time_pattern
        seconds: /20
    sensor:
      - name: Import Power Filtered
        unique_id: import_power_filtered
        unit_of_measurement: "W"
        state_class: measurement
        state: "{{ states('sensor.givtcp_sa2236g166_import_power')|float(0) }}"

That is as far as I can get but I want to do an average. Do I have to code one myself in the template?