node-red-contrib-power-saver 5.0.0-beta.0 → 5.0.0-beta.2

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,7 +1,7 @@
1
1
  # These are supported funding model platforms
2
2
 
3
3
  github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
- patreon: ottopaulsen
4
+ patreon: # ottopaulsen
5
5
  open_collective: # Replace with a single Open Collective username
6
6
  ko_fi: # Replace with a single Ko-fi username
7
7
  tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
package/= ADDED
File without changes
package/README.md CHANGED
@@ -5,3 +5,6 @@ A Node-RED node to save money when power prices are changing by the hour.
5
5
  ![Logo](docs/.vuepress/public/logo.png)
6
6
 
7
7
  ## Please read more in the [documentation](https://powersaver.no/).
8
+
9
+
10
+ [![Donation](./donation.png)](https://powersaver.no/contribute/#donate)
@@ -83,6 +83,7 @@ export default defineUserConfig({
83
83
  "/examples/example-visualize-on-off/example-visualize-on-off.md",
84
84
  "/examples/example-grid-tariff-capacity-part.md",
85
85
  "/examples/example-stromstotte.md",
86
+ "/examples/example-reduce-minutes-array.md",
86
87
  ],
87
88
  },
88
89
  ],
@@ -7,7 +7,18 @@ sidebarDepth: 1
7
7
 
8
8
  List the most significant changes.
9
9
 
10
- ## 5.0.0
10
+ ## 5.0.0.beta.2
11
+
12
+ - Fix bug in Min minutes off
13
+
14
+ ## 5.0.0 beta.1
15
+
16
+ - Fix bug `dataDayBefore.minutes is not iterable`
17
+ - Update example for Lovelace Visualization. That example also has a function node that reduces the number of entries in the minutes array, that can be useful other places too.
18
+
19
+ Please note that if you have nodes using the hours array on output 3, you need to change those to use the minutes array.
20
+
21
+ ## 5.0.0 beta.0
11
22
 
12
23
  ::: danger BREAKING CHANGE
13
24
  This is a breaking change.
@@ -17,6 +17,8 @@
17
17
 
18
18
  [Strømstøtte (governmentall support)](./example-stromstotte)
19
19
 
20
+ [Reduce minutes-array](./example-reduce-minutes-array)
21
+
20
22
  ## User provided examples
21
23
 
22
24
  [Output schedule to a sensor entity](./example-next-schedule-entity.md) (by Stefan)
@@ -0,0 +1,23 @@
1
+ # Reduce minutes array
2
+
3
+ If you want to reduce number of entries in the minutes array on output 3, you can send it through a function node with the following code:
4
+ ```
5
+ const minutes = []
6
+ let previousHour = ""
7
+ let previousSaving = null
8
+ let previousPrice = null
9
+ msg.payload.minutes.forEach(m => {
10
+ const hour = m.start.substring(0, 13)
11
+ if (hour !== previousHour || m.saving !== previousSaving || m.price !== previousPrice) {
12
+ minutes.push(m)
13
+ previousHour = hour
14
+ previousSaving = m.saving
15
+ previousPrice = m.price
16
+ }
17
+ })
18
+
19
+ msg.payload.minutes = minutes
20
+
21
+ return msg;
22
+ ```
23
+ It will remove all entries that are equal to the one before, but still send at least one per hour.
@@ -2,7 +2,7 @@
2
2
 
3
3
  The source of this example is made by Kim Storøy, and Otto Paulsen has written the documentation and made some changes to the files.
4
4
 
5
- ![Lovelace image](./lovelace.jpg)
5
+ ![Lovelace image](./lovelace.png)
6
6
 
7
7
  ## Introduction
8
8
 
@@ -30,7 +30,7 @@ apex_config:
30
30
  yaxis:
31
31
  - id: price
32
32
  show: true
33
- decimalsInFloat: 1
33
+ decimalsInFloat: 2
34
34
  floating: false
