node-red-contrib-energymeterplus 0.0.6 → 0.0.7

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: '#d9910cdb', <!-- 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>
@@ -5,7 +5,6 @@ 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
10
  let inputUnit = config.inputUnit || "kW";
@@ -24,24 +23,10 @@ module.exports = function(RED) {
24
23
  function checkRollover() {
25
24
  let now = new Date();
26
25
 
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
31
  try {
47
32
  fs.writeFileSync(archiveName, JSON.stringify(baseline, null, 2));
@@ -54,18 +39,24 @@ module.exports = function(RED) {
54
39
  lastCheck = now;
55
40
  }
56
41
 
57
- // Run rollover check every minute
58
42
  setInterval(checkRollover, 60000);
59
43
 
60
44
  node.on('input', function(msg) {
61
45
  let factor = (inputUnit === "W") ? 0.001 : 1;
62
- let power = Number(msg.payload) * factor || 0;
63
46
 
64
- // Add to counters
65
- baseline.daily += power;
66
- baseline.weekly += power;
67
- baseline.monthly += power;
68
- baseline.yearly += power;
47
+ // Accept either raw number or JSON object
48
+ if (typeof msg.payload === "number") {
49
+ let power = msg.payload * factor;
50
+ baseline.daily += power;
51
+ baseline.weekly += power;
52
+ baseline.monthly += power;
53
+ baseline.yearly += power;
54
+ } else if (typeof msg.payload === "object") {
55
+ baseline.daily = (msg.payload.daily_kWh || baseline.daily) * factor;
56
+ baseline.weekly = (msg.payload.weekly_kWh || baseline.weekly) * factor;
57
+ baseline.monthly = (msg.payload.monthly_kWh || baseline.monthly) * factor;
58
+ baseline.yearly = (msg.payload.yearly_kWh || baseline.yearly) * factor;
59
+ }
69
60
 
70
61
  // Calculate costs
71
62
  let daily_cost = baseline.daily * unitCost;
@@ -97,6 +88,6 @@ module.exports = function(RED) {
97
88
  }
98
89
 
99
90
  RED.nodes.registerType("energyMeterPlus", EnergyMeterPlus, {
100
- color: "#228B22" // Forest Green node color
91
+ color: "#d9910cdb" // Orange node color
101
92
  });
102
93
  }
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.7",
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",