Page 1 of 1

KWH Counter

Posted: 16 Jun 2020, 18:29
by prutzer
Hi All,

I have searched the whole internet, but i can not find a working solution to build a KWH meter with a D1 mini and a KWH meter.
What I have done:

I have a KWH meter. 1000imp per kwh and connected it to D5:
Image

ESP Easy is configured as follow:
Image

Result with a 500W balast:
W: is sometimes 1, and KWH is counting the pulses.
When I remove the calculation, the results are the same.
Image

What am I doing wrong?

Re: KWH Counter

Posted: 16 Jun 2020, 19:08
by grovkillen
Your time/interval is 10 seconds that mean that your momentary formula is correct. I have done the same on my energy meter here at home and it work just fine. The only thing I do different is that I have 2 decimals instead of zero... and D3 instead of D5.

Re: KWH Counter

Posted: 16 Jun 2020, 19:29
by TD-er
What do you mean by the "total count is not persistent" you wrote in the image?

Re: KWH Counter

Posted: 17 Jun 2020, 08:50
by prutzer
If I use the normal version of ESP easy mega this text is automaticly added. "total count is not persistent"
In the dev version there is no such text.

I think it is strange that kwh is just counting the pulses. The formula does nothing.

I would like to see bij W the power usage at the moment and by KWH the power usage total.
I will add 2 decimals and try again.

Re: KWH Counter

Posted: 17 Jun 2020, 09:06
by TD-er
Ah there has been a report about the formula not working for the pulse counter (and another plugin)

Re: KWH Counter

Posted: 17 Jun 2020, 10:16
by prutzer
Aaah so it is a known bug / problem?
2 decimals are also not working and not showing.

Which version of ESP easy do I have to use for a working solution?

Re: KWH Counter

Posted: 17 Jun 2020, 12:26
by TD-er
prutzer wrote: 17 Jun 2020, 10:16 [...]
Which version of ESP easy do I have to use for a working solution?
I think a future one, as it has not yet been fixed.
You can also do calculations in the rules.

Re: KWH Counter

Posted: 12 Jun 2021, 17:20
by prutzer
I tried this solution again and it looks like the bug is still there.

I tried Release mega-20210223 (Normal) and ESP_Easy_mega_20210114_energy_ESP8266_4M1M.

What rules do I have to make to calculate the energy usage in watts?

Something like this?

on Airco#Count do
SendToHTTP Domoitczip,port,/json.htm?type=command&param=udevice&idx=156&nvalue=0&svalue=[Airco#Count]*3600/10 //Sent to Domoticz
endon

Re: KWH Counter

Posted: 12 Jun 2021, 19:09
by Ath
That'll fire an update to Domoticz on every pulse of the counter, not sure if Domoticz likes that...

You'd better send that only once a minute or similar frequency:
And just for fun, I'd do the calculation before building the url for Domoticz

Code: Select all

on system#clock=All,**:** do
  let,1,[Airco#Count]*360 // *3600/10 == *360, why do an unneeded division?
  SendToHTTP Domoitczip,port,/json.htm?type=command&param=udevice&idx=156&nvalue=0&svalue=[var#1] //Sent to Domoticz
endon

Re: KWH Counter

Posted: 12 Jun 2021, 19:43
by prutzer
Hi ATH,

Thanks a lot for the script!

Wil it run the script every 10 seconds If I change it to:
on system#clock=All,**:**:* do
If I test it, domoticz does not get any updates.
If I do it manually: http://domoticzip:port/json.htm?type=command&param=udevice&idx=156&svalue=1000 it works.

ESP Easy log:
730433: EVENT: Airco#Count=6
730533: EVENT: Airco#Total=49
730633: EVENT: Airco#Time=31

Re: KWH Counter

Posted: 12 Jun 2021, 19:48
by prutzer
I found a working soliotion: Thanks to Ath!

Code: Select all

on Airco#Count do
  let,1,[Airco#Count]*360 // *3600/10 == *360, why do an unneeded division?
  SendToHTTP ipdomoticz,port,/json.htm?type=command&param=udevice&idx=156&nvalue=0&svalue=[var#1] //Sent to Domoticz
endon
Set the device at 10 seconds:
Image

Hardware: D5 to S0+ and ground to S0-
1000 pulses/kwh

Domoticz: Create a virtual device Electric Instant + counter. Edit this device and set it to computed.

Re: KWH Counter

Posted: 12 Jun 2021, 20:21
by Ath
Yes, the system#clock interval is max. 1 per minute, if you need a shorter interval you can set a loop-timer:

Code: Select all

on system#boot do
  loopTimerSet,1,10
endon

on rules#timer=1 do
  let,1,[Airco#Count]*360 // *3600/10 == *360, why do an unneeded division?
  SendToHTTP ipdomoticz,port,/json.htm?type=command&param=udevice&idx=156&nvalue=0&svalue=[var#1] //Sent to Domoticz
endon
But your solution also works fine, so just keep that ;)

An actual improvement would be to use the %eventvalue1% argument that is passed to the event:

Code: Select all

on Airco#Count do
  let,1,%eventvalue1%*360 // *3600/10 == *360, why do an unneeded division?
  SendToHTTP ipdomoticz,port,/json.htm?type=command&param=udevice&idx=156&nvalue=0&svalue=[var#1] //Sent to Domoticz
endon
The advantage is that %eventvalue1% holds the value of that variable at the moment the event was generated, and, as rules can be delayed during execution, the count value could have changed in the meantime.

Re: KWH Counter

Posted: 15 Jun 2021, 19:29
by prutzer
Thanks for the improvement!

I will at it to the script!

Thanks a lot!