35
35
  forceNiceScale: true
36
36
  extend_to: end
@@ -52,15 +52,15 @@ series:
52
52
  extend_to: now
53
53
  name: Pris
54
54
  type: area
55
- curve: smooth
55
+ curve: stepline
56
56
  color: tomato
57
57
  show:
58
58
  legend_value: false
59
59
  data_generator: |
60
- return entity.attributes.hours.map((entry) => {
60
+ return entity.attributes.minutes.map((entry) => {
61
61
  return [new Date(entry.start), entry.price];
62
62
  });
63
- - entity: sensor.accumulated_consumption_current_hour_xxxx
63
+ - entity: sensor.accumulated_consumption_current_hour_xxx
64
64
  yaxis_id: usage
65
65
  type: column
66
66
  name: Forbruk
@@ -68,13 +68,14 @@ series:
68
68
  func: max
69
69
  show:
70
70
  legend_value: false
71
+ curve: smooth
71
72
  - entity: sensor.powersaver
72
73
  data_generator: |
73
- return entity.attributes.hours.map((entry) => {
74
+ return entity.attributes.minutes.map((entry) => {
74
75
  return [new Date(entry.start), entry.onOff];
75
76
  });
76
77
  yaxis_id: powersaver
77
- name: ' '
78
+ name: " "
78
79
  type: area
79
80
  color: rgb(0, 255, 0)
80
81
  opacity: 0.2
@@ -1,88 +1,74 @@
1
1
  [
2
2
  {
3
- "id": "eab799518168f5a3",
4
- "type": "ha-entity",
3
+ "id": "a6c0472f7981fad2",
4
+ "type": "function",
5
5
  "z": "d938c47f.3398f8",
6
- "name": "Info fra PS til HA",
7
- "server": "ec4a12a1.b2be9",
8
- "version": 2,
9
- "debugenabled": false,
6
+ "name": "Reduce minutes count",
7
+ "func": "const minutes = []\nlet previousHour = \"\"\nlet previousSaving = null\nmsg.payload.minutes.forEach(m => {\n const hour = m.start.substring(0, 13)\n if (hour !== previousHour || m.saving !== previousSaving) {\n minutes.push(m)\n previousHour = hour\n previousSaving = m.saving\n }\n})\n\nmsg.payload.minutes = minutes\nmsg.payload.hours = minutes\n\nreturn msg;",
10
8
  "outputs": 1,
11
- "entityType": "sensor",
12
- "config": [
13
- {
14
- "property": "name",
15
- "value": "Powersaver"
16
- },
17
- {
18
- "property": "device_class",
19
- "value": ""
20
- },
21
- {
22
- "property": "icon",
23
- "value": ""
24
- },
25
- {
26
- "property": "unit_of_measurement",
27
- "value": ""
28
- },
29
- {
30
- "property": "state_class",
31
- "value": ""
32
- },
33
- {
34
- "property": "last_reset",
35
- "value": ""
36
- }
37
- ],
38
- "state": "payload",
39
- "stateType": "str",
40
- "attributes": [
41
- {
42
- "property": "Schedule",
43
- "value": "payload.schedule",
44
- "valueType": "msg"
45
- },
46
- {
47
- "property": "Hours",
48
- "value": "payload.hours",
49
- "valueType": "msg"
50
- },
51
- {
52
- "property": "Control",
53
- "value": "payload.hours[0].onOff",
54
- "valueType": "str"
55
- },
56
- {
57
- "property": "Current",
58
- "value": "payload.current",
59
- "valueType": "str"
60
- }
61
- ],
62
- "resend": true,
63
- "outputLocation": "payload",
64
- "outputLocationType": "none",
65
- "inputOverride": "allow",
66
- "outputOnStateChange": false,
67
- "outputPayload": "",
68
- "outputPayloadType": "str",
69
- "x": 830,
70
- "y": 630,
71
- "wires": [[]]
9
+ "timeout": 0,
10
+ "noerr": 0,
11
+ "initialize": "",
12
+ "finalize": "",
13
+ "libs": [],
14
+ "x": 640,
15
+ "y": 640,
16
+ "wires": [["cad33a63f66ef72e"]]
72
17
  },
73
18
  {
74
19
  "id": "cad33a63f66ef72e",
75
20
  "type": "function",
76
21
  "z": "d938c47f.3398f8",
77
22
  "name": "Convert true/false to 1/0",
78
- "func": "msg.payload.hours.forEach(h => h.onOff = h.onOff ? \"1\" : \"0\")\nreturn msg;",
23
+ "func": "msg.payload.minutes.forEach(h => h.onOff = h.onOff ? \"1\" : \"0\")\nreturn msg;",
79
24
  "outputs": 1,
25
+ "timeout": "",
80
26
  "noerr": 0,
81
27
  "initialize": "",
82
28
  "finalize": "",
83
29
  "libs": [],
84
- "x": 550,
85
- "y": 630,
86
- "wires": [["eab799518168f5a3", "37a23d88cfc668f2"]]
30
+ "x": 880,
31
+ "y": 640,
32
+ "wires": [["4e2452b33c54d90b"]]
33
+ },
34
+ {
35
+ "id": "4e2452b33c54d90b",
36
+ "type": "ha-sensor",
37
+ "z": "d938c47f.3398f8",
38
+ "name": "Info fra PS til HA",
39
+ "entityConfig": "eab799518168f5a3",
40
+ "version": 0,
41
+ "state": "payload",
42
+ "stateType": "str",
43
+ "attributes": [
44
+ { "property": "Schedule", "value": "payload.schedule", "valueType": "msg" },
45
+ { "property": "Hours", "value": "payload.hours", "valueType": "msg" },
46
+ { "property": "Control", "value": "payload.minutes[0].onOff", "valueType": "str" },
47
+ { "property": "Current", "value": "payload.current", "valueType": "str" },
48
+ { "property": "Minutes", "value": "payload.minutes", "valueType": "msg" }
49
+ ],
50
+ "inputOverride": "allow",
51
+ "outputProperties": [],
52
+ "x": 1100,
53
+ "y": 640,
54
+ "wires": [[]]
55
+ },
56
+ {
57
+ "id": "eab799518168f5a3",
58
+ "type": "ha-entity-config",
59
+ "server": "ec4a12a1.b2be9",
60
+ "deviceConfig": "",
61
+ "name": "sensor config for Info fra PS til HA",
62
+ "version": 6,
63
+ "entityType": "sensor",
64
+ "haConfig": [
65
+ { "property": "name", "value": "Powersaver" },
66
+ { "property": "device_class", "value": "" },
67
+ { "property": "icon", "value": "" },
68
+ { "property": "unit_of_measurement", "value": "" },
69
+ { "property": "state_class", "value": "" },
70
+ { "property": "last_reset", "value": "" }
71
+ ],
72
+ "resend": true
87
73
  }
88
74
  ]
package/donation.png ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-power-saver",
3
- "version": "5.0.0-beta.0",
3
+ "version": "5.0.0-beta.2",
4
4
  "description": "A module for Node-RED that you can use to turn on and off a switch based on power prices",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,9 @@ const { fillArray } = require("./utils");
8
8
  *
9
9
  * @param {*} onOff Array of on/off values
10
10
  * @param {*} maxMinutesOff Max number of minutes that can be off in a sequence
11
- * @param {*} minMinutesOff Min number of minutes that must be on after maxOff is reached
11
+ * @param {*} minMinutesOff Min number of minutes that must be off to bother
12
+ * @param {*} recoveryPercentage Percent of off-time that must be on after being off
13
+ * @param {*} recoveryMaxMinutes Maximum recovery time in minutes
12
14
  * @returns
13
15
  */
14
16
  function isOnOffSequencesOk(
@@ -16,37 +18,53 @@ function isOnOffSequencesOk(
16
18
  maxMinutesOff,
17
19
  minMinutesOff,
18
20
  recoveryPercentage,
19
- recoveryMaxMinutes = null,
20
- minSaving) {
21
+ recoveryMaxMinutes = null) {
21
22
  let offCount = 0;
22
23
  let onCount = 0;
23
24
  let reachedMaxOff = false;
24
- let reachedMinOn = minMinutesOff === 0;
25
- let minOnAfterOff = null;
25
+ let reachedMinOn = true;
26
+ let reachedMinOff = null;
27
+ let minOnAfterOff = 0;
26
28
  for (let i = 0; i < onOff.length; i++) {
27
29
  if (!onOff[i]) {
28
30
  if (maxMinutesOff === 0 || reachedMaxOff) {
29
31
  return false;
30
32
  }
33
+ if(!reachedMinOn) {
34
+ return false;
35
+ }
36
+ if(reachedMinOff === null) {
37
+ reachedMinOff = false;
38
+ }
31
39
  offCount++;
32
40
  onCount = 0;
33
41
  if (offCount >= maxMinutesOff) {
34
42
  reachedMaxOff = true;
35
43
  }
36
44
  if (offCount >= minMinutesOff) {
37
- reachedMinOn = true;
45
+ reachedMinOff = true;
38
46
  }
39
47
  const minRounded = Math.max(Math.round(offCount * recoveryPercentage / 100), 1)
40
48
  minOnAfterOff = Math.min(minRounded, recoveryMaxMinutes ?? minRounded)
49
+ if(i === onOff.length - 1) {
50
+ // If last minute, consider min reached
51
+ reachedMinOn = true;
52
+ reachedMinOff = true;
53
+ }
41
54
  } else {
55
+ if(reachedMinOff === false) {
56
+ return false;
57
+ }
42
58
  onCount++;
43
59
  if (onCount >= minOnAfterOff) {
44
60
  reachedMaxOff = false;
61
+ reachedMinOn = true;
45
62
  }
46
63
  offCount = 0;
64
+ reachedMinOff = null;
47
65
  }
48
66
  }
49
- return reachedMinOn;
67
+ return reachedMinOn && !(reachedMinOff === false);
50
68
  }
51
69
 
52
70
  /**
package/src/utils.js CHANGED
@@ -105,6 +105,9 @@ function loadDayData(node, date) {
105
105
  schedule: [],
106
106
  minutes: [],
107
107
  };
108
+ if(!res.minutes) {
109
+ res.minutes = []
110
+ }
108
111
  return res;
109
112
  }
110
113
 
@@ -58,17 +58,7 @@
58
58
  {
59
59
  "time": "2021-06-20T02:33:00.000+02:00",
60
60
  "value": true,
61
- "countMinutes": 3
62
- },
63
- {
64
- "time": "2021-06-20T02:36:00.000+02:00",
65
- "value": false,
66
- "countMinutes": 1
67
- },
68
- {
69
- "time": "2021-06-20T02:37:00.000+02:00",
70
- "value": true,
71
- "countMinutes": 1
61
+ "countMinutes": 5
72
62
  },
73
63
  {
74
64
  "time": "2021-06-20T02:38:00.000+02:00",
@@ -58,17 +58,7 @@ module.exports = {
58
58
  {
59
59
  time: "2021-06-20T02:33:00.000+02:00",
60
60
  value: true,
61
- countMinutes: 3,
62
- },
63
- {
64
- time: "2021-06-20T02:36:00.000+02:00",
65
- value: false,
66
- countMinutes: 1,
67
- },
68
- {
69
- time: "2021-06-20T02:37:00.000+02:00",
70
- value: true,
71
- countMinutes: 1,
61
+ countMinutes: 5,
72
62
  },
73
63
  {
74
64
  time: "2021-06-20T02:38:00.000+02:00",