HELP:water flow sensor type: YF-S401

I have tried using a water flow sensor type: YF-S401, working range 0.3-6 L/min,Allowing pressure: pressure 1.75Mpa,Load capacity: 10 mA (DC 5V),Working voltage range: DC 5~18 v,Maximum operating current: 15 mA (DC 5V),The lowest rated working voltage: DC4.5 5V-24V,Size : 6.5cmX4cm/2.55’‘X1.57’’ ,but I encountered problems, this sensor cannot detect flow. I tried installing it on a water dispenser, to measure the rate of drinking water use.
I use D1 mini, with the following code:

  - platform: pulse_counter
    state_class: measurement
    name: "Water Flow"
    id: Aliran_Air
    pin: GPIO5
    update_interval: 1s
    filters:
    - lambda: return (x / 400.0); 
    unit_of_measurement: "L/min"    
  - platform: integration
    device_class: water
    state_class: total_increasing
    name: "water comsumption (m³)"
    unit_of_measurement: 'm³'
    accuracy_decimals: 4
    sensor: flow_water
    time_unit: s
    icon: "mdi:water"
    filters:
        - lambda: return (x / 1000);    #(x / 1000); 

any suggestions to solve this problem. thank you

Use a different sensor. The YF-S401 is fine for an Arduino using 5V logic, but is not really suitable for an ESP using 3.3V.

Is there a recommendation for a sensor that has an inlet diameter of 1/2 cm?thanks

You could use this one, with a seperate power supply to drive it and an optocoupler or logic level converter to connect the GPIO.

For a one way connection even a voltage divider would do.

I have tried it, but the result is still the same.

peoblem solved.thanks