Old analog gas meter located outdoors

It’s this one here:


1 Like

@brooksben11 sorry for all the questions, I’ve been watching my data flow in for the past couple weeks, and it’s definitely stable however i still need to adjust the code.

Can you help by providing a screenshot of your data curve so I can make some comparisons between your high and low in the code as compared to your graph?

I also changed my unit of measurement to cubic meters, since in Canada we use metric. So I still need to adjust my code to also suit that change.

I’ll be honest, I’m a little confused on the lambda parts.

No worries!

Unfortunately I only captured the raw data for a few minutes while I calibrated things some time ago, so I don’t have it anymore. My general approach was this: after I identified the axis that had the largest/cleanest sinusoidal wave, I then figured out the max/min values that it oscillated between as well as the mid-point. Then I just used a value that was roughly halfway between the max and mid value and used that as my upper threshold and did the same thing with the min value to come up with a lower threshold. The reasoning is, I wanted values far enough apart that random noise wouldn’t ever cause it to count a cycle but also far enough from my observed max/mins that if some readings are missed it hopefully will still count a cycle.

Which ones, the interval cycle counts or the Rate & Total parts? Admittedly the Rate and Total ones are kind of hacky and could use to be cleaned up; I’m not great at C++ and then adding in the intricacies of HA and ESPHome makes it worse, so I just kind of brute-forced it until I got what I wanted and left it when it worked. :upside_down_face:

Feel free to ask away and I’ll help as best I can!

OK, let me work through your first part of the response. I’m guessing me having the data constantly dump into HA over the past few weeks every 0.1s is what’s exploding my database size. LOL

I’m sure more questions will follow as I work through this. Thanks for your help :slight_smile:

Alright, let me know if I’m off base here, or if this looks correct. Based on this wave graph:

-20.3 uT   # This is the highest point in the cycle from the graph
-31.0 uT   # Mid-point between high and mid-point of cycle = HIGH factor for code
-41.8 uT   # This is the mid-point in the cycle by dividing the delta of the high and low points by 2
-52.0 uT   # Mid-point between low and mid-point of cycle = LOW factor for code
-62.1 uT   # This is the lowest point in the cycle from the graph

