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.

Links

Amazon links are affiliate links that help support the site

32 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!

    Reply
    • 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.

      Reply
  • 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
    Florian

    Reply
    • 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”

      Reply
      • 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!

        Reply
  • 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

    Reply
    • 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.

      Reply
  • 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?

    Reply
    • 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.

      Reply
  • 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?

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

      Reply
  • 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

    Reply
    • 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.

      Reply
      • Thanks all set up and working fine.

        Reply
        • @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.

          Reply
          • 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.

            Reply
            • 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.

              Reply
              • sent my yaml with comments

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

                  Reply
        • 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.

          Reply
  • How do I create the sensor.gas_price_day ?

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

    Reply
  • 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.

    Reply
    • 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.

      Reply
  • 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?

    Reply
    • 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:

      homeassistant:
      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.

      Reply
  • 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.

    Reply
      • 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.

        Reply
        • Just to follow up on this one, I picked up some a batch of “Y213” reed switches (~£2 on ebay for 5) and found they work nicely. Just soldered onto some wire and used some tape to position it in the indent under the meter and am now seeing pulses come through

          They’re much smaller which I believe helps get closer to the magnet in the meter.

          Reply
  • Hello!
    Thanks for your work! I have added and adapted your template to HA and it’s working well with zigbee door sensor TS0203_TZ3000 pointing to last rotating number in front of my gas meter. I only have a trouble with the initial value manualy entered. After that the values from some meters and long term utility meters long term show irreal values (i.e. sensor gas_price_day_last show 10833.8 € due the initial value!). Do you know how I can correct this ?

    I tried with Developer Tools > Statistics and correct values with the ramp but not works for me…
    Thanks!

    input_number.energy_gas_standing
    Gas preu Terme fixe (€/mes)
    7.83 initial: null
    editable: false
    min: 0
    max: 999999
    step: 0.001
    mode: box
    unit_of_measurement: €
    friendly_name: Gas preu Terme fixe (€/mes)
    input_number.energy_gas_unit
    Gas preu terme variable (€/kwh)
    0.055494 initial: null
    editable: false
    min: 0
    max: 999999
    step: 0.0001
    mode: box
    unit_of_measurement: €
    friendly_name: Gas preu terme variable (€/kwh)
    input_number.gas_meter_reading
    Gas Lectura Comptador
    17444.76 initial: null
    editable: false
    min: 0
    max: 999999
    step: 0.001
    mode: box
    unit_of_measurement: m³
    friendly_name: Gas Lectura Comptador

    sensor.comptador_gas_bateria
    Comptador Gas Bateria
    100 state_class: measurement
    battery_voltage: 3
    unit_of_measurement: %
    device_class: battery
    friendly_name: Comptador Gas Bateria

    sensor.comptador_gas_total
    Comptador Gas Total
    17444.76 state_class: total_increasing
    unit_of_measurement: m³
    device_class: gas
    friendly_name: Comptador Gas Total

    sensor.gas_meter_kwh
    gas_meter_kwh
    200824.08 unit_of_measurement: kWh
    friendly_name: gas_meter_kwh

    sensor.gas_meter_price_m3
    gas_meter_price_m3
    0.6388 unit_of_measurement: €/m³
    friendly_name: gas_meter_price_m3

    sensor.gas_price_day
    gas_price_day
    1.76 unit_of_measurement: €
    friendly_name: gas_price_day

    sensor.gas_price_day_last
    gas_price_day_last
    10833.8 unit_of_measurement: €
    friendly_name: gas_price_day_last

    sensor.gas_price_hour
    gas_price_hour
    0.02 unit_of_measurement: €
    friendly_name: gas_price_hour
    sensor.gas_price_hour_last

    gas_price_hour_last
    0.27 unit_of_measurement: €
    friendly_name: gas_price_hour_last

    sensor.gas_price_month
    gas_price_month
    10842.87 unit_of_measurement: €
    friendly_name: gas_price_month

    sensor.gas_price_month_last
    gas_price_month_last
    7.83 unit_of_measurement: €
    friendly_name: gas_price_month_last

    sensor.gas_price_week
    gas_price_week
    10836.85 unit_of_measurement: €
    friendly_name: gas_price_week

    sensor.gas_price_week_last
    gas_price_week_last
    1.81 unit_of_measurement: €
    friendly_name: gas_price_week_last

    sensor.utility_meter_gas_cost_daily
    utility_meter_gas_cost_daily
    1.50 state_class: total_increasing
    source: sensor.gas_price_day
    status: collecting
    last_period: 10942.81
    last_valid_state: 1.76
    meter_period: daily
    cron pattern: 0 0 * * *
    last_reset: 2024-01-10T23:00:00.011880+00:00
    unit_of_measurement: €
    icon: mdi:counter
    friendly_name: utility_meter_gas_cost_daily

    sensor.utility_meter_gas_daily
    utility_meter_gas_daily
    27.06 state_class: total_increasing
    source: sensor.gas_meter_kwh
    status: collecting
    last_period: 195220.06
    last_valid_state: 200824.08
    meter_period: daily
    cron pattern: 0 0 * * *
    last_reset: 2024-01-10T23:00:00.006940+00:00
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    friendly_name: utility_meter_gas_daily

    sensor.utility_meter_gas_hourly
    utility_meter_gas_hourly
    0.23 state_class: total_increasing
    source: sensor.gas_meter_kwh
    status: collecting
    last_period: 4.72
    last_valid_state: 200824.08
    meter_period: hourly
    cron pattern: 0 * * * *
    last_reset: 2024-01-11T10:00:00.006099+00:00
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    friendly_name: utility_meter_gas_hourly

    sensor.utility_meter_gas_monthly
    utility_meter_gas_monthly
    195247.12 state_class: total_increasing
    source: sensor.gas_meter_kwh
    status: collecting
    last_period: 0
    last_valid_state: 200824.08
    meter_period: monthly
    cron pattern: 0 0 1 * *
    last_reset: 2024-01-10T11:23:13.410939+00:00
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    friendly_name: utility_meter_gas_monthly

    sensor.utility_meter_gas_weekly
    utility_meter_gas_weekly
    195247.12 state_class: total_increasing
    source: sensor.gas_meter_kwh
    status: collecting
    last_period: 0
    last_valid_state: 200824.08
    meter_period: weekly
    cron pattern: 0 0 * * 1
    last_reset: 2024-01-10T11:23:13.177191+00:00
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    friendly_name: utility_meter_gas_weekly

    sensor.utility_meter_gas_yearly
    utility_meter_gas_yearly
    195247.12 state_class: total_increasing
    source: sensor.gas_meter_kwh
    status: collecting
    last_period: 0
    last_valid_state: 200824.08
    meter_period: yearly
    cron pattern: 0 0 1 1/12 *
    last_reset: 2024-01-10T11:23:13.420202+00:00
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    friendly_name: utility_meter_gas_yearly

    Reply
    • I’d have thought editing the value as you attempted would be the right approach. Else you’ll need to edit the database directly. Alternatively. don’t worry about it, I don’t think I ever went and corrected my initial value (or any corrections)

      Reply

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.