-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Hello,
I've been using this awesome lib for years!
I'm using the active power (because it is what is billed) and the difference between apparent power and active power can be high at low load (which is, most of the time!)
So far I am doing the calculation outside the lib in arduino (custom code) or in Node-Red.
I don't know if it's better to calculate the active power in this library or outside, like in Tasmota (refering for example to arendst/Tasmota#19756)
The code follows the increment of EAST and calculate the active power. It is averaging over the last 1 minute but it can be lower, especially at high load. It can (with interval=0), calculates the active power, everytime EAST increases.
This is for example a Node-Red function that takes for input EAST (in Standard mode), and outputs active power minutely.
let now = Date.now();
let interval = (1000 * 60);
let wh = msg.payload;
let lastSend = context.get("last_send");
let lastWh = context.get("last_wh");
let lastEAST = context.get("last_EAST");
context.set("last_EAST", wh);
if (lastSend === undefined || lastWh === undefined || lastEAST === undefined) {
context.set("last_send", now);
context.set("last_wh", wh);
context.set("last_EAST", wh);
}
else if (now - lastSend >= interval && wh > lastWh && wh > lastEAST) {
context.set("last_send", now);
context.set("last_wh", wh);
let Pactive = 3600000 * (wh - lastWh) / (now - lastSend)
return { topic: "teleinfo/Pactive", payload: Math.round(Pactive) };
}