How to get ESP32 reed water sensor to provide values?

Hi there,
I have a similar problem like in this older post

I have bought an ESP32 reed sensor measure water consumption. I never really got it work properly, Despite setting different initial values in the developer tool, it still would start with the value I used for testing first (ca. 3.590m3 instead of currently 1.170m3).

Here is the configuration yaml. Could you kindly help me with that? And yes, I am not really a pro in HomeAssistant…

esphome:
  name: meter-3644                      # unique identifier

esp32:                                  # MAC: 88:56:A6:5C:36:44
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

preferences:
  flash_write_interval: 6h              # save every 6 hours

ota:
  - platform: esphome
    password: "uLo8teip"

wifi:
  output_power: 10db
  ssid: "dummy"                     # Wi-Fi SSID
  password: "dummy"               # Wi-Fi password
  ap:
    password: "EeYaigh4"                # fallback access point password

captive_portal:

api:
  encryption:
    key: O+wPZAwIexKiT9nxVXSsEqfbXA0M9m4NRXUU6bOU+is= # https://esphome.io/components/api.html

globals:
  - id: pulses
    type: int
    restore_value: yes                  # restore value after reboot (yes)
    initial_value: 1150.170                  # inital value (0,0 m³)

binary_sensor:
  - platform: gpio
    id: pulse
    internal: true
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
    name: Pulse
    filters:
      - delayed_on: 10ms
    on_press:
      then:
        - lambda: id(pulses) += 1;

sensor:
  - platform: template
    name: Water
    device_class: water
    unit_of_measurement: m³
    state_class: total_increasing
    icon: mdi:water
    accuracy_decimals: 3
    lambda: return id(pulses) * 0.01;   # meter multiplier (0,01 m³)
    update_interval: 60s
  - platform: homeassistant
    name: Offset-water
    entity_id: sensor.meter_3644_offset
    id: offset
    on_value:
      then:
        - globals.set:
            id: pulses
            value: !lambda 'return int(x);'

web_server:
    port: 80
    local: true

logger:

Unlikely to be correct. GPIO0 is typically wired to the boot switch on an ESP32.

Can you tell from the pics?

Ah C3. Nevermind, it’s correct then.

But what is the actual issue? Just that the initial value is kept from your initial tests? In this case, you would need a factory reset to wipe the saved values:

Or is the pulse counter not working?

The pulse counter did work from the beginning or at least I did not have the right decimal value set.

As first step, factory reset sounds like a good idea. Would it be OK to do it via the physical button method?

The reset is always done through the physical button when using the integration, if I get it right :wink:
Just adding the integration won’t perform the reset.

I never used the functionality myself. What I did as some point is to just set restore_values to false, flash, and set it back to true.

Or if you want to play with it or regularly want to adjust the value, add a template number on your setup…

number:
  - platform: template
    name: "Set Value"
    optimistic: true
    set_action:
      - lambda: |-
          id(pulses) = x;

In the latest changes, 2026.1: Home is where the dashboard is 🥂 - Home Assistant the new Action Responses capability may solve some of your problems.