Gas meter from Xiaomi/Aqara door sensor (ZigBee)

Hi guys my last project with is working flawlessly for 1 week now (some issues in the beginning first 2 weeks, issues: sensor position and not weatherproofing the sensor case)
I wanted a cheep and easy way to read my Gas meter (in the current context that price increased 5x in my country) Most of the gas meters have built in magnet that sends an impulse every 0.01 m3 (I have the BK-G4MT, is popular in Europe)
The gas meter in my country is located in front of the propriety on the street and no way you easy add power there, so a low power solution like ZigBee is the best in my case.
I used a Aqara door sensor witch I disassembled and added an size AA 3.2V Feo4 rechargeable battery (this is optional as I do not know how much the built in battery will last in this usage) and replaced the internal reed contact with a smaller one, 5-20AT sensibility.(works with the built in sensor I think, I managed to broke it, is very sensible)
Position of the sensor is very important and the best place I found showed in the picture. Home assistant has an automation that counts data to a sensor.

Hardware

ideal location for the reed sensor in my case

Software

HA → Configuration → helpers and create a counter

Automation

alias: Gas Counting
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.0x158d000708a09f_contact
    from: 'off'
    to: 'on'
condition: []
action:
  - service: counter.increment
    target:
      entity_id: counter.gas_counter
mode: single

configuration.yaml

homeassistant:
  customize: !include customize.yaml
sensor:
  - platform: template
    sensors:
### Gas meter template from counter
      gas_meter:
        friendly_name: Gas Meter
        value_template: "{{ states ('counter.gas_counter') | float * 0.01}}"
        unit_of_measurement: "m³"
        icon_template: "mdi:fire"
        device_class: gas

in customize.yaml you ned to add

sensor.gas_meter:
  state_class: measurement
  state_class: total_increasing
  last_reset: '2021-08-20T06:43:36.740703+00:00'

you can add it too energy and then you can get stressed that you consumed to much gas with heating :slight_smile:

Tests and explications
The meter has one small magnet in the mechanism and once every 0.01m of gas you get a impulse. in the specific area, if the meter is stopped in the 0.XX9 the impulse is constant.

  1. Start by having the reed sensor on the wire connected to the PCB and working (test with original magnet)
  2. have someone use something that consumes gas in the house and try to stop the meter exactly in the 0.XX9-0 range (last digit must between 9 and 0 so that the 0.XX digit is somehow between two numbers)
  3. once the meter in that range the magnetic field is constant from the meter so you just check the positioning of the sensor (must be closed once you get the correct position) - use tape to fix the sensor, HA must report that sensor is “closed”
  4. once you start consuming gas again the sensor will go to “open” in HA once the 0.XX digit of gas meter will move to a number.

You can see in the picture that my meter was stopped at the constant impulse position XXX.7 2-3 9-0
If your meter has the marking in the picture then is 100% that you have the impulse coming from it.

13 Likes

Hi Marius !

Nice setup ! Regarding the waterproofing, how did you manage it ? I was thinking of covering the whole PCB with epoxy with the wires (for power and contact) coming off to be able to replace the sensor/battery.

Regards,

Hello Arnaud, it was tricky :slight_smile: the gas meter is located in a metal box in front of the propriety, the sensor will sit ok there but because is a metal case the ZigBee signal is lost sometimes, so I had to move it outside of the box, had different ideas one of them was extending the antenna of the sensor outside of the box wtch did not work for some reason.

Final solution was:

  1. reed sensor was encased in hot glue (to give it weatherproofing)
  2. electronics of sensor where moved outside of the metal case in an small weatherproof electrical box
2 Likes

Thanks for your reply, can you tell me where you bought your sensor ?

Thx !

Hi, you can use the Xiaomi reed sensor you just need move it to a wire so it can fit in the meter slot. I ordered the reed sensor from www.tme.eu

Hey Marius,

Everything is working fine. Thanks a lot for this. Love it.

I do have one problem only. The sensor does not appear at my energy dashboard. I cant select it because its not in the list. Any idea what I am doing wrong?

Best regards
Pascal

