Hi, I try to calculate the watt from my energy meter. I use NodeREDs smartmeter input plugin to get the values from my counter. The values are read every second. My function looks like this, but I know I miss something:
var counter_out=msg.payload["1-0:2.8.0*255"].values[0].value // in KWh
var counter_in=msg.payload["1-0:1.8.0*255"].values[0].value // in KWh
var now=new Date().getTime()
if (flow.get("last_changed"))
{
var last_changed=flow.get("last_changed")
var TimeDiffMs = now - last_changed
var TimeDiff = TimeDiffMs / 1000
var TimeDiffM = TimeDiff / 60
var TimeDiffH = TimeDiff / 60 / 60
flow.set("TimeDiff", TimeDiff)
flow.set("TimeDiffM", TimeDiffM)
flow.set("TimeDiffH", TimeDiffH)
// Wh = W x Time
// W = Wh / Time
// counter_in / 1000 to get from KWh to Wh
var power_in = (counter_in / 1000) / TimeDiffH
flow.set("power_in", power_in)
flow.set("power_in_real", msg.payload["1-0:16.7.0*255"].values[0].value)
var power_out = (counter_out / 1000) / TimeDiffH
flow.set("power_out", power_out)
}
flow.set("counter_out", counter_out)
flow.set("counter_in", counter_in)
flow.set("last_changed", now)
return null
I primary want to calculate the power_out
, to calculate a limit for my inverter.
I get the following results:
var | val |
---|---|
TimeDiff | 1.015 |
TimeDiffH | 0.0002819444444444444 |
TimeDiffM | 0.016916666666666667 |
counter_in | 26021.4767 |
counter_out | 7.3337 |
current_power | 682 |
last_changed | 1697384125268 |
power_in | 92292.9222857143 |
power_in_real | 682 |
power_out | 26.01115270935961 |
Any math gurus who can help so solve my problem???