Skip to content

AK-Homberger/D1Mini-GasCounter

Repository files navigation

D1 Mini Gas Counter

A simple ESP8266 based (D1 Mini) counter for the gas meter with a web interface. It is measuring pulses from the gas meter and calculating consumption values which are shown on a web interface. It's available in English/German language. MQTT and ioBroker integration is supported as an option.

Meter

Web interface (English/German):

Counter

Counter

Depending on your gas meter type, it might be sufficient to use a reed contact switch. For my meter Pipersberg G4 RF1 c it was necesssary to use an inductive sensor LJ18A3-8-Z/BX.

Alternatively you can also use the original Cyble Encoder Sensor for this meter type.

With the web interface you can set the current metering value. After that, it counts the individual pulses from the meter (0.01 m^3). It shows the overall consumption, the currrent day consumption, the consumption from yesterday and the current consumption.

In addition, the consumption fom the last hour and the total daily average consumption is shown.

If the client supports MDNS (Bonjour), you can access the server with "gascounter.local". If not, you have to use the IP-Address.

Hardware

The open collector output from the sensor is connected to pin D5 on the D1 Mini. No additional resistor is necessary due to the configured internal pull-up resistor for the D5 input pin.

The sensor (LJ18A3-8-Z/BX) is supplied with 12 Volt (6-36 Volt). For the D1 Mini you need an additional step-down converter to create 5 Volt from the 12 Volt.

With a reed contact you can directly use a 5 Volt power supply or power it via USB. For the reed contact, I added now also a small capacitor (10 nF) to minimise the potential effect HF interference. Please use twisted pair cable if the reed contact is far away from the ESP.

Diagram

Software

The Arduino IDE has to be installed and the ESP8266 Board URL "https://arduino.esp8266.com/stable/package_esp8266com_index.json" has to be included in the preferences. Two additional libraries have to be installed with the library manager in the Arduino IDE:

  • ArduinoJson
  • PubSubClient

Within the sketch you can select the language by coosing the desired header file, the timezone and set the wlan credentials. If you want to publish data via MQTT then set "USE_MQTT" to "true" otherwise to "false". The MQTT server IP can be defined with the "mqtt_server" variable.

//#include "index_html_de.h"    // Web site information for Gauge / Buttons in German
#include "index_html_en.h"      // Web site information for Gauge / Buttons in English

#define USE_MQTT          true  // Set to false if no MQTT to be used

#define TIME_24_HOUR      true
#define NTP_SERVER "de.pool.ntp.org"
#define TZ_INFO "WEST-1DWEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" // Western European Time

// Wifi
const char *ssid = "ssid";           // Set WLAN name
const char *password = "password";   // Set password

// MQTT
#if USE_MQTT == true
WiFiClient Mqtt;
PubSubClient client(Mqtt);
const char* mqtt_server = "192.168.0.71";
#endif

If you configured MQTT with username an password on your MQTT server, then you have to provide username and password in the client.connect function call. Please change line:

  if (client.connect(clientId.c_str()))

to

  if (client.connect(clientId.c_str(), "username", "password"))

Then it works.

ioBroker Integration and Data Visualisation

I'm using MQTT to publish data to an ioBroker instance with an influxDB database on a Raspberry server. That provides an easy was to log consumption data and to visualise the consumption history.

ioBroker

VIS

Detailled instructions for installation and configuration of ioBroker can be found here.

The following adapters have to be installed in ioBroker:

  • MQTT Broker/Client
  • Influxdb
  • Visualisation VIS
  • Flot adapter

The visualisation is available here. First install the VIS and Flot adapter in ioBroker. Then import the downloaded visualisation ZIP-file with the VIS editor.

The visualisation is using, in addition to the gas values, also inside/outside temperature and humidity. One option to get this information into ioBroker is a receiver/decoder for 433MHz sensors.

An example, especially for a Bresser 3 channel sensor, can be found here.

But integration with an ESP8266 plus BME280 or DHT11 via MQTT is another option. A sketch for both options is avalable with the links above.

If you are using the Bresser sensor for outside Temp/Hum and one of the others (BME280/DHT11) for inside Temp/Hum the visualisation will work out of the box, without any changes needed in object names. For the MQTT objects, which are created automatically, it might be necessary to change the "role" of the object to "variable" and "type" to "number".

For the Bresser sensor, everything is prepared correctly from the integration script.

For a correctly working visualisation, please make sure to enable Influxdb logging in ioBroker for these objects:

  • javascript.0.Temperature
  • mqtt.0.InsideTemperature
  • mqtt.0.Current
  • mqtt.0.DayEndCount
  • mqtt.0.Yesterday

The standard setting "only store changes" is sufficient.

The visualisation for the Bresser sensor supports also the Low Battery indicator in VIS. That means, a blinking battery symbol is shown right to the outside humidity value, to indicate that the sensor is signaling a needed battery replacement.

Parts:

Updates:

  • Version 1.6 - 13.11.24: Changed pointer type from unsigned to signed to avoid wrong hour average value once per hour.
  • Version 1.5 - 09.05.23: Changed function name for "getLocalTime()" to "MyGetLocalTime()" to avoid problems with duplicate definitions in certain environments.
  • Version 1.4 - 20.02.23: Calculate values before MQTT send.
  • Version 1.3 - 13.02.23: Debouncing interrupt as preparation for reed contact use.
  • Version 1.1 - 09.02.23: Added MQTT option.

About

A smart gas meter with a web interface and optional ioBroker integration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published