node-red-contrib-energymeterplus 0.0.4 → 0.0.6

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,24 +1,56 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('energyMeterPlus',{
3
- category: 'energy', // palette section name
4
- color: '#5cb85c', // green background
2
+ RED.nodes.registerType('energyMeterPlus', {
3
+ category: 'energy',
4
+ color: '#228B22',
5
5
  defaults: {
6
6
  name: {value:""},
7
- unitCost: {value:""},
8
- filePath: {value:""},
9
- baselineCorrection: {value:""}
7
+ baselineDaily: {value:0},
8
+ baselineWeekly: {value:0},
9
+ baselineMonthly: {value:0},
10
+ baselineYearly: {value:0},
11
+ costPerUnit: {value:0.15},
12
+ filepath: {value:"/config/energymeterplus.json"},
13
+ inputUnit: {value:"kW"}
10
14
  },
11
15
  inputs:1,
12
16
  outputs:1,
13
- icon:"smartmeter.png",
17
+ icon: "smartmeter.png",
14
18
  label: function() {
15
- return this.name||"energyMeterPlus";
16
- },
17
- oneditprepare: function() {
18
- // Add labels to the fields
19
- $("#node-input-unitCost").attr("placeholder","Enter cost per kWh");
20
- $("#node-input-filePath").attr("placeholder","Path to JSON file (e.g. C:/Users/Francis/Documents/energy.json)");
21
- $("#node-input-baselineCorrection").attr("placeholder","Baseline correction in JSON (e.g. {\"daily\":10,\"weekly\":50})");
19
+ return this.name || "energyMeterPlus";
22
20
  }
23
21
  });
24
22
  </script>
23
+
24
+ <script type="text/x-red" data-template-name="energyMeterPlus">
25
+ <div class="form-row">
26
+ <label for="node-input-baselineDaily">Baseline Daily (kWh)</label>
27
+ <input type="number" id="node-input-baselineDaily">
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-baselineWeekly">Baseline Weekly (kWh)</label>
31
+ <input type="number" id="node-input-baselineWeekly">
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-baselineMonthly">Baseline Monthly (kWh)</label>
35
+ <input type="number" id="node-input-baselineMonthly">
36
+ </div>
37
+ <div class="form-row">
38
+ <label for="node-input-baselineYearly">Baseline Yearly (kWh)</label>
39
+ <input type="number" id="node-input-baselineYearly">
40
+ </div>
41
+ <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">
44
+ </div>
45
+ <div class="form-row">
46
+ <label for="node-input-filepath">Filepath</label>
47
+ <input type="text" id="node-input-filepath">
48
+ </div>
49
+ <div class="form-row">
50
+ <label for="node-input-inputUnit">Input Unit</label>
51
+ <select id="node-input-inputUnit">
52
+ <option value="kW">kW</option>
53
+ <option value="W">W</option>
54
+ </select>
55
+ </div>
56
+ </script>
@@ -5,41 +5,38 @@ module.exports = function(RED) {
5
5
  RED.nodes.createNode(this, config);
6
6
  var node = this;
7
7
 
8
+ // Config values
8
9
  let unitCost = Number(config.unitCost) || 0;
9
10
  let filePath = config.filePath || "/addon_configs/a0d7b954_nodered/node_red/solarGen_data.json";
10
- let baselineCorrection = config.baselineCorrection || "";
11
+ let inputUnit = config.inputUnit || "kW";
12
+
13
+ // Numeric baseline corrections
14
+ let baselineDaily = Number(config.baselineDaily) || 0;
15
+ let baselineWeekly = Number(config.baselineWeekly) || 0;
16
+ let baselineMonthly = Number(config.baselineMonthly) || 0;
17
+ let baselineYearly = Number(config.baselineYearly) || 0;
11
18
 
12
19
  // Baseline counters
13
- let baseline = { daily: 0, weekly: 0, monthly: 0, yearly: 0 };
20
+ let baseline = { daily: baselineDaily, weekly: baselineWeekly, monthly: baselineMonthly, yearly: baselineYearly };
14
21
  let lastCheck = new Date();
15
22
 
16
- // Apply correction if provided
17
- if (baselineCorrection) {
18
- try {
19
- let correction = JSON.parse(baselineCorrection);
20
- baseline = { ...baseline, ...correction };
21
- } catch (err) {
22
- node.error("Invalid baseline correction JSON");
23
- }
24
- }
25
-
26
23
  // Function to handle rollover
27
24
  function checkRollover() {
28
25
  let now = new Date();
29
26
 
30
27
  // Daily rollover
31
28
  if (now.getDate() !== lastCheck.getDate()) {
32
- baseline.daily = 0;
29
+ baseline.daily = baselineDaily;
33
30
  }
34
31
 
35
32
  // Weekly rollover (Sunday = 0)
36
33
  if (now.getDay() === 0 && lastCheck.getDay() !== 0) {
37
- baseline.weekly = 0;
34
+ baseline.weekly = baselineWeekly;
38
35
  }
39
36
 
40
37
  // Monthly rollover
41
38
  if (now.getMonth() !== lastCheck.getMonth()) {
42
- baseline.monthly = 0;
39
+ baseline.monthly = baselineMonthly;
43
40
  }
44
41
 
45
42
  // Yearly rollover
@@ -51,7 +48,7 @@ module.exports = function(RED) {
51
48
  } catch (err) {
52
49
  node.error("Failed to archive yearly file: " + err);
53
50
  }
54
- baseline.yearly = 0;
51
+ baseline.yearly = baselineYearly;
55
52
  }
56
53
 
57
54
  lastCheck = now;
@@ -61,19 +58,20 @@ module.exports = function(RED) {
61
58
  setInterval(checkRollover, 60000);
62
59
 
63
60
  node.on('input', function(msg) {
64
- let power = Number(msg.payload) || 0;
61
+ let factor = (inputUnit === "W") ? 0.001 : 1;
62
+ let power = Number(msg.payload) * factor || 0;
65
63
 
66
64
  // Add to counters
67
- baseline.daily += power;
68
- baseline.weekly += power;
65
+ baseline.daily += power;
66
+ baseline.weekly += power;
69
67
  baseline.monthly += power;
70
- baseline.yearly += power;
68
+ baseline.yearly += power;
71
69
 
72
70
  // Calculate costs
73
- let daily_cost = baseline.daily * unitCost;
74
- let weekly_cost = baseline.weekly * unitCost;
71
+ let daily_cost = baseline.daily * unitCost;
72
+ let weekly_cost = baseline.weekly * unitCost;
75
73
  let monthly_cost = baseline.monthly * unitCost;
76
- let yearly_cost = baseline.yearly * unitCost;
74
+ let yearly_cost = baseline.yearly * unitCost;
77
75
 
78
76
  // Build Output
79
77
  msg.payload = {
@@ -97,5 +95,8 @@ module.exports = function(RED) {
97
95
  node.send(msg);
98
96
  });
99
97
  }
100
- RED.nodes.registerType("energyMeterPlus", EnergyMeterPlus);
98
+
99
+ RED.nodes.registerType("energyMeterPlus", EnergyMeterPlus, {
100
+ color: "#228B22" // Forest Green node color
101
+ });
101
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-energymeterplus",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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",