This project is a DIY Zigbee-enabled gas meter that measures and tracks gas consumption. The device integrates with Zigbee2MQTT and Home Assistant, providing accurate readings for energy management and analysis. It’s designed to be battery-powered and operate autonomously, addressing common challenges of similar solutions.
- Real-time gas consumption tracking in cubic meters (m³).
- Zigbee communication for seamless integration with Zigbee2MQTT and Home Assistant.
- Battery-powered for installation flexibility.
- Built-in counter to prevent data loss if the network or Home Assistant goes offline.
- Easy setup and minimal hardware requirements.
Zigbee is a low-power, reliable wireless protocol ideal for IoT devices. Unlike Wi-Fi, Zigbee consumes minimal energy, making it perfect for battery-operated devices. While commercial Zigbee gas meters aren’t readily available, this project demonstrates how to build one from scratch using affordable components and the ESP32-C6 module.
Below are some screenshots of the device integrated into Zigbee2MQTT:
- The gas meter’s rotating wheel has a built-in magnet.
- A magnetic sensor detects each full rotation of the wheel, corresponding to a predefined volume of gas.
- The ESP32-C6 processes the data, maintaining a cumulative counter (currentSummDelivered) and calculating instantaneous demand (instantaneousDemand) in m³/h.
- These metrics are sent via Zigbee to Zigbee2MQTT, which forwards them to Home Assistant.
Before this project, I used a modified door sensor to monitor gas usage. While functional, it had several drawbacks:
- Short battery life: The door sensor required frequent battery replacements.
- Data loss: If Zigbee2MQTT or Home Assistant went offline, pulse data was lost, leading to discrepancies.
- Complexity: Managing counters and automations in Home Assistant was cumbersome.
After searching for commercial Zigbee gas meters and finding none, I decided to create a custom device tailored to my needs.
To build this project, you’ll need:
- ESP32-C6-WROOM-1 or a compatible development board.
- Magnetic reed switch for pulse detection.
- 10kΩ resistor (pull-down).
- 3V CR123A battery. TBD
- Optional: Custom 3D-printed enclosure for the hardware.
- ESP-IDF (Espressif IoT Development Framework): Installation Guide
- Zigbee2MQTT: Setup Guide
- Home Assistant: Official Website
First, download the project code from the GitHub repository:
git clone https://github.com/IgnacioHR/ZigbeeGasMeter.git
cd ZigbeeGasMeter
Set the corrent target for the ESP32-C6:
idf.py --preview set-target ESP32C6
Ensure ESP-IDF and its tools are installed on your machine.
Clear previous configurations:
idf.py -p PORT erase-flash
Compile the code and flash it to the ESP32-C6 board:
idf.py build
idf.py -p PORT flash
idf.py -p PORT monitor
- Reset Counter: Long-press the device button to reset the counter.
- Set Counter Value: Send a Zigbee command to synchronize with your gas meter.
The cumulative gas consumption (currentSummDelivered) is stored in the device’s NVS to prevent data loss. The counter is automatically restored upon reboot.
The device uses sleep modes to conserve energy. It wakes up:
- When gas consumption is detected.
- Periodically (e.g., every hour) to send reports.
You can adapt this project for other pulse-based meters (e.g., water or electricity) by modifying the code to reflect the appropriate measurement units and formulas.
This project includes a custom manufacturer name and code:
- Name: “MICASA” – A playful mix of “mi casa” (my home) in Spanish.
- Code: 0x8888 – Chosen arbitrarily for this DIY project.
If you want to contribute or improve this project, feel free to fork the repository and open a pull request. Suggestions are welcome!
Here are the planned improvements:
- Implement battery monitoring and reporting via Zigbee.
- Design a custom PCB for the ESP32-C6, connectors, and resistors.
- Create a 3D-printed enclosure for secure installation.
- OTA support.
By improving the content structure and emphasizing actionable steps, this README not only serves as a guide for your project but also inspires others to create their own Zigbee devices.