To aper at energy in the drop-down menu the sensor need to have exactly the attributes:
unit_of_measurement: “m³”
device_class: gas
state_class: measurement
last_reset: ‘2021-08-20T06:43:36.740703+00:00’
You can add them thru HA → Configuration → Customizations.
You are missing one or you have change something, if you copy exactly what is in my initial post it will work.

Thanks. My error was I did not enter the last reset value.

I love this! I don’t need it personally but I love the creativity. I knew you could do a lot of cool things with the Aqara door sensors but this is a step above using it as a simple binary sensor.

1 Like

Hi Marius, nice project. I’m in the same situation, I cannot make cabling to my gas meter so I have to make the connection wireless. Tell me please about your Zigbee gateway, which type you use?
Other question is if you made a counter in HA, which have the same value like the counter of gas meter. This counter can help for monthly readings for the gas company.

Hi Stefan
I use the Mi home hub 3 (ZNDMWG03LM) pared with the AlexxIT integration Can be any GW from Xiaomi.
yes, the HA counter is synchronized with the real meter number using the command, “counter:configure”

1 Like

Multumesc Marius !
Right now I’m using a Zigbee USB dongle from Itead and I’m not so happy about the gain of antenna. Anyway I’m waiting for the next one from Itead (https://itead.cc/product/sonoff-zigbee-3-0-usb-dongle-plus/) with gain increased. In the meantime I’ll try to connect a Aqara door sensor with my existing dongle.
Thanks for the tip with counter. BTW, how do you measure the electrical energy? I’m using a Shelly EM.

I’m more in to DIY
For the electrical I’m using this setup: PZEM-0xx power monitor - Tasmota

For individual devices: Gosund SP111 Power Monitoring Plug Configuration for Tasmota

1 Like

Hello Marius, could you please give a bit more explanation on how you connected your external sensor to the board. I can’t see on your first picture how the connection is made.

Hello, I have marked on the picture the wires and will replace the picture in the first post.

  • I have replaced the battery with bigger one but I think it will be ok with the original battery at least for 3-4 months.
  • The Antenna connection is not necessary if your sensor is outside of the meatal box of the meter.
  • the Reed sensor is connected thru two wires (no polarity) is the black cable in the picture (has two wires inside) you can barley see the original Reed sensor in the picture to get an idea where is located.

I overcomplicated the picture but basically you just need to move the original Reed sensor from the PCB to an cable so you can arrange it in the meter hole.

1 Like

thank you. Meanwhile i ran some tests with the original sensor and a sensors app for my phone.
I think the magnetic field of my type of gasmeter is probably not strong enough for this method to work, not sure it will even work with the replacement reed sensor.

The original reed sensor doesn’t pick up the movement of the dials. The sensors app on my phone shows this miniscule up and down momevent (in the boxed area) as the dial moves:


→ almost a flat line really

Compared with holding the original magnet of the door/window sensor next to the phone:


→ big spikes when you hold magnet

But i’m a total noob concerning electronics, so maybe those tiny movements can be picked up after all with a more sensitive reed sensor?

Do not get disappointed, I had same experience in testing, at one point I was thinking that my meter was not sending the impulse.
The meter has one small magnet in the mechanism and once every 0.01m of gas you get a impulse. in the specific area, if the meter is stopped in the 0.XX9 the impulse is constant.

  1. Start by having the reed sensor on the wire connected to the PCB and working (test with original magnet)
  2. have someone use something that consumes gas in the house and try to stop the meter exactly in the 0.XX9-0 range (last digit must between 9 and 0 so that the 0.XX digit is somehow between two numbers)
  3. once the meter in that range the magnetic field is constant from the meter so you just check the positioning of the sensor (must be closed once you get the correct position) - use tape to fix the sensor, HA must report that sensor is “closed”
  4. once you start consuming gas again the sensor will go to “open” in HA once the 0.XX digit of gas meter will move to a number.

You can see in the picture that my meter was stopped at the constant impulse position XXX.7 2-3 9-0
If your meter has this marking is 100% that you have the impulse coming from it.

What should I be wrong?

Pay attention to measurement unit. Must be m³.

Many thanks for ideea Marius !

After I struggle with my gas counter, which I discovered that had the magnet unmagnetized, I asked the guys from gas company, to replace with a new one. As a charm, my counter started to work and now I can see how fast is increased my gas bill :frowning: