ESP Easy MEGA: sending RAW pulses plus calculation to controller

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
binderth
New user
Posts: 6
Joined: 15 Apr 2022, 10:08

ESP Easy MEGA: sending RAW pulses plus calculation to controller

#1 Post by binderth » 15 Apr 2022, 10:23

I'm using ESP Easy MEGA (mega-20220328 - ESP_Easy_mega_20220328_energy_ESP8266_4M1M Mar 28 2022) with my D1 Wemos.

What I'm trying to do is to fetch the impulses from a energy meter (Eltako WSZ15D-65A) and my gas meter (elster IN-Z62). They send their pulses to
  • GPIO-12 (D6) => gas (200 impulses / m3)
  • GPIO-13 (D7) => energy (2000 impulses / kWh)
As I'd like to have the D1 calculate the consumption, I configured the devices as follows:

Energy:
  • Internal PullUp: activated
  • GPIO <- Puls: GPIO-13 (D7)
  • 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
    • 1: W -> %value%*3600/2/30
    • 2: kWh -> %value%/2000
    • 3: Time -> empty
This works just fine. But I also want to have the RAW pulses sent in parallel, but if I add a second device and use the Generic - Pulse Counter with the same GPIO - all gets confused! ;)
Is there a simple way to sent both raw pulses and the consumption of a energy meter?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP Easy MEGA: sending RAW pulses plus calculation to controller

#2 Post by TD-er » 15 Apr 2022, 11:03

You can leave the values as raw values in the task and then periodicaly read those values from the rules and process them there.

One (rather big) advantage is that the values restored from RTC at boot (without power loss) will still be raw and will not be converted again by the formula.
Another advantage is that you can control the moment when the values are converted and published.

binderth
New user
Posts: 6
Joined: 15 Apr 2022, 10:08

Re: ESP Easy MEGA: sending RAW pulses plus calculation to controller

#3 Post by binderth » 15 Apr 2022, 11:50

TD-er wrote: 15 Apr 2022, 11:03 You can leave the values as raw values in the task and then periodicaly read those values from the rules and process them there.
That sounds great!
you mean with that:
https://www.letscontrolit.com/wiki/inde ... rial_Rules

