How to count pulse frequency accurately with ESPHome?

I’m also using the pulse_meter (for my water, gas and electricity meters), but the one from the esphome dev channel, using the new pulse mode (instead of edge mode). The accumulated number of pulses counted is closer than the best I could do with the ‘old’ pulse_meter setup, even with the best filter time tuning. But even with the new situation I’m also seeing unwarranted dips, even down to 0. Still, it’s worth it, as the total is more reliable.

Since yesterdays ESPHome update, I now no longer see zero values or such variable numbers from the Pulse Meter. Looking better!

Which script are you using?

image

I have an ITELMA water meter with namur and the measurement accuracy is 1 liter = 1 pulse. I read the documentation and calculated and got an accurate calculation. If you look at the numbers on the water meter, then when the figure is fully visible, the counting is triggered. I calculated that I have 3-4 pulses per revolution on the dial. Further, he indicated the pulse duration at 600ms, and not what is indicated in the ESP Home documentation at 13us, which is why the pulse per liter is incorrectly recorded.

On ESP 32, I connected one wire to GND, and the second wire I connected to GPIO19. No resistors and no matter which wire is connected to GND and to GPIO19. No matter how connected, it works in both versions

  - platform: pulse_counter
    id: id_water_counter
    pin:
      number: GPIO19
      inverted: true
      mode:
        input: true
        pullup: true
    name: Water Counter
    icon: mdi:pulse
    update_interval: 5s
    unit_of_measurement: "Impulse/min"
    internal_filter: 600ms #Specify the duration as indicated in the water meter passport
    use_pcnt: false #Turning off use_pcnt. By default, it is enabled and does not allow you to specify above 13us
    accuracy_decimals: 3
    filters:
      - multiply: 0.25 #(4 pulses per liter = 0.25. Explanation = 1 liter divided by the number of pulses)
    total:
      name: Water Usage
      unit_of_measurement: "L"
      icon: mdi:water
      id: water_meter_total
      accuracy_decimals: 0
      device_class: water
      state_class: total_increasing
      on_value:
        then:
          - if:
              condition:
               - lambda: 'return (id(water_meter_total).state) > 0 ;'
              then:
               - number.set:
                  id: water_meter_number
                  value: !lambda 'return id(water_meter_total).state;'
Text in Russian (Текст на русском)

У меня имеется водосчетчик ITELMA с намур и точность замера 1 литр = 1 импульс. Я прочитал документацию и вычислил и получилось точное вычисление. Если смотреть на цифры на водосчетчике, то когда цифра видна полностью, то срабатывает подсчет. Я вычислил, что за один оборот на циферблате у меня случается 3-4 импульса. Далее указал длительность импульса в 600мс, а не то, что указывается в документации ESPHome в 13us из-за чего неверно ведется учет импульса на литр.

На ESP32 один провод я подключил к GND, а второй провод я подключил к GPIO19. Никаких резисторов и без разницы какой провод подключим к GND и к GPIO19. Как бы не подключали, в обеих вариантах это работает

  - platform: pulse_counter
    id: id_water_counter
    pin:
      number: GPIO19
      inverted: true
      mode:
        input: true
        pullup: true
    name: Water Counter
    icon: mdi:pulse
    update_interval: 5s
    unit_of_measurement: "Impulse/min"
    internal_filter: 600ms #Указываем длительность как указано в паспорте водосчетчика 
    use_pcnt: false #Выключаем use_pcnt. По умолчанию оно включено и не дает указать выше 13us
    accuracy_decimals: 3
    filters:
      - multiply: 0.25 #(4 импульса на литр = 0.25. Пояснение = 1 литр делим на кол-во импульсов )
    total:
      name: Water Usage
      unit_of_measurement: "L"
      icon: mdi:water
      id: water_meter_total
      accuracy_decimals: 0
      device_class: water
      state_class: total_increasing
      on_value:
        then:
          - if:
              condition:
               - lambda: 'return (id(water_meter_total).state) > 0 ;'
              then:
               - number.set:
                  id: water_meter_number
                  value: !lambda 'return id(water_meter_total).state;'
1 Like

Not sure, but one thing to check would be to ensure that there is no light leaking to the sensor from other sources. I’m not very familiar with the LDR:s, but at least with photodiodes I need to carefully block external light so it does not mess measurements.