Water flow meter (optical) - pulse meter - esphome

After a lot of research i bought for my old water meter a optical pulse counter.

The sensor is working (hardware) however i’m not able to get the pulses into Home Assistant.

I’m using the sketch below:

sensor:
  - platform: pulse_counter
    pin:
      number: D6
      allow_other_uses: true
    name: "water pulse"
    id: water_pulse

  - platform: pulse_meter
    pin:
      number: D6
      allow_other_uses: true
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Total"
      unit_of_measurement: "liter"

  - platform: pulse_meter
    pin:
      number: D6
      allow_other_uses: true
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    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

  - platform: template
    name: "Water Usage Liter"
    id: water_flow_rate
    accuracy_decimals: 1
    unit_of_measurement: "l/min"
    icon: "mdi:water"
    lambda: return (id(water_pulse).state * 10);

What do you mean by this?

Is the device being discovered without the sensors or not being discovered at all?

Edit: also this topic is probably relevant:

https://community.home-assistant.io/t/pin-4-is-used-in-multiple-places-since-update/659412

hello,

perhaps try pullup the gpio : like this :

  - platform: pulse_counter
    pin:
      number: GPIO26
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: sdb_water_flow_meter
    name: "Débit d'eau instantané SDB"
    update_interval: 6s
    filters:
      - lambda: return (x / 660); # 660 = 11 * 60

That did the trick :slight_smile: thanks… its working now :slight_smile:

1 Like

Last question here. i fully integrated the pulse counter including settings options and initial value setting on the meter itself.

When using the energy dashboard do i need to create a sensor per 24 hours? or does the dashboard this by itself.

api:
  services:
    - service: meterstand_water
      variables:
        meter_value: float
      then:
        - globals.set:
            id: initial_water_usage
            value: !lambda "return ( meter_value - (id(total_water_pulses)) * atof(id(Select_pulse_water).state.c_str()) ) ;"
        - globals.set:
            id: total_water_pulses
            value:  "0"
            

globals:
  - id: initial_water_usage
    type: float
    restore_value: yes
    initial_value: '0'
  - id: total_water_pulses
    type: int
    restore_value: yes
    
select:
  - platform: template
    name: "Pulsrate water per m3"
    id: Select_pulse_water
    optimistic: true
    options:
      - "0.0001"
      - "0.0005"
      - "0.001"
      - "0.01"
      - "0.1"
    initial_option: "0.001"
    restore_value: yes
    entity_category: config
    on_value:
      then:
        - logger.log:
            format: "Chosen option: %s "
            args: ["x.c_str()"]

number:
  - name: Initiële meterstand m3
    platform: template
    id: initial_water_value
    device_class: water
    min_value: 0
    max_value: 100000
    step: 0.001
    entity_category: config
    icon: mdi:water
    unit_of_measurement: "m³"
    set_action:
      - lambda: id(total_water_pulses) = x * 1000;

binary_sensor:
  - platform: gpio
    id: water_sensor_status
    name: "Water sensor status"
    internal: False
    pin:
      number: D5
      allow_other_uses: true
    on_press:
      - then:
          lambda: id(total_water_pulses) += 1;  
sensor:
  - platform: pulse_counter
    pin: 
      number: D5
      allow_other_uses: true
      mode:
        input: true
        pullup: true
    id: watermeter_pulse
    name: "Watermeter pulse"
    state_class: measurement
    unit_of_measurement: "l/min"
    accuracy_decimals: 1
    icon: "mdi:water-pump"
    filters:
      lambda: return x * atof(id(Select_pulse_water).state.c_str()) * 1000;

    total:
      id: sensor_pulse_meter_total
      name: "Watermeter Totaal"
      unit_of_measurement: "m³"
      state_class: total_increasing
      device_class: water
      accuracy_decimals: 3
      filters:
        lambda: return x * atof(id(Select_pulse_water).state.c_str());

  - platform: template
    id: watermeter_total
    name: "Watermeter Stand"
    state_class: "total_increasing"
    icon: mdi:water
    unit_of_measurement: "m³"
    accuracy_decimals: 3
    lambda: return id(initial_water_usage) + (id(total_water_pulses) * atof(id(Select_pulse_water).state.c_str()));

  - platform: template
    id: watermeter_pulses
    name: "Watermeter pulsen Totaal"
    state_class: "total_increasing"
    accuracy_decimals: 0
    lambda: return id(total_water_pulses);
    internal: False