node-red-contrib-power-saver 5.0.0-beta.1 → 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,6 +7,10 @@ sidebarDepth: 1
7
7
 
8
8
  List the most significant changes.
9
9
 
10
+ ## 5.0.0.beta.2
11
+
12
+ - Fix bug in Min minutes off
13
+
10
14
  ## 5.0.0 beta.1
11
15
 
12
16
  - Fix bug `dataDayBefore.minutes is not iterable`
@@ -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.
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.1",
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
  /**
@@ -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",