First off, you need a reed contact for your type of gas meter. in my case, I have an “BK4” gas meter (pretty standard in Germany), which already has an predefined place for a reed switch like “elster IN-Z61”. So I plug that elster-thingy in my BK4, and at the other side of the cable I use a simple ESP8266 “D1 Wemos”, which gets the impuls wires “green” and “brown”, being brown on GND and green on GPIO-12 (D6). I also plugged in an Eltako WSZ15D-65A, which counts the energy for my whirlpool (that one on GPIO-13 (D7).
So, now we have the S0 pulse counters on the D1 Wemos and are ready to go:
- download (or flash directly) ESP Easy MEGA (don’t know, if Mega is needed, but sounds cool) from letscontrolit.com as described in Flashing — ESP Easy 2.1-beta1 documentation
- once, the ESP Easy is up, go into its web-UI and do the magic
- add an MQTT-controller under “controller” (I used Home Assistant (openHAB) MQTT),
you can adjust the topics to your liking in there!
- add a new device “Gas” as follows
** Internal PullUp: activated
** GPIO ← Puls: GPIO-12 (D6)
** Debounce Time (mSec): 10
** counter Type: Delta/Total/Time
** Mode Type: Falling
** Data Acquistion/single event: unchecked
** Send to Controller (1): activated (MQTT)
** Interval: 30 sec
** Values: leave as is (should be three: Count, Total and Time)
- now you have all you need
if you - for some reason are keen on calculating as much at the source as possible, especially if it’s crititcal to get the correct time calculations, you can let your D1 do the work for you!
So, what I did was not only send the raw pulses via MQTT (as explained in steps 1-5), but I wanted to let it calculate the kWh out of it, so I deactivated the “send to controller” part in step 4 and added a “Rule” in ESP Easy:
- add “rules” for ESP Easy (“Tools” - “Advanced”: check the “rules” box and submit)
- take Rule 1 (they’re numbered without the possibility to insert names)
- insert the following code for an gas meter with 100 impulses / m3 (1 imp for 0.01 m3)
On System#Boot do //When the ESP boots, do
event,"Rules#Timer=1" // Force initial update
loopTimerSet,1,30 //Set Timer 1 endless repeating for the next event every 30 seconds
endon
On Rules#Timer=1 do //When Timer1 expires, do
let,1,[Gas#Count]*3600*1000/30*0.9122*11.271 // calculate the Watts (depending on the local utility provider for gas
let,2,[Gas#Total]/100 // caclulates total m3 consumption
let,3,[Gas#Total]/100*0.9122*11.271 // calculates the total kWh (depending on the local utility provider for gas
Publish openHAB/%sysname%/Gas/W,[VAR#1] // sends the Watts to MQTT
Publish openHAB/%sysname%/Gas/m3,[VAR#2] // sends the total m3 to MQTT
Publish openHAB/%sysname%/Gas/kWh,[VAR#3] // sens the total kWh to MQTT
Publish openHAB/%sysname%/Gas/Count,[Gas#Count] // sends raw count
Publish openHAB/%sysname%/Gas/Total,[Gas#Total] // sends raw total
endon
- deactivate the “Send to Controller” in the device
- reboot the ESP
Now, it should send you the values every 30secs. I figured a shorter interval gets messy with the pulses, even if it’s as high as 3.000Watts or a bit higher, which my Whirlpool consumes, if heating is on. Luckily I have a potent PV!
=> the gas-part is untested, because it’s summer and my solarthermic is heating up my heating storage, so I’ll have to wait for late autumn to get correct gas consumptions…
I guess, I’ll put that on github, as I didn’t find much of this in the usual DIY youtubes, forums and stuff