Help me with water flow sensor

I’m using a YF-B5 water flow sensor (pulse counter) connected to Home Assistant via ESPHome.

This is the best configuration I found online:

sensor:
  - platform: pulse_counter
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
    name: "Water Flow Rate 1"
    id: "water_flow_rate_1"
    icon: "mdi:water"
    unit_of_measurement: "L/min"
    update_interval: 1s
    filters:
      - lambda: return (x+4)/8/60;
      # Filter out values less than 0.1 L/min to prevent small noise
      - filter_out: 0.1
      # Alternatively, you can use a more complex lambda filter
      - lambda: |-
          if (x <= 0.1) {
            return 0.0;
          }
          return x;

However, the results are inaccurate. During testing, the readings are consistently 4 times less than expected. For instance, if the sensor shows 1.0 L/min, the actual tests shows 4.0 L/min.

Even when I try returning raw values, the output consists of random large numbers like 3750, 10700, 0, 800, etc.

Note: I am not using a resistor, Just connected the sensor to the 3v and pin 4

Could someone help me properly configure this sensor to get accurate readings?

If it’s consistently a factor of 4 off then can’t you just multiply the result by 4?

If you don’t want to do it in HA then maybe this would work (not tested):

    filters:
      - lambda: return (x+4)/8/60;
      # Filter out values less than 0.1 L/min to prevent small noise
      - filter_out: 0.1
      # Alternatively, you can use a more complex lambda filter
      - lambda: |-
          if (x <= 0.1) {
            return 0.0;
          }
          return (x*4);