KWH Counter

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

KWH Counter

#1 Post by prutzer » 16 Jun 2020, 18:29

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?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: KWH Counter

#2 Post by grovkillen » 16 Jun 2020, 19:08

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: KWH Counter

#3 Post by TD-er » 16 Jun 2020, 19:29

What do you mean by the "total count is not persistent" you wrote in the image?

prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

Re: KWH Counter

#4 Post by prutzer » 17 Jun 2020, 08:50

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.

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

Re: KWH Counter

#5 Post by TD-er » 17 Jun 2020, 09:06

Ah there has been a report about the formula not working for the pulse counter (and another plugin)

prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

Re: KWH Counter

#6 Post by prutzer » 17 Jun 2020, 10:16

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?

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

Re: KWH Counter

#7 Post by TD-er » 17 Jun 2020, 12:26

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.

prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

Re: KWH Counter

#8 Post by prutzer » 12 Jun 2021, 17:20

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

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

Re: KWH Counter

#9 Post by Ath » 12 Jun 2021, 19:09

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
/Ton

prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

Re: KWH Counter

#10 Post by prutzer » 12 Jun 2021, 19:43

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

prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

Re: KWH Counter

#11 Post by prutzer » 12 Jun 2021, 19:48

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.

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

Re: KWH Counter

#12 Post by Ath » 12 Jun 2021, 20:21

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.
/Ton

prutzer
Normal user
Posts: 9
Joined: 16 Jun 2020, 16:45

Re: KWH Counter

#13 Post by prutzer » 15 Jun 2021, 19:29

Thanks for the improvement!

I will at it to the script!

Thanks a lot!

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests