Incoming item value should add to the item's current value

I managed to read out my Gas and Energy meters with and D1 Wemos, which sends me the current pulses every 30secs (it also conveniently calculates kWh out of the pulses and sends them also).
But: it doesn’t persist the total counts once it lost power - and begins to calculate anew.

I’d like to have the counts of 30secs to add to my “Raw Counts meter”-item, so I can check the total consumption once the Wemos was disconnected. is there a simple way to add incoming MQTT-payloads to an existing item, or do i have to use two items for this? one being the proxy item, which then adds to the real Counter-Item via a rule?

You’ll have to use two Items and a rule. But you may not need to write the rule. See Meter Reading. This rule template handles the case where the reporting device is reset back to zero but you want to keep up with the totals.

1 Like

Thanks - as usual! :wink:

Can you share your setup with Gas reading?? how you did it, with reed switch??

Thanks
Nikos

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:

  1. 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
  2. once, the ESP Easy is up, go into its web-UI and do the magic
  3. add an MQTT-controller under “controller” (I used Home Assistant (openHAB) MQTT),
    you can adjust the topics to your liking in there!
  4. 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)
  5. 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! :wink:

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:

  1. add “rules” for ESP Easy (“Tools” - “Advanced”: check the “rules” box and submit)
  2. take Rule 1 (they’re numbered without the possibility to insert names)
  3. 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
  1. deactivate the “Send to Controller” in the device
  2. 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! :wink:

=> 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

Thank you ,
Very good How to…
I ready my gas meter with a reed sensor https://www.ebay.de/itm/255283290267?hash=item3b7011e09b:g:0p4AAOSwapdb3x~k but when i switch on the light of the room that is the meter i get sometimes pulse count. i think have to do with
electromagnetic interference