So, to understand:
  1. After booting, the timer 1 is set for 30secs
  2. timer 1 executes itself plus sets itself for another 30secs
  3. in System#Boot and Rules#Timer=1 I can
    • access the pulses via [DeviceName#ValueName] (after reset it do default the device is "Whirlpool" and the ValueName is "Count") => should be Whirlpool#Count
    • calculate with the pulse Whirlpool#Count*3600/2/30 (to have it in W again)
    • send it directly via MQTT: Publish %sysname%/Whirlpool/W,[Whirlpool#Count]*3600/2/30
    • and send the raw pulse via MQTT: Publish %sysname%/Whirlpool/W,[Whirlpool#Count]
So, it would look like:

Code: Select all

On System#Boot do    //When the ESP boots, do
 Publish %sysname%/Whirlpool/Watt,[Whirlpool#Count]*3600/2/30
 Publish %sysname%/Whirlpool/Pulse,[Whirlpool#Count]
  timerSet,1,30      //Set Timer 1 for the next event in 30 seconds
endon

On Rules#Timer=1 do  //When Timer1 expires, do
 Publish %sysname%/Whirlpool/Watt,[Whirlpool#Count]*3600/2/30
 Publish %sysname%/Whirlpool/Pulse,[Whirlpool#Count]
  timerSet,1,30       //Resets the Timer 1 for another 30 seconds
endon
Where is my error here? how can I calculate in rules? It sends the values as Strings! ;)

Code: Select all

402441: EVENT: Whirlpool#Count=48.00
402531: EVENT: Whirlpool#Total=23417.00
402634: EVENT: Whirlpool#Time=622.29
408801: EVENT: Clock#Time=Fri,09:50
420945: EVENT: Gas#All=0.00,0.09,0.00
421001: SYS : 7.00,17656.00,-1.00,18.45
421029: EVENT: Systeminfos#uptime=7.00
421130: EVENT: Systeminfos#freeheap=17656.00
421229: EVENT: Systeminfos#vcc=-1.00
421329: EVENT: Systeminfos#load=18.45
421768: EVENT: Rules#Timer=1,1
421790: ACT : Publish S0_Counter/Whirlpool/Watt,48.00*3600/2/30
421810: ACT : Publish S0_Counter/Whirlpool/Pulse,48.00
421820: ACT : timerSet,1,30
422389: WD : Uptime 7 ConnectFailures 0 FreeMem 17936 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP Easy MEGA: sending RAW pulses plus calculation to controller

#4 Post by TD-er » 15 Apr 2022, 12:44

First of all, the Wiki documentation is outdated. Please use the ReadTheDocs documentation: https://espeasy.readthedocs.io/en/latest/

There is a number of ways to accomplish this:
- Use dummy tasks to store the values
- Use variables within rules.

A dummy task can be filled from the rules using the taskvalueset command.
You can "run" a dummy task by calling taskrun from the rules, which will send all values from that task to any connected controller.

If you're not using a dummy task, you need to store the values in a variable and then do whatever you need to do with them. e.g. format them into an URL for a http call.

N.B. variables will be erased after a reboot, where task values will be restored after a reboot (without power loss).
However, since you will be updating these dummy task values every N seconds, this does not have any benefit in this use case.


Some example rules code for you.
I assume your pulsecount tasks are called "gas" and "energy" and you have to check for yourself what task value you want to use. I just call it "count" but you may need to change that in your setup.

Code: Select all

on energy#count do
  let,1,(%eventvalue1%*60) // 1: W -> %value%*3600/2/30
  let,2,[var#2]+(%eventvalue1%/2000) // 2: kWh -> %value%/2000
  logentry,"[var#1] Watt [var#2] kWh"
endon
As you can see, I assigned the values on every read of the pulsecount task named "energy" to variables 1 and 2 and log them.

This will be done each "Interval" nr of seconds of your task. (see at the bottom of the task configuration page)

But you can also set the rules to do this every minute or set a specific timer for it.
Then you don't have the value in the %eventvalueX%, but you have to fetch it via [energy#count] notation.

See the Rules documentation for more inspiration: https://espeasy.readthedocs.io/en/lates ... Rules.html

binderth
New user
Posts: 6
Joined: 15 Apr 2022, 10:08

Re: ESP Easy MEGA: sending RAW pulses plus calculation to controller

#5 Post by binderth » 15 Apr 2022, 16:21

Thanks! that helped a lot!

so, my solution right now for energy (it's for a Whirlpool) is

Code: Select all

On System#Boot do    //When the ESP boots, do
  let,1,[Whirlpool#Count]*3600/2/30
  let,2,[Whirlpool#Total]/2000
  Publish openHAB/%sysname%/Whirlpool/W,[VAR#1]
  Publish openHAB/%sysname%/Whirlpool/kWh,[VAR#2]
  Publish openHAB/%sysname%/Whirlpool/Count,[Whirlpool#Count]
  Publish openHAB/%sysname%/Whirlpool/Total,[Whirlpool#Total]
  timerSet,1,30      //Set Timer 1 for the next event in 30 seconds
endon

On Rules#Timer=1 do  //When Timer1 expires, do
  let,1,[Whirlpool#Count]*3600/2/30
  let,2,[Whirlpool#Total]/2000
  Publish openHAB/%sysname%/Whirlpool/W,[VAR#1]
  Publish openHAB/%sysname%/Whirlpool/kWh,[VAR#2]
  Publish openHAB/%sysname%/Whirlpool/Count,[Whirlpool#Count]
  Publish openHAB/%sysname%/Whirlpool/Total,[Whirlpool#Total]
  timerSet,1,30       //Resets the Timer 1 for another 30 seconds
endon
the Gas-device just changes the name to "Gas" and the impules are 200 per m3 - and I do calculate m3 _and_ kWh consumption! ;)

...and of course, if the Wemos looses power, it'll reset "Total" to 0, that's why i needed the Raw Counts on every timer, to add it up in my Smarthome for persistance. I really don't need kWh, if I'm honest, because its not persisted in the Wemos.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP Easy MEGA: sending RAW pulses plus calculation to controller

#6 Post by Ath » 15 Apr 2022, 17:08

To avoid duplication of your rules-code, you could limit that like this:

Code: Select all

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,[Whirlpool#Count]*3600/2/30
  let,2,[Whirlpool#Total]/2000
  Publish openHAB/%sysname%/Whirlpool/W,[VAR#1]
  Publish openHAB/%sysname%/Whirlpool/kWh,[VAR#2]
  Publish openHAB/%sysname%/Whirlpool/Count,[Whirlpool#Count]
  Publish openHAB/%sysname%/Whirlpool/Total,[Whirlpool#Total]
endon
You could even consider to not force the initial update, as at the time of System#Boot, not many counts will have been counted yet, if any ;)

Using LoopTimerSet has the additional advantage that it is fired quite exactly every 30 seconds, instead of adding the execution (and possible delays) of the Publish commands. That might be of significance when adding more publish commands there.
/Ton (PayPal.me)

binderth
New user
Posts: 6
Joined: 15 Apr 2022, 10:08

Re: ESP Easy MEGA: sending RAW pulses plus calculation to controller

#7 Post by binderth » 16 Apr 2022, 11:18

Ath wrote: 15 Apr 2022, 17:08 Using LoopTimerSet has the additional advantage that it is fired quite exactly every 30 seconds, instead of adding the execution (and possible delays) of the Publish commands. That might be of significance when adding more publish commands there.
Thanks! works like a charm! :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 39 guests