I know how to calculate the kWh delta (the energy spent during the period) using Meta Data point. What I am not sure about is how to calculate the total kWh usage, I mean accumulating reading through time periods. What I am not sure about is how to get the last current kWh state and add the kWdelta to it and save it as a new value.
Let's assume I have values in the W.
// getting the current and the previous readings (W + time)
var lastW = p.lastValue(1);
var nowW = p.lastValue(0);
// getting epoche period in milliseconds
var period = nowW.time - lastW.time;
//getting period in seconds
periodS = period/1000
// getting the W readings
var Wnow = nowW.value;
var Wlast = lastW.value;
// calculating the W delta
Wdelta = Wnow - Wlast;
// getting periods W seconds
Wsdelta = Wdelta*periodS
// getting Whdelta
Whdelta = (1/3600)*Wsdelta
//getting kWhdelta
kWhdelta=(1/1000)*Whdelta
// so how I can get the last point kWh value
//assuming that the metadata point variable name is "my", should I return something like my.value + kWhdelta for the new value?
return my.value+kWhdelta;