Smarter gas meter
Home Assistant has great energy management features. ESPHome provides easy and cheap way to get various measurements into Home Assistant. Combine the two and you can start tracking gas usage at homes that have old style gas meters.
There are a couple of already documented ways to get gas meter readings into Home Assistant. At first I tried using a window sensor to track whenever the gas meter wheel makes a full rotation. But I was never able to position the reed sensor in a way that it would reliably detect the full wheel rotation.
Then I found an article that uses a photoresistor to track the reflective patch on one of the numbers of the gas meter number row. But I never gave this one a try.
![](/assets/images/reflective_patch.small-cdead93ffef85c4f096b08eb8b5a7f01.png)
Reflective patch on the gas meter last number
After playing around with the Physics Toolbox Sensor Suite Android application it became obvious that magnetic field is quite strong and the same magnetic field that should flip the reed switch could be measured quite precicely with a magnetometer.
After taking a quick look at magnetic field sensors that are supported by ESPHome, I found QMC5883L
that is supported and easily accessible.
![](/assets/images/mag_sensor.small-22da1ca3899b2e86acbb08b7168c62ef.png)
Magnetic field sensor attached to the outside of the gas meter with a double sided tape
The setup for this sensor is quick and straight-to-the-point, as it always is with ESPHome.
sensor:
- platform: qmc5883l
address: 0x0D
field_strength_x:
name: "Gas Meter Field Strength X"
field_strength_y:
name: "Gas Meter Field Strength Y"
field_strength_z:
name: "Gas Meter Field Strength Z"
temperature:
name: "Gas Meter Temperature"
filters:
- offset: 34.0
range: 200uT
oversampling: 512x
update_interval: 1s
i2c:
sda: GPIO21
scl: GPIO22
scan: true
Looking at the data from the sensor, Z axis was the most sensitive to the magnetic field changes. A threshold
integration in Home Assistant can be used to detect when the magnetic field changes significantly - detecting a full wheel rotation.
binary_sensor:
- platform: threshold
entity_id: sensor.gas_meter_field_strength_z
lower: -70
name: Gas Meter Pulse
![](/assets/images/sensors.small-1318dab09921e0680d4236b138d9c886.png)
This binary_sensor
is used in Home Assistant Automation to increment a counter every time a full wheel rotation is detected.
- alias: Dujų Skaitliuko Skaičiuoklė
trigger:
- platform: state
entity_id:
- binary_sensor.gas_meter_pulse
from: 'off'
to: 'on'
action:
- service: input_number.increment
target:
entity_id: input_number.duju_skaitliukas
Having the gas meter as an input_number
in Home Assistant makes it easy to set the initial value and also make any corrections if needed via the UI.
input_number:
duju_skaitliukas:
name: "Dujų Skaitliukas"
min: 622202
max: 999999
step: 1
mode: box
template:
- sensor:
- name: "Dujų Skaitliukas"
device_class: gas
unit_of_measurement: "m³"
state_class: "total_increasing"
icon: "mdi:fire"
state: "{{ states('input_number.duju_skaitliukas') | float * 0.01}}"
With this setup sensor.duju_skaitliukas
sensor can be added to the "Gas Consumption" energy dashboard configuration together with the unit cost. Now gas usage and cost can be tracked in Home Assistant Energy dashboard.
Full ESPHome configuration for the sensor can be found here. It also includes a snippet that shows the value of the sensor.duju_skaitliukas
Home Assistant sensor on the OLED screen of the ESP32 device.
For comments and any questions feel free to reach out on Mastodon.