Reduce data history in database

Hello, i have a sensor called “sensor.pzem_powermeter_watt” that measurse the power draw from the grid every second. This results in the database getting bigger and bigger. I don’t need to keep the data measured every second but I would like to keep record every 2-3 minutes. Is it possible to do so on the database?

So now I have 60 records every minute, is it possible to create a script and edit the database to keep only 1 record per minute of the old data?

Create a template sensor with a time trigger and then record that one.

Here’s an example on taking a sensor that updates every 5 seconds and reducing that to once a minute

template:
  - trigger:
      - platform: homeassistant
        event: start
      - platform: time_pattern
        minutes: "/1"
    sensor:
      - name: "phase_a_current"
        state: "{{ states('sensor.phase_a_current_fast') }} "
        unit_of_measurement: A
        device_class: current