Replicate Average Sensor HACS integration

Hi, since the development of the Average Sensor HACS integration seems to be stalled, I’d like to replicate it’s functionality for my temp sensors. (and I had a few hiccups as well, where the average sensor’s output dropped to zero, even though the temperature sensor’s output that’s being averaged, didn’t show this drop)

Currently it calculates the average of the values of entity sensor.mi_li_room_f33b_temperature from the last 3 minutes, and refreshes the value every 30 seconds.

The Average Sensor settings look like this in the config yaml:

  - platform: average
    name: Average MI_Li_Room Temperature
    duration:
    minutes: 3
    precision: 1
    entities:
      - sensor.mi_li_room_f33b_temperature

How would a template sensor look like?