Irrigation Zone Water Used - Template Sensor

How can I go about creating a template sensor with the totalized volume of water (sensor.totalized_water_use) used if I know when I have an irrigation zone opened/on and closed/off (switch.zone_1)?

I would need to store the initial volume and subtract that from the current volume on the fly. I feel like I can do this with some automations and helpers, but it would be messy. Anything in the template sensor that can do this in one step?

Thanks.

This is what I’ve gotten so far, but it has some issues… It doesn’t default to zero and it doesn’t update on the fly. Otherwise, this is the functionality that I want in a single template.

template:
  - trigger:
      - platform: state
        entity_id: switch.irrigation_zone_1
        from:
          - 'off'
        to:
          - 'on'
    sensor:
      - name: "Irrigation Zone 1 Last Total Initial"
        state: "{{ states('sensor.flume_sensor_87_current_day') | float(0) }}"
        state_class: total_increasing
        unit_of_measurement: gal
        device_class: water
  - trigger:
      - platform: state
        entity_id: switch.irrigation_zone_1
        from:
          - 'on'
        to:
          - 'off'
    sensor:
      - name: "Irrigation Zone 1 Last Total"
        state: "{{ states('sensor.flume_sensor_87_current_day') | float(0) - states('sensor.Irrigation_Zone_1_Last_Total_Initial') | float(0) }}"
        state_class: total_increasing
        unit_of_measurement: gal
        device_class: water

Thought of using another trigger to update when current_day changes, but it seems like I need a conditional for when the zone is on…