ESP32H2-based pulse counter that measures pulses from utility meters with magnetic impulse output and sends them to Zigbee2MQTT.
Inspired by ZigbeeGasCounter.
- Flash the firmware onto your ESP32-H2 board.
- Copy the external converter to Zigbee2MQTT.
π See External Converter - Restart Zigbee2MQTT completely (full restart required).
- Enable Zigbee pairing (permit join)
- Power on the board or press the Boot button to send the first data packet.
- The vBat pin operates at VDD levels (typically 3.3V).
- The pin vBat is NOT 5V tolerant.
- To reduce power consumption, the power LED may be removed (unsoldered).
- Use a voltage regulator or voltage divider if needed.
- Can also be powered from USB (3.3V internally regulated).
- Counts pulses from a meter using a reed sensor connected to a GPIO and GND pin.
- Stores pulse count in non-volatile memory (NVS).
- Sends data to Zigbee2MQTT:
- On a configurable timer
- When accumulated pulses reach a threshold
- Triggers immediate transmission when Boot button is pressed
- Supports deep sleep for low power.
- LED for pulse indication.
- ESP32-H2-DevKitM-1 internal antenna / ESP32-H2-DevKitM-1 external antenna board (4MB Flash)
- Gas meter with pulse output (e.g., BK-G4MT, Honeywell BK-G6M or similar)
- Reed sensor (10AT is better): Normally Open (NO) β tested with GPS-01 Reed Switch 4Γ18 (not quite sensetive)
- Battery power supply (supports USB-C power banks)
- Zigbee2MQTT with external converter configured
- ESP-IDF (used in installation by ESP-IDF)
- MQTT broker
- Home Assistant server
| ESP32H2 Pin | Connection |
|---|---|
| GPIO10 | Reed sensor signal |
| GND | Reed sensor GND |
| VBat(Vcc) | +VDD (+3.3V) |
| GND | Battery '-' |
| Parameter | Description |
|---|---|
PULSE_PIN |
GPIO pin connected to the reed sensor |
MAIN_BTN |
GPIO used for the button |
MUST_SYNC_MINIMUM_TIME |
Interval between automatic transmissions (default: 60 min) |
COUNTER_REPORT_DIFF |
Number of pulses to trigger immediate transmission (default 10) |
INITIAL_COUNTER_VALUE |
Initial counter value (e.g., 2134 = 21.34 mΒ³) |
FEATURE_MEASURE_BATTERY_LEVEL |
Enable or disable battery voltage monitoring |
ADC_CHANNEL_2 |
GPIO pin used to measure voltage via a resistive divider |
RATED_BATTERY_VOLTAGE |
Nominal battery voltage (as specified by the manufacturer) |
MAX_BATTERY_VOLTAGE |
Maximum battery voltage |
MIN_BATTERY_VOLTAGE |
Minimum battery voltage |
WARN_BATTERY_VOLTAGE |
Battery voltage threshold for warning |
ADC_MAX_VALUE |
Maximum ADC value (on GPIO pin used to measure voltage) |
- ESP32H2 counts pulses from the meter.
- Pulses are stored in NVS flash to survive reboots or deep sleep.
- When timer expires or pulse threshold is reached data is sent to Zigbee2MQTT.
- Device enters deep sleep to save power until next event (pulse or timer).
To correctly interpret the counter values as gas consumption, create a Helper in Home Assistant Settings β Devices & services β Helpers β Create helper β Template β Sensor with the following parameters.
5720.17- is the initial reading of your utility meter.
sensor.0xf4ce3662f44a0e45_gas_count- your sensor entity in Home Assistant.
Name: Gas meter
State: {{ (states('sensor.0xf4ce3662f44a0e45_gas_count') | float(0) * 0.01 + 5720.17) | round(2) }}
Device class: Gas
State class: Total increasing
Unit of measurement: mΒ³
Availability template: {{ has_value('sensor.0xf4ce3662f44a0e45_gas_count') }}GAS_COUNTER: Counter loaded value=160
GAS_COUNTER: Setup deep sleep
GAS_COUNTER: Wake up from PULSE.
GAS_COUNTER: Checking if Zigbee radio should be enabled
GAS_COUNTER: Counter stored value=161
GAS_COUNTER: Configuring wake-up methods
GAS_COUNTER: Enabling wake-up timer , 162s
β οΈ Don't forget to create an external converter in Zigbee2MQTT first!
- git clone https://github.com/romlisrl/Esp32H2GasCounter
- cd Esp32H2GasCounter
- Set the desired configuration values
- idf.py erase-flash
- idf.py build flash
2οΈβ£ Using esptool.py (firmware_batmon.bin/firmware_wo_batmon.bin)
- Connect the board to a UART port (e.g., COM10 on Windows)
With battery monitor:
esptool.py --chip esp32h2 --port COM10 write_flash 0x0 firmware_batmon.bin Without battery monitor:
esptool.py --chip esp32h2 --port COM10 write_flash 0x0 firmware_wo_batmon.bin 3οΈβ£ Using ESPHome Web (firmware_batmon.bin/firmware_wo_batmon.bin)
- Connect the board via USB/UART
- Select the firmware file:
firmware_batmon.bin(with battery monitor)firmware_wo_batmon.bin(without battery monitor)
- Flash it directly from the browser
The following tasks are planned or pending implementation:
- [Ρ ] Implement battery voltage measurement via voltage divider on GPIO3 β include ADC reading and calibration.
- [Ρ ] Add configuration for voltage divider parameters (scaling factor, low-battery thresholds).
- Make sure the Zigbee coordinator is running and permit join is enabled
- After modifying the external converter, restart Zigbee2MQTT completely (do not use Settings β Tools β Restart Zigbee2MQTT)



