Skip to content

DIY Zigbee-enabled gas meter that measures and tracks gas consumption

License

Notifications You must be signed in to change notification settings

IgnacioHR/ZigbeeGasMeter

Repository files navigation

Zigbee GAS counter

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.

Features

  • 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.

Why Zigbee for DIY Projects?

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.

Screenshots

Below are some screenshots of the device integrated into Zigbee2MQTT:

Main device Exposes Bind Reporting Clusters

How It Works

  1. The gas meter’s rotating wheel has a built-in magnet.
  2. A magnetic sensor detects each full rotation of the wheel, corresponding to a predefined volume of gas.
  3. The ESP32-C6 processes the data, maintaining a cumulative counter (currentSummDelivered) and calculating instantaneous demand (instantaneousDemand) in m³/h.
  4. These metrics are sent via Zigbee to Zigbee2MQTT, which forwards them to Home Assistant.

Motivation

Before this project, I used a modified door sensor to monitor gas usage. While functional, it had several drawbacks:

  1. Short battery life: The door sensor required frequent battery replacements.
  2. Data loss: If Zigbee2MQTT or Home Assistant went offline, pulse data was lost, leading to discrepancies.
  3. 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.

Old device

Getting Started

Required Hardware

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.

Software Requirements

Setup Instructions

1. Clone the Repository

First, download the project code from the GitHub repository:

git clone https://github.com/IgnacioHR/ZigbeeGasMeter.git
cd ZigbeeGasMeter

2. Configure the target chip

Set the corrent target for the ESP32-C6:

idf.py --preview set-target ESP32C6

3. Install Dependencies

Ensure ESP-IDF and its tools are installed on your machine.

4. Erase Flash Memory

Clear previous configurations:

idf.py -p PORT erase-flash

4. Build and 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

Advanced Configuration

  • Reset Counter: Long-press the device button to reset the counter.
  • Set Counter Value: Send a Zigbee command to synchronize with your gas meter.

NVS (Non-Volatile Storage)

The cumulative gas consumption (currentSummDelivered) is stored in the device’s NVS to prevent data loss. The counter is automatically restored upon reboot.

Battery Optimization

The device uses sleep modes to conserve energy. It wakes up:

  • When gas consumption is detected.
  • Periodically (e.g., every hour) to send reports.

Customization

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.

Manufacturer information

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.

SDK Resources

Contributing

If you want to contribute or improve this project, feel free to fork the repository and open a pull request. Suggestions are welcome!

TODO

Here are the planned improvements:

  1. Implement battery monitoring and reporting via Zigbee.
  2. Design a custom PCB for the ESP32-C6, connectors, and resistors.
  3. Create a 3D-printed enclosure for secure installation.
  4. OTA support.

Acknowledgments

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.

License

License

About

DIY Zigbee-enabled gas meter that measures and tracks gas consumption

Topics

Resources

License

Stars

Watchers

Forks