Water flow-meter with PulseCounter

Hi, I am getting the following error while compiling a program:

INFO ESPHome 2024.6.6
INFO Reading configuration /config/esphome/watermeter-demo.yaml...
WARNING GPIO2 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
Failed config

sensor.pulse_counter: [source /config/esphome/watermeter-demo.yaml:42]
  
  Pin 14 is used in multiple places.
  platform: pulse_counter
  pin: 
    number: 14
    mode: 
      input: True
      output: False
      open_drain: False
      pullup: False
      pulldown: False
    inverted: False
    ignore_pin_validation_error: False
    ignore_strapping_warning: False
sensor.pulse_meter: [source /config/esphome/watermeter-demo.yaml:48]
  
  Pin 14 is used in multiple places.
  platform: pulse_meter
  pin: 
    number: 14
    mode: 
      input: True
      output: False
      open_drain: False
      pullup: False
      pulldown: False
    inverted: False
    ignore_pin_validation_error: False
    ignore_strapping_warning: False
sensor.pulse_meter: [source /config/esphome/watermeter-demo.yaml:59]
  
  Pin 14 is used in multiple places.
  platform: pulse_meter
  pin: 
    number: 14
    mode: 
      input: True
      output: False
      open_drain: False
      pullup: False
      pulldown: False
    inverted: False
    ignore_pin_validation_error: False
    ignore_strapping_warning: False

I’ve used the following blog post as example (which is linked on the documentation page (Integrating your water usage - Home Assistant)

Blog: Build a cheap water usage sensor using ESPhome and a proximity sensor - PieterBrinkman.com

Since the PulseMeter is only connected to one pin, I would expect that I could create different “versions” of the sensor (different units, etc.)

Post your yaml please!

ah … sorry. Wanted to add it, but just forgot before submitting :slight_smile:

sensor:
## Cold-Water-Meter for Garden
  - platform: pulse_counter
    pin: GPIO14
    update_interval : 6s
    name: "cold water pulse"
    id: cold_water_pulse

  - platform: pulse_meter
    pin: GPIO14
    name: "Cold Water Pulse Meter (L/min)"
    unit_of_measurement: "liter/min"
    device_class: volume_flow_rate
    state_class: measurement
    icon: "mdi:water"
    total:
      name: "Cold Water Total (L)"
      unit_of_measurement: "liter"

  - platform: pulse_meter
    pin: GPIO14
    name: "Cold Water Pulse Meter (L/min)"
    unit_of_measurement: "liter/min"
    device_class: volume_flow_rate
    state_class: measurement
    icon: "mdi:water"
    total:
      name: "Cold Water Meter Total (m³)"
      unit_of_measurement: "m³"
      id: cold_water_meter_total
      accuracy_decimals: 3
      device_class: water
      state_class: total_increasing
      filters:
        - multiply: 0.001

  - platform: template
    name: "Water Usage Liter"
    id: water_flow_rate
    accuracy_decimals: 1
    unit_of_measurement: "l/min"
    device_class: volume_flow_rate
    state_class: measurement
    icon: "mdi:water"
    lambda: return (id(cold_water_pulse).state * 10);
    update_interval: 6s

You can’t have multiple time platform using the same pin.

See this example of my config for same kind of device

sensor:
- platform: pulse_meter
  pin: GPIO4
  name: "Water Pulse Meter"
  unit_of_measurement: "liter/min"
  icon: "mdi:water"
  id: pulse
  total:
    name: "Water Meter Total"
    unit_of_measurement: "m³"
    id: water_meter_total
    accuracy_decimals: 3
    device_class: water
    state_class: total_increasing
    filters:
      - multiply: 0.001
    on_value:
      then:
        - lambda: |-
            float y = round(x * 1000) / 1000;
            id(store_count).state = id(store_count).state - id(my_previous_val) + y ; 
            id(my_previous_val) = y ;
            ESP_LOGD ("global","%f", id(my_previous_val));
            ESP_LOGD ("store","%f", id(store_count).state);
        - homeassistant.service:
             service: input_number.set_value
             data:
                entity_id: input_number.water_counter_store
                value: !lambda return id(store_count).state ;
                

- platform: copy
  name: "Water Liter"
  source_id: water_meter_total
  state_class: total_increasing
  device_class: water
  unit_of_measurement: 'L'
  accuracy_decimals: 0
  filters:
    - multiply: 1000

thanks :slight_smile:

Am I right, that the lamda call:

    on_value:
      then:
        - lambda: |-
            float y = round(x * 1000) / 1000;
            id(store_count).state = id(store_count).state - id(my_previous_val) + y ; 
            id(my_previous_val) = y ;
            ESP_LOGD ("global","%f", id(my_previous_val));
            ESP_LOGD ("store","%f", id(store_count).state);
        - homeassistant.service:
             service: input_number.set_value
             data:
                entity_id: input_number.water_counter_store
                value: !lambda return id(store_count).state ;

is only for storing the values of the sensor in HomeAssistant?

With this “input_number” I could probably also create an “offset”?
So I might set the input_number to 31 what the meter is currently showing before the ESP has been attached?

No, you have to use platform: copy instead of having 2 times pulse_meter.
About pulse_counter, it may work with pulse_meter in //

About the lamdba, it’s not related to your question. It’s part of my code to store value in HA and do calculation then I can have same value as real counter value.

1 Like

thanks :slight_smile:

I’ve just tested to use pulse_counter & pulse_meter on the same IO pin - which seems not to work … but in my opinion, this limitation does not seem correct to me…

I should be able to use two different platforms that should do different things with the same signal…
Anyway - thank you so far :slight_smile:

I will also have a look into the lamba, since this is also something I wanted to implement later on :slight_smile:

Yes that should work for 2 different platform but I saw that it’s in comment in my yaml. I guess I removed in 2022 for some reasons but not remember :slight_smile:

See the note is only on pulse_meter:Pulse Meter Sensor — ESPHome

About the real counter value, it’s not perfect…I see some deviation when stop/start HA occur but that’s fine for my usage.

This is needed:

globals:
   - id: my_previous_val
     type: float
     restore_value: no
     initial_value: '0'

- platform: homeassistant
  id: store_count
  entity_id: input_number.water_counter_store
  accuracy_decimals: 3
  internal: False
  unit_of_measurement: "m³"
  state_class: total
1 Like