Gas meter sensor

First post ever. Hope I’m doing it right.
I wanted to integrate my gas meter with homeassistant. Unfortunately my gas meter is an ancient design and has no smart output but Fortunately my gas meter has a magnet embedded under the last digit on the dial so I could build a sensor.

In in Melbourne Australia and my meter is a landis and gyr model 750.

I’ve created a sensor based on an ikea tradfri dimmer switch E1743. It is the small 2 button battery powered dimmer.

It is about the cheapest zigbee switch that I can readily find that I also was confident that I could modify to meet my needs.

Jamie D has a hack for this switch on this site:

I soldered a reed switch bridging one of the micro switches in a similar way.

I then paired this with my homeassistant running zigbee2mqtt. As the magnet goes by quite slowly the switch registers the closed circuit as a brightness_move_up action. I’ve setup an automation to count these actions with a helper (Starting from the existing reading on the meter so it is synchronised with the physical meter value so I can see if any counts are missed). The meter measures gas volume in m3.

I’ve used this value multiplied by the appropriate constants to convert gas volume to kWh in a total_increasing sensor. This can then be fed to the energy dashboard.

It has been going almost a week now and has only dropped 2 readings in that time. I might need to put a zigbee repeater closer to help avoid that further but generally I’m pretty happy with it!

If anyone is interested I can post further details.

7 Likes

Hey
Thats a great idea. I am in Perth and have a similar gas meter. Are you able to share some install photos?

How does it look in the dashboard? Curious to how it performs realtime.

This sounds like a great project to do this weekend.

Real-time sensors:

I’ll grab a photo of the meter and the switch in another post a bit later today.
Dashboard pic in next post

Frankly the hardest part of the whole thing was the Zigbee2mqtt part. I had hoped I could see the switch through the hue hub that I had, but I could not. So I picked up a cheap zigbee2mqtt dongle off eBay and went that route instead and with the bonus that now I can use any brand zigbee device.

1 Like

This is awesome, thanks for the details so far. I have the same meter (and in Perth) and have a Tradfri Shortcut Button I might try this with.

Keen to see your meter photo so I can match the reed switch location.

Meter photo. Reed switch placement is important. I just hooked it up to a multimeter and played with placement. Facing one way is better than the other. It is stuck with blue tack. But no blue tack above the switch itself only on the side.

1 Like

Sensor photo.
My soldering is a bit rough. It is an old Tupperware container. A bit of desiccant from vitamin jars underneath to help avoid condensation.

Great pics thanks - I’ve soldered up and tested my reed switch to Tradfri shortcut button and it works well. I have it incrementing a helper counter (set initial value to the current meter value) and it seems to work.

Now the bit about total_increasing sensor is where I’m lost. How did you do that? A bit of YAML code?

here’s my code. I’m not a YAML expert so if anyone has any suggestions I’d welcome them.
Total gas energy calculated from meter values (which are m3/1000) by multiply by correction factor 1.0109, heating value 38.588 (from my Origin Energy Bill).
Then divide by 1000 to allow for my home assistant synchronised meter missing the decimal point and being read as Litres instead of M3 then multiply by 0.27778 to convert from MJ to kWh

counter.gas_meter is my helper synchronised with the gas meter number (but without the decimal point in my case). Ive got it incrementing 10 at a time (each revolution of the dial is 10 minimum divisions of the meter).

template:
  sensor:
    - name: "gas_total_use"
      state: "{{ (states('counter.gas_meter') | float * 1.0109 * 38.588/1000 * 0.27778) | round(1) }}"
      unit_of_measurement: "kWh"
      state_class: total_increasing
      device_class: energy 

I’ve got this code in my configuration.yaml file

If you’ve got a pic of your modified tradfri shortcut button I’d be interested. I was originally looking at using one of those, but I did not want to buy it and find that I could not modify it.

Thanks - Sunday’s project is to have a crack at your code solution!

Here are two pics of the shortcut button. I damaged the one in the photos, possibly with too much heat on the switch when I wired it up as you see it in the first pic. It resets and re-pairs but won’t register a button press at all anymore. I even tried removing the switch altogether and looked around the circuit board for another couple of pickup points for the reed switch. Fortunately I had a second one and was more careful.

What I found was that the D1 you see me pointing at in the second pic, is connected to the onboard switch poles, so just solder your reed switch to those two points and all done!


1 Like

That’s helpful!

I note that on the dimmer that I modded there is also a D1 and D2 marked near each of the switches. I suspect I’ll be making another one or two of these so I might try soldering to those points instead.

