Resetting sensor on inactivity

Hello. I’m trying to make a sensor in ESPHome, that resets when there has been no water flowing for 5 minuts. I managed to get the sensor below work, but I cant figure out how to reset the integration when there has been no pulse from the pulse_counter for 5 minuts.

sensor:

  • platform: pulse_counter
    state_class: measurement
    name: “Vandflow”
    id: flow_vand
    pin: GPIO12
    update_interval: 1s
    filters:

    • lambda: return (x / 400.0); #Flow pulse: F=(6.68Q)±5% with Q=L/min
      unit_of_measurement: “L/min”
  • platform: integration
    device_class: water
    state_class: total_increasing
    name: “Vandforbrug i liter”
    unit_of_measurement: ‘L’
    accuracy_decimals: 2
    sensor: flow_vand
    time_unit: min
    icon: “mdi:water”

Looks like you want a pulse meter (not counter!)

But the counter works fine in order to sum up the water used. I only want to reset it, when the water has been off for 5 min.

Try putting a timeout filter on the integration with value : 0 ?

By the way, please take a moment to figure out how to format your code properly for the forum so it is easier for us to read.

Sorry, my rookie mistake.

I put the timeout filter on like this, but it didn’t help me.

Maybe I’m doing it wrong

- platform: integration
    device_class: water
    state_class: total_increasing
    name: "Aktuelt badeforbrug"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: flow_vand
    time_unit: min
    icon: "mdi:water"  
    filters:
      - timeout: 300s  #reset value after 5 min
      - timeout:
          timeout: 300s
          value: 0

Try getting rid of this whole line below.
The example provides two examples and you prob want the second one which fallsback to 0 rather than nan.

If the pulse counter is providing values every one second even if they don’t change (I’m not so familiar with that) , you might also need to put a delta filters before the one above so that the repeat values which aren’t changing don’t prevent the timeout from happening. Although you may need to assess the impact of that on your calcs too.

Posting some logs as you go will help to debug /optioneer.

This is exactly what the difference between the pulse counter and meter is. The default reset for the pulse meter is even 5 minutes!

No need to reinvent the wheel, only use the right component!

Also no integration component is necessary because thr pulse meter (and counter) components support total.

2 Likes

To clarify here, are we trying to reset after 5min, the total volume or the flow?

The total volume

1 Like

The pulse meter does seem like the best base for this code.

But it seems like the trigger for resetting the total after 5min of activity will still need to be a bit more hand-rolled I think?

I think putting the timeout filter on the total would probably work? It may still need a delta fiter if it is sending repeat values.

So I have changed the names of the sensors slightly in order to make it easier to understand the purposes.

Pulse_counter is changed to pulse_meter, and I have added the timeout section in the last integration. This one actually resets now after the timeout, but when I start using water again it starts from where it was before reset.

Excuse me for beeing such a stupid newbee :- :face_with_peeking_eye:

sensor:
  - platform: pulse_meter
    state_class: measurement
    name: "water flow"
    id: flow_vand
    pin: GPIO12
    filters:
    - lambda: return (x / 400.0); #Flow pulse: F=(6.68Q)±5% with Q=L/min
    unit_of_measurement: "L/min"

  - platform: integration
    device_class: water
    state_class: total_increasing
    name: "water used in m³"
    unit_of_measurement: 'm³'
    accuracy_decimals: 4
    sensor: flow_vand
    time_unit: min
    icon: "mdi:water"
    filters:
        - lambda: return (x / 1000);

  
  - platform: integration
    device_class: water
    state_class: total_increasing
    name: "Long time water used"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: flow_vand
    time_unit: min
    icon: "mdi:water"

  - platform: integration
    device_class: water
    state_class: total
    name: "Short time water used"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: flow_vand
    time_unit: min
    icon: "mdi:water"  
    filters:
      - timeout:
          timeout: 30s
          value: 0