Hi,
i have a gas meter i want to track in Home Assistant. I have attached a reed switch to the gas meter and every time the second decimal place completes one turn the switch gets triggered.
I have created a pulse counter with ESPHome and a utility meter inside Home Assistant that tracks the total daily usage based on the pulse counter. However this is a very unprecise way of measurement, because the pulse meter often lags behind. I believe this is caused by the fact that the gas meter often is not turning at all, because no gas is used (see the attached picture) and ESPHome takes a few seconds to ārealizeā this and correct the value. Please correct me if i missunderstoof the functioning of the pulse counter.
Gas consumption in mĀ³/min
I also implemented a template sensor in ESPHome that simply counts the number of times the reed switch got triggered. This value perfectly corresponds to the actual value on the meter.
Im unsure where to go from here. While the second method results in precise values, im unsure how to implement this in Home Assistant. I also see the problem, that in the case of a power loss the esp loses the value and the whole measurement gets thrown off.
I canāt speak to the HA setup side of things, but you are rightly concerned about power/data loss. You could try adding a LiPO charger and battery to your circuit. Sometimes like this one could work:
Hi, thanks for sharing your project @saruter. I didnāt know traditional gas meters had that magnet feature. Iām going to check if mine supports this to try implementing your project.
A pair of questions:
when you say āextract from the ESP yaml codeā is it the full code needed for the ESP part or is it just a part (extract) of the whole code?
In the hardware needed you include: āKƤbelchenā that translates as āsmallā . I guess this is a typo or a bad translation, isnāt it? I understand that all is needed includes the magnet switch, the ESP8266 NodeMCU, the USB power supply and the housing, am I right?
Thanks again for sharing!!
Hi, nickrout is right, the code lacks the standard settings for Wi-Fi and so on but the code is complete for the reading and calculation.
KƤbelchen are the typical jumper wires often used with breadboards and so on. I used them to connect the loose end of the reed switch cable to the ESP (Female to Female Jumper Wire). Soldering is another optionā¦
Ok thanks, understood @saruter .
And regarding connections from the reed switch to NODE MCU: I understand that the reed switch is normally open and has 2 wires, so one will connect, according to your code, to GPIO5(D1) and the other one, I guess to 3V3?? Thanks again.
Hi! Iāve already implemented @saruter ESPHome gas meter(thanks!!) with espHome and Iāve already tied it with an utility meter. Itās working well but it is not very accurate. I guess because of the way it measures every 60 seconds. So if I understand your code:
Being the code as it is, if the gas consumption just stops (gas meter stops) precisely at the moment when it is closing the pullup input because of the magnetic reed and counter position closing the āswitchā, then, every 60 seconds (updating interval chosen) weāll get a not valid +0.01 increment into our gas meter.
I know nothing about esphome coding but, is there anyway to manage to trigger the sensor only if the switch has just changed from 0 to 1 and only then add +0.01 to our gas meter?? and after that only keep listening if the sensor has changed from 1 to 0 only?? If this is possible, measures would be completely accurate. Thanks again!!
Hi, @nickrout, very useful. Now I understand it, and as NodeMcu offers an input pull up mode (having internally the adequate resistor, it can just be connected as @MatthewFlamm pointed out: one wire to the input pin (in pullup mode) and the other to ground. Thank you both!!
OK, Iāve read the espHome code docs and now I get that teh platform pulse_counter already takes into account what I was talking about, but Iām still getting more counts than the real ones and I donāt understand why. Just in case I have included this to the code:
But the same issue still happens, itās counting more than real. Iāve no idea why I could have this problem. Now my gas meter itās not really accurate at all.
@jolaca: have you found a solution for accurate values? I also tried to build up the version @saruter mentioned, but get incorrect values.
What does your NodeMCU setup look like? I used that setup:
Hi, sorry, currently Iām not living where I have it installed and I donāt remember how I connected it. If I have time Iāll take a look at it and report back.
Consider reconsidering your design/architecture. (this may alarm some readers)
The sensor is not necessarily the best place to be tracking the ongoing state of the meter. And, itās harder to make the sensor be robust enough to store state across power glitches, etc.
Whereas, your HA installation - the receiver and ultimate database supporting your goal - is more likely to be fortified (UPS?) against power outage, but also will remember its data during an actual outage.
So in such a rebalanced design, you put the emphasis on how HA processes and retains the usage ātickā events for you.
For example:
Shift the āweightā of your design inboard, away from the āsensorā (the ESP) and toward the layer where the database will live.
Instead of having the ESP retaining state, let HA do that for you.
Let the ESP merely send HA the events when the pointer passes its mark, using the sensing equipment and setup you already have.
Turn your focus to how to make HA retain and present the data as you want.
Or consider using an alternative data gathering/presentation system (nagios, munin?) if HA doesnāt provide what the graph(s) you want to see.
Under this rebalanced design, in case of outage you may lose some usage events as the pointer passes the mark without being counted, but you wonāt lose the cumulative usage thatās already stored in HA. That seemed to be your ultimate goal, if I understood your OP at all.