Update 3 March 2023: I did a second one of these switches and was able to successfully solder to d1 and d2 instead of the main switch.

1 Like

Just went to Ikea Perth today… Out of stock!!! Should be back next weekend.

My idea is to remove the Trafidi PCB and enclose it into a waterproof Jaycar enclosure, mounted under the Gas meter box.

Couple of coin batteries? Maybe can be replaced by few rechargeable AA.

That’ll probably look better than a Tupperware container!

Just jumped on the jaycar site and I’m surprised by how cheap they and the battery holders are. I’d considered replacing the coin battery with a rechargeable battery. If you do I’d be keen to see how you do it.

Looks like they are back in stock! I will grab one tomorrow.

Ive been thinking, we are only using one of the buttons for the gas meter. What if we used the other button to monitor the water meter?

Good to see some other Aussies and especially Perth people on these forums! hope you are enjoying the rain

I have the same gas meter at my house, I tried the reed switch a while ago but found it somewhat unreliable, not wanting to hijack your thread but thought you may find some of this helpful

due to miss reads with the reed switch I ended up changing to a hall sensor. I had issues with pulses being missed and a couple of times the wheel stopping right on the edge and causing many reads throughout the day even though no gas was used. this is the one I used https://www.jaycar.com.au/arduino-compatible-hall-effect-sensor-module/p/XC4434

Instead of a battery powered unit I’m using an esp8266 from jaycar and just powering it from a usb adaptor. WiFi Mini ESP8266 Main Board | Jaycar Electronics

as my power meter is directly above the gas meter I also have a photodiode to count the flashes Infrared Phototransistor | Jaycar Electronics the only other item needed was a 10k resistor for the photo transistor.
I ended up an old USB cable to remote mount the sensors, both are about a meter from the ESP and seem very reliable. both the photo transistor and the hall sensor are held in place using blutac

for the gas meter - the hall sensor is connected to 5v, GND and GPIO5/D1
the photo transistor is connected to 3v3 and the other terminal to GPIO4/D2
the 10k resistor between GPIO4/D2 and GND

the ESP is flashed with a custom build of Tasmota with Smart Meter Interface - Tasmota

the script to load into tasmota

