node-red-contrib-power-monitor
node-red-contrib-power-monitor copied to clipboard
Wrong calculactions?
I think I have found a bug at line 98 (if (node.latest > 0) energy = (time - node.latest) * power;) where it calculates the energy delta. It takes the current power * time. But shouldn’t it take the last power * time?
For example, if module gets 1000 w at time 0:00. Then the power changes to 2000 W at 1:00. If I understand your code correctly it will take the time * 2000 so the result will be 2 kWh, but it should take time * 1000 so the result should be 1 kWh.
So I think you need to save power to lastpower at end of loop and use that at line 98 when the new power value is posted.