Pulse counter - how to reset total value?

I’d like to measure flow and amount of water which is used by watering system in one cycle. Water flow is measured by flow sensor, and I used Pulse Counter Sensor:

  - platform: pulse_counter
    pin: D7
    name: "Flow"
    update_interval: 5s
    filters:
    - lambda: return (x / 27.0) * 12.0;
    unit_of_measurement: "l/h" 
    total:
      unit_of_measurement: "l"
      id: amount
      name: "Amount of water"      

Generally it works perfect, I have two entities: sensor.flow, which shows flow of water in liters/hour and sensor.amount, which shows how much of water was used.
But, unfortunately, it seems that this “total” value is really total, I can’t reset it. I’m trying to zeroed it during start of watering session, but it just doesn’t work, entity still has previous value and just increasing.
Here is other part of my code, this switch which physically is a valve for this watering, on turn on it should reset amount value (and it also resets other value for measuring a time and it works well), why it doesn’t reset an amount?

switch:
  - platform: gpio
    pin: D5
    inverted: yes
    id: zawor1
    restore_mode: ALWAYS_OFF
    name: Zawór1
    icon: "mdi:watering-can"
    on_turn_on:
      - switch.turn_on: zompa
      - lambda: |-
          id(runtime_zawor1) = 0;
          id(amount) = 0;

Did you have any luck solving this issue. I have a similar pulse counter I would like to reset daily in an automation

If you are integrating this with HA, try a utility meter. Or, with ESPHome, try the integration sensor.

1 Like

Yes, I did it finally. Pulse counter is using only as a sensor for getting value, then I’m using it for updating a global variables, which I can reset or whatever I need.

globals:
  - id: water_amount
    type: double
    restore_value: no
  - id: water_flow_rate
    type: double
    restore_value: no

sensor:
  - platform: pulse_counter
    id: water_pulse
    pin: D7
    name: "Flow"
    update_interval: 5s
    unit_of_measurement: "l/min" 
    filters:
    - lambda: |-
        x = x / 300;
        id(water_amount) += x * 0.0835;
        id(ilosc_wody).publish_state(id(water_amount));
        id(water_flow_rate) = x;
        return x ;

  - platform: template
    id: ilosc_wody
    name: "Water amount" 
    unit_of_measurement: "l"
    #lambda: return (id(water_amount));

Where are you resetting it?

e.g. here. It is a switch for driving a valve, water amount is zeroed after every opening of it, so after run the water, indication starts from zero.

switch:
  - platform: gpio
    pin: D5
    inverted: yes
    id: zawor1
    restore_mode: ALWAYS_OFF
    interlock: [zawor2]
    name: Zawór1
    icon: "mdi:watering-can"
    on_turn_on:
      - lambda: |-
          id(water_amount) = 0;    
1 Like

Awesome, thanks for the info!

1 Like

@Jarek_P , Im trying do do something similar, but I want the the water amount to be reset to zero when there has been no pulse for a some time. Can you help me?