node-red-contrib-energymeterplus 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/energyMeterPlus.js +16 -10
  2. package/package.json +1 -1
@@ -5,10 +5,9 @@ module.exports = function(RED) {
5
5
  RED.nodes.createNode(this, config);
6
6
  var node = this;
7
7
 
8
- // Config values
9
8
  let unitCost = Number(config.unitCost) || 0;
10
9
  let filePath = config.filePath || "/addon_configs/a0d7b954_nodered/node_red/solarGen_data.json";
11
- let inputUnit = config.inputUnit || "W";
10
+ let inputUnit = config.inputUnit || "W"; // default to Watts since your stream is in W
12
11
 
13
12
  // Numeric baseline corrections
14
13
  let baselineDaily = Number(config.baselineDaily) || 0;
@@ -16,7 +15,7 @@ module.exports = function(RED) {
16
15
  let baselineMonthly = Number(config.baselineMonthly) || 0;
17
16
  let baselineYearly = Number(config.baselineYearly) || 0;
18
17
 
19
- // Baseline counters start at corrections
18
+ // Baseline counters
20
19
  let baseline = { daily: baselineDaily, weekly: baselineWeekly, monthly: baselineMonthly, yearly: baselineYearly };
21
20
  let lastCheck = new Date();
22
21
 
@@ -37,14 +36,21 @@ module.exports = function(RED) {
37
36
  setInterval(checkRollover, 60000);
38
37
 
39
38
  node.on('input', function(msg) {
40
- let factor = (inputUnit === "W") ? 0.001 : 1;
41
- let power = Number(msg.payload) * factor || 0;
39
+ let now = new Date();
40
+ let durationHours = (now - lastCheck) / (1000 * 3600); // elapsed time in hours
41
+ lastCheck = now;
42
+
43
+ let power = Number(msg.payload) || 0;
44
+ let power_kW = (inputUnit === "W") ? power / 1000 : power;
45
+
46
+ // Energy increment = Power × Time
47
+ let energyIncrement = power_kW * durationHours;
42
48
 
43
49
  // Add to counters
44
- baseline.daily += power;
45
- baseline.weekly += power;
46
- baseline.monthly += power;
47
- baseline.yearly += power;
50
+ baseline.daily += energyIncrement;
51
+ baseline.weekly += energyIncrement;
52
+ baseline.monthly += energyIncrement;
53
+ baseline.yearly += energyIncrement;
48
54
 
49
55
  // Calculate costs
50
56
  let daily_cost = baseline.daily * unitCost;
@@ -73,6 +79,6 @@ module.exports = function(RED) {
73
79
  }
74
80
 
75
81
  RED.nodes.registerType("energyMeterPlus", EnergyMeterPlus, {
76
- color: "#d9910cfe" // Dutch Orange
82
+ color: "#228B22" // Forest Green
77
83
  });
78
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-energymeterplus",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "A node-red energy meter node with editable baseline data, milestone summary, and cost calculation",
5
5
  "author": "Arcfrankye",
6
6
  "license": "MIT",