Therefore I’ve edited the interval lambda code to be this:

  - interval: 0.1s
    - lambda: |-
       if (id(gasz).state > -31 && !id(gas_high)) {
          id(gas_counter_total) += 1;
          id(gas_counter) += 1;	
          id(gas_high) = true;
        } else if (id(gasz).state < -52 && id(gas_high)) {
          id(gas_high) = false;

I think I’ll pause here and wait for some confirmation, before I look any closer at the Gas Rate and Gas Total lambda’s.

With the above changes, I am now actually seeing a value for my Gas Rate (when the furnace is running) on the HA card, along with an incrementing amount for the Gas Total.

Looks good to me!

1 Like

As I try to understand the lambda code for Gas Rate and Gas Total, a couple questions come to mind.

Below code is what I am currently using, all I’ve done is change the unit of measurement from 'ft³/min' that you had to 'm³/min' for the Gas Rate lambda.

I understand the multiply by 2 part relates to the interval of 30 seconds, so x2 is the value for 1 minute.

Is the “8 counts per cubic foot” comment, in regards to how many full cycles of the sine wave occurs for every 30 seconds? Or is it 8 full cycles of the sine wave for each revolution of 1 cubic meter on my gas meter outside?

Is the value of 8 a variable that is specific to your meter readings and gas rate, so I need to be outside, watching the meter as the dial measures 1 cubic meter, while also watching my HA graph, to see how many cycles of the sine wave in that same time period?

I’m still not fully clear on the formulas for lambda, but I think understanding the above, might help me clear the formulas up in my mind.

#8 counts per cubic meter, multiplied by 2 to get per minute based on update interval
  - platform: template    
    name: "Gas Rate"
    lambda: |-
      int temp = id(gas_counter);
      id(gas_counter) -= temp;
      float temp2 = temp;
      float temp3 = (temp2/8)*2; 
      return temp3;
    update_interval: 30s
    unit_of_measurement: m³/min
    device_class: 'gas'

  - platform: template    
    name: "Gas Total"
    lambda: |-
      float temp = id(gas_counter_total);
      return temp/8;
    update_interval: 1s
    unit_of_measurement: 'm³'
    state_class: 'total_increasing'
    device_class: 'gas'

Exactly that. I just turned on the furnace and counted how many cycles in saw in the HA graph as I watched the meter count up one cubic foot. In my case, it was exactly 8 cycles per cubic foot. I assume that you’ll either end up with a nice clean number for cubic meters as well (or it might actually match to a cubic foot number if you’re in North America and the meter was manufactured in the US. If you find yourself getting a partial number of cycles per cubic meter, I’d check what it comes to when you convert it to cubic feet).

1 Like

How do y’all handle getting the data back to an ESP? To get my ESP close enough to a a wifi point I need the wire going from my QMC5883L to the ESP to be longer than i2c can work.

I was thinking about putting an ESP-01 in the box as well, having the ESP-01 communicate to the QMC and then sending the values over serial to my esp32… but I’m hoping you have a smarter idea :rofl:

The grey wire exiting my outside weatherproof box (with the QMC5883L sensor) goes about 3 ft into the basement through the brick exterior wall and is currently mounted in my basement ceiling.
Eventually this will be finished with drop ceiling panels but is currently unfinished. HA project get in the way of finishing the basement! :upside_down_face:

I still need to shorten and solder the wires to the ESP, then enclose it all into a small box such as the one shown below. My wireless AP is only 30 ft across the basement, and it works great.

Power is supplied down the wall via a long USB cable and power block. I might also run power up to a b ox in the ceiling, to avoid this wire down the wall.

How far away is your gas meter from the closest wireless access point?

Actually, I might be wrong about this, I took everything apart and am trying to communicate to the board with them sitting right next to each other with less than a foot of breadboard wires and my ESP won’t respond over wifi. I either have a bad solder joint or a bad board, I’ll try and get a replacement and try again in a few days.

You might have a look at your door bell circuit power, this is somethings a way to power esp devices over fairly long distances without having to do the whole usb wall wart and usb cable. The various low cost buck converters and a good capacitor can make this a useful path. Do note that door bells in USA are often 24 volt AC (<- IMPORTANT to note), so you need to make sure your buck solution can start there.

Good hunting!

1 Like

Do you mean, running a power source from the doorbell transformer across the basement to my ESP devices? I currently have a couple using this USB cable/power block method, and if I could just run another low voltage wire, it would be awesome.
I have a Ring Doorbell and transformer as shown below which is 16V.
I’m not familiar with capacitor’s but will need to look into this. I assume the Capacitor will drop the voltage down to 5V or 3.3V for the ESP?

The ‘magic’ is the ‘buck converter’ device. I just thru in capacitor as an added ‘shock absorber’ in case you have Big Ben for a door bell :wink:

Google buck converters and you will see lots of options and explainers on how to use. The link below is for an example device, note I have not used it, that should handle the AC/DC issue. I don’t think you need the ‘adjustable’ feature of this one, but it might be fun to have one of these in your tool chest to experiment with different inputs and outputs.

Good hunting and good success home automating into 2024!


Flat CAT5 (or greater) cable is another good tool in your HA tool box for low voltage. Easy to run and stick up. Low cost ethernet breakout plugs at each end to use the wires with power source and with ESP at other end.


Well, I got it working in the end. I had to greatly reduce the length of my wire, but that was my own shortsightedness. My graph is looking good

and I’ve set my limits based on my graph after running my hot water heater to

High - 20
High Mid - 17.7
Mid - 15.4
Low Mid - 10
Low - 4.6

I realized afterwards, that I didn’t count the revolutions of my two cubic feet needle, so at the moment I’m making the assumption that my meter also does 8 cycles a cubic foot, but I’ll turn on the hot water again and count it up to confirm.

Great project!

1 Like

Okay, followup question, do you have to re-calibrate your device every time the power is lost?

I’ve done a couple power cycles as I’ve transitioned it from my temporary wiring into something a little more robust and I’ve noticed that each time my limits seem to have changed.

A) Does that happen to you as well


B) Can you think of a way that after a power cycle it could set some sort of min/max variable or maybe a “calibrate” button that you could trigger to have it recalculate min/max values that could then be used to find the high and Low mids?

I haven’t had to recalibrate it, mine remembers the limits and they seem to remain the same continuously.

I’ve created a coded reset sensor to restart it if it freezes which it did a couple times.

Post your code for others to review, maybe something’s missing.

Also, how is your device mounted, maybe it’s shifting somehow which would cause different readings.

I have it in a small plastic enclosure like shown above, I’ve attached it to the back of my meter using some 3m tape