>D
>B
->sensor53 r
;disable publishing at MQTT teleperiod, on boot
smlj=0
>S
;re-enable publishing at MQTT teleperiod, after 10 seconds of uptime
if upsecs>20
then
smlj=1
endif
;recalc descriptor math
smld(2)
>M 2
+1,5,c,1,-10,GAS
+2,4,c,1,-10,Power
1,1-0:1.8.0*255(@100,Gas,m3,Count,3
2,1-0:1.8.0*255(@1000,Power,kWh,Count,3
2,=d 2 10 @1,Current Power,W,Power,0
#

this basically gives 3 readings to home assistant, im not even sure how the values are pulled in… its just magic! gas count, power count, instantaneous power
i then use these into utility meters to be able to graph etc

utility_meter:
  quatrerhour_electricity:
    source: sensor.utility_meter_power_count
    cycle: quarter-hourly
    tariffs:
      - peak
  daily_electricity:
    source: sensor.utility_meter_power_count
    cycle: daily
    tariffs:
      - peak
  monthly_electricity:
    source: sensor.utility_meter_power_count
    tariffs:
      - peak
  quaterhour_gas:
    source: sensor.utility_meter_gas_count
    cycle: quarter-hourly
    tariffs:
      - peak
  daily_gas:
    source: sensor.utility_meter_gas_count
    cycle: daily
    tariffs:
      - peak
  monthly_gas:
    source: sensor.utility_meter_gas_count
    tariffs:
      - peak

here are some templates I use that you may also find useful, values should be spot on for Perth’s only power provider, for others the 0.266612 is the unit cost for power, and the 0.955818 is the daily supply charge.

template:
  - sensor:
      - name: Today Energy Total Cost
        device_class: monetary
        state_class: measurement
        unit_of_measurement: AUD
        state: >
          {{ (states('sensor.daily_electricity_peak') | float * 0.266612 + 0.955818) | round(2) }}
  - sensor:
      - name: Yesterday Energy Total Cost
        device_class: monetary
        unit_of_measurement: AUD
        state: >
          {{ (state_attr('sensor.daily_electricity_peak','last_period') | float * 0.266612 + 0.955818) | round(2) }}
  - sensor:
      - name: Next Bill Estimate
        device_class: monetary
        state_class: measurement
        unit_of_measurement: AUD
        state: >
          {{ (states('sensor.monthly_electricity_peak') | float * 0.266612 + (0.955818 * ((now() | as_timestamp | int - state_attr('sensor.monthly_electricity_peak','last_reset') | as_timestamp | int) / 86400 ) | int )) | round(2) }}

I use an input helper to adjust my billing cycle. its almost automatic with this automation and I just correct it manually if it starts getting out of sync with my bills

alias: Power Bill Reset
description: ''
trigger:
  - platform: time
    at: input_datetime.power_bill_reset
condition: []
action:
  - service: utility_meter.reset
    target:
      entity_id: utility_meter.monthly_electricity
    data: {}
  - service: input_datetime.set_datetime
    target:
      entity_id: input_datetime.power_bill_reset
    data:
      datetime: >-
        {{ (state_attr('input_datetime.power_bill_reset', 'timestamp') + (61 *
        24 * 60 * 60) ) | timestamp_custom ('%Y-%m-%d %H:%M:%S') }}
mode: single
5 Likes

I don’t think my water meter has a magnet in the counter. Is that a thing that they have too? Maybe I should check more closely.

It does seem wasteful not using the second switch!

What sort of level of missed reads did you have? I’ve been getting the occasional one but not too many generally. By chance in the last few days I had many missed reads and found that it was because a zigbee globe nearby had been turned off at the Switch and so was lost from the mesh network. Enough were getting through that it had not outright failed but I was missing probably 70%. I put in a repeater nearby and no missed reads so far at all since then.

When I originally placed the Reed switch I found placement was critical. I experimented with all possible orientations to find the one that worked best. The fully rectangular switch Rebem used would have given more potential placement options than the more odd shaped one I used but I did find a spot where I was happy. My next step was to sand off a bit of plastic from the casing of the switch so it could be closer to the magnet but I did not have to resort to that.

I’ve had no issue with too many reads due to the meter stopping at the point the Reed switch is closed for a long period of time. I think the ikea switch I’m using is (by chance) helping avoiding that issue. I must admit it was something I did worry about but it has not been a problem.

I do admire your technical capability - quite ahead of me!

I think there was some issues with my debounce settings, it was too short initially (maybe 50ms?) which caused double and triple counts every time the wheel went round but only when just my heater pilot light was on, so my thinking was the wheel moving really slow into the range of the reed switch. there was also a day where I used more than double my normal gas, but when I checked the meter it hadn’t changed at all, I suspect it stopped at exactly the wrong spot and just sat triggering continuously.

I then changed the debounce to something I though was clever, calculating at maximum flow of 8m3/hr=13.3pulses/minute or 1pulse every 4.5seconds maximum, I set something really high like a 500ms debounce which fixed the double and triple counts for a single rotation.

Later I noticed some missed counts, initially it was only one or or 2 but then in winter when I had the gas heater on and the hot water cranked up to maximum it would miss a few more counts than normal. I think it may have been spinning too fast for the debounce to pick it up, although it was only 1 pulse every 4.5seconds the pulse itself may not have been more than 500ms. which thinking about it now I doubt the magnet in the wheel would be emitting a field that takes up 2/9th’s of the circumference of the wheel?

but anyway for the current hall sensor I have a counter poll interval of 10ms, which essentially provides the debounce. this seems to work very well and I haven’t needed to adjust it.

As for the water meter, I am using GitHub - jomjol/AI-on-the-edge-device to read the meter using AI, it works OK… the occasional miss read but generally only correcting the meter every other week now. I was thinking of changing the gas meter to this as well, but the current hall sensor is so reliable I don’t see the need. The good thing is the cheap ESP cam it runs on, but I have spent hundreds on a solar setup to power it due to its location, not to mention the hundreds on mesh wifi to get the range out there too haha.

at my old house I had a different water meter that would accept a reed switch in a hole that had a small black plug in it originally. this worked pretty well, but I had battery issues with such a small solar panel and the way I was waking and connecting the Bluz device via BT to the particle cloud then going to sleep. a long shower every night made the battery drain more than it could charge during the whole day.

Hi @GobblerGuy

Thanks for sharing your project.
I just created a sensor out of a z-wave device (door sensor from Amazon Ring alarm system).

Would you mind sharing the helpers / entities you use and potentially the automation to update these?
I am relatively new to HA (coming from openhab) and don’t understant all the different entity types yet.
Best regards,
NCO

Interesting @chris.huitema , I wonder if the spinning old electrical meters have a magnet that spins where the hall sensor can be used. What does the flashing for your project to read?