3D PrintingHome Automation

Gas Meter Usage Sensor Using Zigbee Door Sensor

Since Home Assistant launched the Energy Management dashboard, I wanted to find a way to add my Gas usage to the dashboard. I’ve opted for the moment not to have a Smart Meter since the mess that was the SMETS 1 meter rollout, but that means I had to find a way to measure usage from my analog gas meter.

Commercial pulse sensor

The meter has a small magnet in the last digit of the dial, each rotation of the digit represents 10 cubic decimetres of gas consumption. You can buy a module specifically for the meter for around £40 here, but that still needs to be connected to something to actually measure the pulses. In order to sense the rotation of the magnet it just needs a reed switch, a £40 solution seems a bit overpriced.

Wireless Magnetic Sensor

To meet my requirements I needed a magnetic sensor that could send pulse information wirelessly and be battery powered with a 6-12 month battery life. I already have a number of magnetic door/window sensors around my house that use Zigbee and the battery life on those has been surprisingly good.

I initially tested to see if placing the door sensor on/around the meter would trigger it, but it didn’t, so I knew I’d have to be able to better position the sensor in order for it to work and provide accurate measurements. Opening the Aqara Zigbee magnetic Door/Window sensor I could see it used a simple glass reed switch, I was about to de-solder it when I noticed two pads on the PCB which connected in parallel with the sensor so I opted to leave the existing reed switch in place and solder on wires for the external sensor

Reed Switch

I could have used the glass reed switch from the door sensor, or sourced another glass reed switch, but I wanted something that looked a bit more professional, should someone take a look in the meter cabinet. I also wanted a sensor that I would be able to position easily. A quick search revealed a number of reed switches enclosed in plastic housings, the smaller ones tending to be used for pneumatic control systems. Based on availability and size I ended up with the D-Z73 reed switch sensor. Hooking this up and testing it held near the bottom of the meter showed that the pulses were sent on each rotation.

Mounting the Reed Switch

The meter has a couple of small plastic posts protruding from the front, in a small recess at the bottom right-hand cover of the meter dial. Taking some measurements I created a mount for the sensor that would press-fit over these posts and hold the sensor securely in place. The design is available over on Printables.com.

Home Assistant Integration

Along with tracking consumption, I wanted to track the cost of the gas and integrate it with the energy dashboard. To do this required the creation of a number of sensors, to track the units used, incrementing the value on each pulse received. Along with calculating the cost after converting the consumption to kWh. I wrapped up all the sensors etc into a package file for home assistant, which is available on GitHub.


Amazon links are affiliate links that help support the site

29 thoughts on “Gas Meter Usage Sensor Using Zigbee Door Sensor

  • Thank you very much for this. I thought you might be interested to know that I found your post and replicated your setup perfectly. I wrote my own HA automation from scratch, with subtle differences, but completely cribbed the hardware side.

    I asked a friend to 3D print the part, but unfortunately it doesn’t fit over my meter’s stubs. I’ll drill it wider when I get a chance. Until then I’m using Blu-Tack.

    Some photos, if you’re interested: https://imgur.com/a/hQhLWDy

    Thanks again!

    • So glad it worked for you. 3D printer tolerances can vary, so that may account for why it doesn’t fit. But you can’t go wrong with blu-tack 😉
      I hope a few spins for a drill bit, possibly even by hand, will get the mounting plate to fit.

  • Florian Schmidt

    Thank you very much for your work! This worked great for our Home Assistant installation and gas meter.

    I changed the sensors from £ to €. At the beginning I set input_number.gas_meter_m3 via Home Assistant service to actual meter standing. This causes HA to think we used ~20.000 m3 on Monday but it works. 🙂

    What is the sense of input_number.energy_gas_standing? I guess this should represent the basic price per day, correct?

    One last strange thing: energy dashboard shows no costs but the price sensors show some values. Any idea what I’m missing? I guess this is caused by my lack of knowledge about energy dashboard, yet.

    Best regards

    • Glad you’ve found this useful. `input_number.energy_gas_standing` is a standing charge price we pay in the UK for energy, whether we use any or not, intended to pay for the infrastructure. I’m not using that figure at the moment, it’s just on my dashboard and I update when it changes, I was thinking of how I might use in in a future sensor to track the real total costs.

      WRT to the price not showing on the energy dashboard have you edited there gas sensor on your dashboard, selected “Use an entity with current price”? For me this is `gas_meter_price_gbp_m3` which has a unit of measurement configured as “GBP/m³” I guess for you you’d need to change this to “EUR/m³”, and also ensure your HomeAssistant currency is set to “EUR”

      • Anonymous

        There’s an similar payment in Germany to receive gas supply independently you are consuming or not. This should work as is calculated the daily price value.

        I guess your hint for the cost tracking is absolutely correct. I configured the dashboard without cost tracking. 🙈 Home Assistant forced me to correct unit of measurement to “€/kWh” and now the configuration should be correct. I’ll monitor if the costs will be coming up.

        Thanks again!

  • Thanks for this write-up, I never realised our 15+ year old bog-standard Bord Gais meter had a magnetic element. I disassembled a tuya zigbee door / window sensor and taped the board under the lip of the meter dial and it was able to detect the magnet from there. It couldn’t detect it with the tuya casing intact.

    My only concern is that the meter-reading companies might suspect tampering or something if they see this small device attached to the meter? I might add a note underneath.

    Your automation and sensor YAML works perfectly in my own setup, with a few small tweaks. Converting m3 to kwh is a bit awkward but your templating works well here, I don’t think I would have figured it out myself. Thanks again

    • Hi David, glad you found it useful. Hopefully, anyone inspecting the meter or taking manual readings will understand what’s attached isn’t interfering with the operation.

  • Hello Martin,
    thx for that great script for Homeassistant. Changed everything to EUR and it works like a charm with copy & paste. the count was not the problem at the first setup (it works) but the energy meter didn´t recordnize the aquara sensor (but with your solution – fire and forget).

    is it possible to add some # in your yaml for definitions?

    • Hi Mike, glad this worked for you. Which aspects of the YAML file do you feel need explaining? I can look to add some comments, or if you wish you can submit a PR to add clarification where you think it’s needed.

      The Github is my a sync of my running configuration, I used to have a lot of comments in my files buy stopped doing it so much when editing via the UI was introduced for automations and each time you edit the automationes via the UI it removed all the comments from the YAML file. However as this is a separate package file I don’t think HA will remove comments.

  • Robert Fitzgerald

    Thank you for your guide and 3D file. I’ll aim to replicate this soon.

    Out of interest how long does the battery last in this sort of setup?

    • I’ve changed the battery once since I installed it, I can’t recall how long it was after installation maybe 6 months.

  • My UK meter is even older and uses ft3
    I do have a rj11 socket which I believe gives out a pulse like a reed contact
    I assume your meter didn’t have a rj11 socket hence mounting a read contact on there

    • Correct, my meter doesn’t have a handy socket, hence the need to use the reed switch. You should in theory be able to use the same magnetic door sensor and have it work with the RJ11 connection, which I imagine is probably just an internal reed switch, since I can’t imagine anything electronically active.

      • Kev Willers

        Thanks all set up and working fine.

        • @Kev Would you submit a PR to the repro with the sensors needed to handle measurements in ft³? Commented out in the file is fine, just would be good to include it in order to help others out. Specifically, I guess I’m asking if you just converted to kWh, or if you also needed to convert to m³ in order to get the usage data to report correctly in the Energy Dashboard.

          • I try and add it to the repo. Github and I are not friends 🙂 I removed lots of the sensors as I didn’t need them for the Energy Meter.

            But the key was to just convert to kWh and then created a sensor for daily cost.

            The biggest thing to watch out for is day one reading in the Energy meter will be ridiculous because it will make day one the value of your current meter reading. Just let it run until the next day then use the developer tool – ‘Statistics’ to remove the erroneous entry.

            • HI Kev, If you’re not comfortable with fighting GitHub. Feel free to use the contact form on the site and send me an email with the sensors and I’ll update the repository.

              • Kev Willers

                sent my yaml with comments

                • Thanks, got your email and I will update the file at the weekend.

        • Ravi Mohta

          Would you be able to share some details photos of how you setup the aqara sensor to work with gas meter with RJ11 socket? I have a gas meter which says schlumberger R5 and it has RJ11 socket under the rotating dials.

          I am good with home Assistant side but just need to be sure of the wiring and setup of the sensor to work with RJ11 socket, so any help would be really appreciated.

  • How do I create the sensor.gas_price_day ?

    ” utility_meter_gas_cost_daily:
    source: sensor.gas_price_day
    cycle: daily”

  • This is a great write up and simple enough to make me think I can do it too.

    However it looks like we have a parkinson Cowan meter which has a rotary dial on RHS. From what I read this is type has no magnet opportunities. I saw another tinkerer solved it with a mouse sensor but looked a bit too heath Robinson for me. Any other ideas like camera? Or maybe a smart meter upgrade would provide this information more directly.

    • I’m glad you liked the write-up Mick. I’m assuming this is the meter and method you’re referring to: https://www.rotwang.co.uk/projects/gasmeter.html

      It’s unfortunate the meter won’t work with the simple magnet approach it does make things more complicated and typically will mean needing to use an approach which won’t be suitable for battery use. You could explore character recognition systems like: https://github.com/jomjol/AI-on-the-edge-device but this tends to get more complex and can be sensitive to changes in light levels.

      What I would investigate are a couple of ideas:

      Going for a smart meter is obviously simpler, but depending on the energy supplier their API for accessing the data may not be great (if they have one at all), or may not be frequently updated.

  • Hi, just used a flood sensor to replicate this on a water meter and changed gas to water.

    I am new to HA, so apologies if this sounds stupid, but with the gasmeter.yaml file with the sensor etc, i cant see the readings or calcs on usage etc.

    How do i modify the config.yaml to read gasmeter.yaml?

    • I’m using the packages feature of HA. Which is useful for grouping a collection of different entity types into a single file. So to use this, you need to modify configuration.yaml with:

      packages: !include_dir_merge_named packages/

      (Note the packages entry should be indented, but the spaces are being stripped out in this comment section)
      Then create a packages directory and write the gasmeter.yaml (or watermeter.yaml as you see fit) into that folder. Then restart HA to pick up the changes.

  • Thanks for the write up!

    My meter is a Honywell / Elster BK-G4M, I tried the same combination of D-Z73 soldered onto an Aqara door sensor. While I was able to close/open the switch with a normal magnet, it seems like the sensor isn’t sensitive enough to pick up the pulse from the meter, I tried a number of locations but nothing each time.

      • Ah thanks for digging that out, I gave that a go but no luck unfortunately.

        My android phone does seem to corraborate that the magnetic field is strongest by the front of the display, it measures ~600 microtesla at the strongest point when the phone is pressed against the display while the meter completes a rotation.

        Very roughly, I found the maximum distance from a magnet that the reed switch would activate and then placed my phone’s magnetometer at the same distance from the magnet in the same orientiation and found it measured ~2500 microtesla, so some ways off.

        The strength of the pulse of my meter seems low, thinking I might have more luck with a hall effect sensor. Will update this thread if I have any luck and thoughts/suggestions welcome.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.