ESPHome configuration for reading a gas meter using a reed contact sensor with a Wemos D1 Mini (ESP8266).
- 📊 Real-time gas consumption monitoring
- 🔄 Persistent pulse counter (survives reboots)
- 📈 Accurate meter reading with adjustable offset
- 🏠 Home Assistant Energy Dashboard compatible
- 💾 Adjustable meter offset (for annual calibration)
- 🔄 Reset button for pulse counter
- 💡 Visual LED feedback on each pulse (3 seconds)
- 📦 Modular package-based configuration
- 🌐 Dual language support (English/German)
- Wemos D1 Mini (or any ESP8266 board)
- Reed contact sensor (normally open)
- Gas meter with magnetic pulse output
- USB cable for power and programming
Connect the reed contact sensor to your Wemos D1 Mini:
Reed Contact Sensor
┌─────────────┐
│ Reed │
│ Contact │
└──┬──────┬───┘
│ │
│ └──────────> GND (Wemos D1 Mini)
│
└─────────────────> D2 (GPIO4, Wemos D1 Mini)
| Component | Wemos Pin | GPIO | Description |
|---|---|---|---|
| Reed Contact | D2 | GPIO4 | Pulse input from gas meter |
| Internal LED | D4 | GPIO2 | Status indicator (flashes on pulse) |
Note: The internal pull-up resistor is enabled in the configuration, so no external resistor is needed.
- Install ESPHome
- Have your WiFi credentials ready
- Know your gas meter's pulses per cubic meter (check meter specifications)
-
Clone this repository:
git clone https://github.com/legacycode-esphome/ESPHome-Gas-Meter.git cd ESPHome-Gas-Meter -
Create a
secrets.yamlfile from the template:cp esphome/secrets.yaml.example esphome/secrets.yaml
Then edit
esphome/secrets.yamlwith your WiFi credentials:wifi_ssid: "YourWiFiSSID" wifi_password: "YourWiFiPassword"
-
Adjust the configuration in
esphome/gas-meter-wemos.yaml:substitutions: devicename: "gas-meter" friendly_name: "Gas Meter" pulses_per_cubic_meter: "100" # Adjust for your meter initial_meter_offset: "0" # Set to your current meter reading
-
(Optional) Change localization to German:
Edit line 50 in
esphome/gas-meter-wemos.yaml:# Change from: translations: !include localization/en.yaml # To: translations: !include localization/de.yaml
Flash via USB:
esphome run esphome/gas-meter-wemos.yamlNote: This project uses USB flashing only. OTA updates are not included for simplicity and security.
Instead of cloning the repository, you can use the remote package configuration that loads all files directly from GitHub. This is perfect if you don't want to maintain local copies of the configuration files.
-
Prerequisites:
- Install ESPHome
- Have your WiFi credentials ready
-
Download only the remote config file:
curl -O https://raw.githubusercontent.com/legacycode-esphome/ESPHome-Gas-Meter/main/esphome/gas-meter-wemos-remote.yaml
-
Create a secrets.yaml in the same directory:
wifi_ssid: "YourWiFiSSID" wifi_password: "YourWiFiPassword"
-
Adjust configuration variables in
gas-meter-wemos-remote.yaml:substitutions: devicename: "gas-meter-remote" friendly_name: "Gas Meter Remote" pulses_per_cubic_meter: "100" # Adjust for your meter initial_meter_offset: "0" # Set to your current meter reading
-
Flash via USB:
esphome run gas-meter-wemos-remote.yaml
The remote configuration automatically downloads all necessary files from GitHub on first use:
- common/packages.yaml - Core ESPHome components
- common/boards/esp8266-d1-mini.yaml - Board configuration
- gas-meter/packages.yaml - All gas meter functionality
- localization/en.yaml - English translations
Files are cached locally and refreshed every 24 hours (refresh: 1d).
✅ No repository cloning - Just one config file needed ✅ Automatic updates - Get latest changes from GitHub ✅ Minimal maintenance - No local file management ✅ Same functionality - 100% feature parity with local version
If you prefer local files for customization, simply:
- Clone the full repository
- Use
esphome/gas-meter-wemos.yamlinstead - Modify any package files as needed
Common values for gas meters:
- 1 pulse/m³: 1 pulse = 1 cubic meter
- 10 pulses/m³: 1 pulse = 0.1 cubic meters
- 100 pulses/m³: 1 pulse = 0.01 cubic meters (most common)
- 1000 pulses/m³: 1 pulse = 0.001 cubic meters
Check your gas meter specification or the meter itself for the correct value.
Set this to your current gas meter reading to start tracking from the actual meter value:
initial_meter_offset: "1234" # Your current meter reading in m³You can also adjust this later via Home Assistant using the "Meter Offset" entity.
After adding the device to Home Assistant, you'll have access to:
| Entity | Type | Description |
|---|---|---|
| Flow Rate | Sensor | Current gas flow rate (m³/h) |
| Total | Sensor | Measured consumption since reset (m³) |
| Meter Reading | Sensor | Actual meter reading (Offset + Total) |
| Total Pulses | Sensor | Raw pulse count |
| Meter Offset | Number | Adjustable offset for calibration |
| Reset Pulses | Button | Reset the pulse counter to zero |
| LED | Light | Control the status LED |
- Go to Settings → Dashboards → Energy
- Under Gas consumption: Add Gas Source
- Select: sensor.gas_meter_meter_reading
- Confirm
The Energy Dashboard will automatically track your daily, monthly, and yearly gas consumption.
To calibrate with your energy provider's reading:
- Compare Meter Reading sensor with your physical meter
- Calculate the difference:
actual_reading - sensor_reading - Adjust Meter Offset by adding the difference
- The Meter Reading now matches your physical meter
Example:
- Physical meter: 1456 m³
- Sensor reading: 1450 m³
- Difference: +6 m³
- Current offset: 1234 m³
- New offset: 1234 + 6 = 1240 m³
This project uses a modular package-based structure for better maintainability:
esphome/
├── common/ # Base configuration
│ ├── boards/ # Board-specific configs
│ ├── core/ # Core ESPHome components
│ └── packages.yaml # Aggregates all common packages
├── gas-meter/ # Gas meter functionality
│ ├── controls/ # Reset button, offset number
│ ├── core/ # Boot, globals, pulse meter logic
│ ├── led-internal.yaml
│ └── packages.yaml # Aggregates all gas-meter packages
├── localization/ # Language support (EN/DE)
└── gas-meter-wemos.yaml # Main device configuration
The main configuration includes just 4 packages:
common/packages.yaml- Core components (esphome, wifi, api, preferences)- Board configuration (ESP8266 D1 Mini)
gas-meter/packages.yaml- All gas meter functionalitylocalization/en.yaml(or de.yaml) - Language translations
- Check wiring connections (D2 and GND)
- Verify the reed contact is positioned correctly near the magnet
- Test the reed contact with a magnet manually
- Check the logs:
esphome logs esphome/gas-meter-wemos.yaml
Adjust the internal filter in esphome/gas-meter/core/pulse-meter.yaml:
internal_filter: 200ms # Increase from default 100ms if you get false pulses- Check
esphome/secrets.yamlcredentials - Ensure you're using 2.4 GHz WiFi (ESP8266 doesn't support 5 GHz)
Note: This configuration does not include a fallback WiFi AP. If WiFi connection fails, you'll need to reflash via USB with corrected credentials.
This is a simplified configuration focused on core functionality. The following features are intentionally excluded:
- ❌ OTA updates (use USB for flashing)
- ❌ MQTT (use Home Assistant API instead)
- ❌ Web server (configure via Home Assistant)
- ❌ Captive portal (no fallback WiFi AP)
- ❌ Time/NTP (not needed for pulse counting)
- ❌ API encryption (suitable for trusted home networks)
Why simplified? Faster compilation, smaller firmware, easier to understand, and fewer dependencies.
Need these features? You can add them by creating additional package files
in esphome/common/core/ and including them in gas-meter-wemos.yaml.
This project uses GitHub Actions to automatically build and validate the firmware on every push and pull request. The workflow:
- ✅ Compiles the YAML configuration
- ✅ Validates the ESPHome configuration syntax
- ✅ Ensures firmware builds successfully
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Built with ESPHome
- Compatible with Home Assistant
If you encounter any issues or have questions, please open an issue on GitHub.
Disclaimer: This project involves electrical components and gas meter modifications. Ensure you comply with local regulations and safety standards. The authors are not responsible for any damage or injury resulting from the use of this project.