Calculate Energy Used by Plug using Webcore


#1

1) Give a description of the problem
I want to create a piston that calculates the energy used in a Dryer cycle taking info from my zigbee plug that does not support Energy Readings…

2) What is the expected behaviour?
Calculate the energy using the following formula:

(AvgPowerUsed*TimeUsed)/1000

After the dryer start its cycle I take max 10probes of Power that I’m later using for calculate the Energy Used.

3) What is happening/not happening?
I am having issues with converting the TimeUsed variable into a integer number to use it in the formula. I get only 01:30 hours format and I need 1.5 format in order to use it accordingly in the formula.

4) Post a Green Snapshot of the pistonimage


#2

You can try converting 01:30 into minutes, and then divide by 60 to get 1.5


#3

I would first make usedTime a decimal variable. Then calculate the hours as

(FinishTime-StartTime)/3,600,000

FinishTime-StartTime calculates the time difference in milliseconds. Dividing that number by 3,600,000 (60 min/hour * 60 sec/min * 1000 msec/sec) gets you to hours.


#4

Hi!

I used your formula, but I get nonsense result. I’ve put the difference between Start and Finish exactly 1 hour and this is what i get on “usedTime” variable:


#5

Unless you have changed something, lines 69 - 1000 will never execute.
(there is no trigger there, so {startTime} is never updated)


#6

The fact that the epoch time (446641.5401636111) produced by the expression is Mon, 14 Dec 2020 13:34:42 GMT strongly suggests that StartTime either had no value (0) or was not correctly set at the time the expression was evaluated in your image.

On a separate but quite possibly related point, it is not immediately clear to me how StartTime is ever going to be set in this piston, as there is no trigger for the lower half of your piston and that code exists outside of the timer.


#7

You say tomatoe, I say to-ma-to… :grin:


#8

My fingers are a bit slow this morning. :smile:


#9

Hi !

I’ve remade almost the whole piston. The startTime and finishTIme problem i’ve solved by changing the type of variable to “integer” in the first place, then assign them with $now when it’s the case.The difference it’s now working as it should.
Another change that I’ve made it’s using an averagePower, I’m not quite convinced that it’s right.I am not best at math, maybe share some thoughts on how can I improve this calculation.
Take a look at my new piston. In fact, any idea it’s good, so feel free :smiley:


#10

It would be helpful in the future if you would post the Green Snapshot with Trace enabled so that we can easily see (instead of guess) how WebCoRE is interpreting the various triggers and conditions. While my overall impression is that this piston is much better, the only question that really matters is whether or not it works for you.

Changing the variable type to integer is a workable approach, although the formula I provided would have worked just as well and I personally prefer to keep time and date numbers in the appropriate variable format, but in this case it’s not likely to matter.


#11

I totally agree about turning on Trace.


#12

I’ll keep that in mind for the future.
I gave it a try yesterday’s evening and seems to be working just fine, maybe needs a little fine tuning here and there…

Do you have any other idea on how should I compute the avarage Power on a working cycle, maybe something more engineering like? (Lines 70-75)

Here’s the Green version of my Piston:
For the ones that did not have time to read the whole thread here are its functions:

  • Measure the power input of a Power Plug on which I’ve connected a clothes dryer (but could work very fine for any other appliance)
  • automatically calculates the cycle, weekly and monthly energy (the DHT of the plug cannot read it)
  • based on the used energy, it calculates the cost of a cycle usage, alongside with weekly and monthly usage.
  • it sends a notification after each cycle, week, month with the usage and costs
  • opens a virtual contact that triggers an Alexa Routine -> for voice announcements (RIP EchoSpeaks :frowning:)

Greenshot: