This project implements a cheap and easy way to read out meter pulses from the Pipersberg G4 RF1 c gas meter via an Espressif ESP8266 micrcontroller and a PL-05N proximity sensor. The meter reading can be calculated and stored locally and used by a Home Assistant instance using ESPHome.
The following hardware is needed to implement this project
- ESP8266 NodeMCUv3 (or similar, e.g. Wemos D1)
- PL-05N NPN Contact DC Proximity Sensor Switch
- Alternative: LJ12A3-4-Z/AY, but needs more space in front of gas meter. See NOTE in sensor holder for a suitable holder.
- Home Assistant running on a server
- ESPHome running on a server
The 3D printing files for the sensor holder can be found in the holder folder or on Thingiverse.
NOTE: The design is a remix of a sensor holder for LJ12A3-4-Z/AY.
The cable colors of (inductive) sensors, seem to deviate from the standard colors, especially with blue for GND and brown for (VIN) power supply. Please connect the sensor to the NodeMCU v3 as follows.
ESP8266 NodeMCU v3 | PL-05N |
---|---|
VIN (5V) | brown |
GND | blue |
A0 (Analog) | black |
NOTE: The PL-05N is rated for input voltages from 10V to 30V. However, I found that it is working perfectly fine with the 5V voltage supply sketched above. If in doubt, please add a buck-boost converter to the brown cable to reach 10V.
In the following sections, the software setup will be described.
One of the easiest ways to connect an ESP8266 to Home Assistant is using ESPHome. The basic firmware can be easily flashed from the browser connecting the device to the computer. Afterwards, the configuration can be easily updated over Wifi.
I am using
- an analog to digital sensor to measure the raw voltage on pin A0
- an analog threshold binary sensor with the threshold set to 0.01V to trigger a pulse
- a template sensor to convert the pulses to the m³ consumer locally and to expose this value to Home Assistant
Please see the ESPHome configuration for PL-05N for all details.
NOTE: I tried using the GPIO binary sensor on a digital GPIO pin before but encountered a lot of misreadings. Even with different pullup
and filters
using delayed_on
I was not able to fix them. Please check the esphome logs, in case of misredings.
...
[09:26:48][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.29883 V with 2 decimals of accuracy
[09:26:48][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.29883 V with 2 decimals of accuracy
[09:26:48][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.29883 V with 2 decimals of accuracy
[09:26:48][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
[09:26:48][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
[09:26:48][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
[09:26:49][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
...
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00098 V with 2 decimals of accuracy
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.00195 V with 2 decimals of accuracy
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.29590 V with 2 decimals of accuracy
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.29590 V with 2 decimals of accuracy
[09:26:51][D][sensor:093]: 'Internal pulse sensor voltage': Sending state 0.29590 V with 2 decimals of accuracy
...
Home Assistant should automatically be able to find the new sensor when it is connected to the same network.
To convert the gas meter reading in m³ to energy (kWh) and cost (€), please see packages/gas-meter.yaml.
Basically, the gas meter reading in m³ is converted to kWh via a factor which can be requested by the gas supplier or is part of the gas bill. The gas cost is calculated via the gas concumption in kWh multiplied by the gas price in €/kWh. The current gas price can be set via a input number.
With the meter reading in m³, kWh and € you can already use some basic built-in Home Assistant statistics. However, if you want to keep statistics for time frames such as yesterday, last week or last month, a bit more effort is needed.
See packages/gas_statistics.yaml for all details.
This project is under MIT license. See LICENSE.md.