node-red-contrib-energymeterplus 0.0.6 → 0.0.8

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.
@@ -1,20 +1,20 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType('energyMeterPlus', {
3
3
  category: 'energy',
4
- color: '#228B22',
4
+ color: '#d9910cfe', <!-- Dutch Orange -->
5
5
  defaults: {
6
6
  name: {value:""},
7
7
  baselineDaily: {value:0},
8
8
  baselineWeekly: {value:0},
9
9
  baselineMonthly: {value:0},
10
10
  baselineYearly: {value:0},
11
- costPerUnit: {value:0.15},
12
- filepath: {value:"/config/energymeterplus.json"},
11
+ unitCost: {value:0.15},
12
+ filePath: {value:"/addon_configs/a0d7b954_nodered/node_red/solarGen_data.json"},
13
13
  inputUnit: {value:"kW"}
14
14
  },
15
15
  inputs:1,
16
16
  outputs:1,
17
- icon: "smartmeter.png",
17
+ icon: "sun.png",
18
18
  label: function() {
19
19
  return this.name || "energyMeterPlus";
20
20
  }
@@ -22,6 +22,10 @@
22
22
  </script>
23
23
 
24
24
  <script type="text/x-red" data-template-name="energyMeterPlus">
25
+ <div class="form-row">
26
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
27
+ <input type="text" id="node-input-name">
28
+ </div>
25
29
  <div class="form-row">
26
30
  <label for="node-input-baselineDaily">Baseline Daily (kWh)</label>
27
31
  <input type="number" id="node-input-baselineDaily">
@@ -39,12 +43,12 @@
39
43
  <input type="number" id="node-input-baselineYearly">
40
44
  </div>
41
45
  <div class="form-row">
42
- <label for="node-input-costPerUnit">Cost per Unit</label>
43
- <input type="number" id="node-input-costPerUnit" step="0.01">
46
+ <label for="node-input-unitCost">Cost per Unit</label>
47
+ <input type="number" id="node-input-unitCost" step="0.01">
44
48
  </div>
45
49
  <div class="form-row">
46
- <label for="node-input-filepath">Filepath</label>
47
- <input type="text" id="node-input-filepath">
50
+ <label for="node-input-filePath">Filepath</label>
51
+ <input type="text" id="node-input-filePath">
48
52
  </div>
49
53
  <div class="form-row">
50
54
  <label for="node-input-inputUnit">Input Unit</label>
@@ -8,7 +8,7 @@ module.exports = function(RED) {
8
8
  // Config values
9
9
  let unitCost = Number(config.unitCost) || 0;
10
10
  let filePath = config.filePath || "/addon_configs/a0d7b954_nodered/node_red/solarGen_data.json";
11
- let inputUnit = config.inputUnit || "kW";
11
+ let inputUnit = config.inputUnit || "W";
12
12
 
13
13
  // Numeric baseline corrections
14
14
  let baselineDaily = Number(config.baselineDaily) || 0;
@@ -16,45 +16,24 @@ module.exports = function(RED) {
16
16
  let baselineMonthly = Number(config.baselineMonthly) || 0;
17
17
  let baselineYearly = Number(config.baselineYearly) || 0;
18
18
 
19
- // Baseline counters
19
+ // Baseline counters start at corrections
20
20
  let baseline = { daily: baselineDaily, weekly: baselineWeekly, monthly: baselineMonthly, yearly: baselineYearly };
21
21
  let lastCheck = new Date();
22
22
 
23
- // Function to handle rollover
23
+ // Rollover logic
24
24
  function checkRollover() {
25
25
  let now = new Date();
26
-
27
- // Daily rollover
28
- if (now.getDate() !== lastCheck.getDate()) {
29
- baseline.daily = baselineDaily;
30
- }
31
-
32
- // Weekly rollover (Sunday = 0)
33
- if (now.getDay() === 0 && lastCheck.getDay() !== 0) {
34
- baseline.weekly = baselineWeekly;
35
- }
36
-
37
- // Monthly rollover
38
- if (now.getMonth() !== lastCheck.getMonth()) {
39
- baseline.monthly = baselineMonthly;
40
- }
41
-
42
- // Yearly rollover
26
+ if (now.getDate() !== lastCheck.getDate()) baseline.daily = baselineDaily;
27
+ if (now.getDay() === 0 && lastCheck.getDay() !== 0) baseline.weekly = baselineWeekly;
28
+ if (now.getMonth() !== lastCheck.getMonth()) baseline.monthly = baselineMonthly;
43
29
  if (now.getFullYear() !== lastCheck.getFullYear()) {
44
- // Archive previous year
45
30
  let archiveName = filePath.replace(".json", `_${lastCheck.getFullYear()}.json`);
46
- try {
47
- fs.writeFileSync(archiveName, JSON.stringify(baseline, null, 2));
48
- } catch (err) {
49
- node.error("Failed to archive yearly file: " + err);
50
- }
31
+ try { fs.writeFileSync(archiveName, JSON.stringify(baseline, null, 2)); }
32
+ catch (err) { node.error("Failed to archive yearly file: " + err); }
51
33
  baseline.yearly = baselineYearly;
52
34
  }
53
-
54
35
  lastCheck = now;
55
36
  }
56
-
57
- // Run rollover check every minute
58
37
  setInterval(checkRollover, 60000);
59
38
 
60
39
  node.on('input', function(msg) {
@@ -86,17 +65,14 @@ module.exports = function(RED) {
86
65
  };
87
66
 
88
67
  // Save snapshot
89
- try {
90
- fs.writeFileSync(filePath, JSON.stringify(msg.payload, null, 2));
91
- } catch (err) {
92
- node.error("Failed to write to file: " + err);
93
- }
68
+ try { fs.writeFileSync(filePath, JSON.stringify(msg.payload, null, 2)); }
69
+ catch (err) { node.error("Failed to write to file: " + err); }
94
70
 
95
71
  node.send(msg);
96
72
  });
97
73
  }
98
74
 
99
75
  RED.nodes.registerType("energyMeterPlus", EnergyMeterPlus, {
100
- color: "#228B22" // Forest Green node color
76
+ color: "#d9910cfe" // Dutch Orange
101
77
  });
102
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-energymeterplus",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
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",