Get value difference of template sensor

I have defined a template sensor which derives its state from another sensors attribute like this:

- platform: template
  sensors:
    cat_feeding_change_wet:
      friendly_name: "Katze Nassfutter"
      unique_id: cat_feeding_change_wet
      unit_of_measurement: "g"
      value_template: >-
        {% set feeder_status_attr = state_attr('binary_sensor.pet_cat', 'status') %}
        {{ feeder_status_attr.feeding.change.0 | float }}

The attribute and therefore the template sensor show the last value all the time. But I would like to have that values for a limited amount of time (e.g. 60s) and set it to zero afterwards. This way I could easily graph the sensor and see when the cat was eating.

I already tried this automation, but it didn’t work.

- id: "1723382696795"
  alias: Reset feeding values
  description: ""
  trigger:
    - platform: numeric_state
      entity_id:
        - sensor.cat_feeding_change_dry
        - sensor.cat_feeding_change_wet
      for:
        minutes: 1
      above: 0
      below: 0
  condition: []
  action:
    - service: python_script.set_state
      data_template:
        entity_id: "{{ trigger.entity_id }}"
        state: "{{ float(0) }}"
  mode: single

What would be the best way to do this using manual yaml code? Idealy with the ability to list multiple entities to be set to 0.

I’m asking for manual yaml, because I have a bunch of those template sensors and this would allow me to adapt them by search&replace.

Feed that first template sensor to a Utility Meter Helper with a crontab of one minute.

Hi Tom,
thanks for the suggestion. Unfortunately it doesn’t work as desired.

The left side shows the original sensor from SureHA.

The central entity holds the changes in wet food, taken from the Status.feeding.change attribute. When the cat is eating its value changes and keeps this value until the cat eats the next time. This seems to work so far.

On the right side I’d expect a 2 minute long peak with 44 grams in this case, but it remains 0 all the time although the corresponding attribute shows the correct value.

In the end I’d like to have a sensor/entity which I can simply plot in a graph which roughly shows when the cat ate which amount of food. If there’s an easier way it would also be ok. I’d prefer a yaml version as this can be shared and modified easily.