// Wait for both messages to arrive
// Calculate delta between consumption and PV
context.power = context.power || {};
switch (msg.topic) {
case 'power_cons_sum':
context.power.cons = parseInt(msg.payload);
//node.warn("context.power.cons " + context.power.cons);
msg = null;
break;
case 'pv_bwp_sum':
context.power.pv = parseInt(msg.payload);
//node.warn("context.power.pv " + context.power.pv);
msg = null;
break;
default:
msg = null;
break;
}
if (context.power.cons != null && context.power.pv != null) {
var surplus = (context.power.pv - context.power.cons);
context.power = null;
return {topic:'surplus', payload:surplus};
}
else return msg;
Last active
February 14, 2017 06:19
-
-
Save Sineos/a50e8de05f00f38dea75d13bcc0bb755 to your computer and use it in GitHub Desktop.
Sync node-red sensor values
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment