node-red-contrib-power-saver 3.2.2 → 3.3.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.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/docs/.vuepress/clientAppEnhance.js +5 -0
- package/docs/.vuepress/components/BestSaveVerificator.vue +306 -0
- package/docs/.vuepress/components/DonateButtons.vue +87 -0
- package/docs/.vuepress/config.js +29 -5
- package/docs/.vuepress/dist/.nojekyll +0 -0
- package/docs/.vuepress/dist/404.html +5 -5
- package/docs/.vuepress/dist/assets/css/563.styles.99f4a8aa.css +1 -0
- package/docs/.vuepress/dist/assets/css/835.styles.c5afb22b.css +1 -0
- package/docs/.vuepress/dist/assets/css/{styles.e835bef6.css → styles.031dcf27.css} +2 -1
- package/docs/.vuepress/dist/assets/img/best-save-config.79a2f39a.png +0 -0
- package/docs/.vuepress/dist/assets/img/copy-payload-best-save.b9192985.png +0 -0
- package/docs/.vuepress/dist/assets/js/262.cf2c57d2.js +1 -0
- package/docs/.vuepress/dist/assets/js/{293.5e967839.js → 293.08ea5200.js} +0 -0
- package/docs/.vuepress/dist/assets/js/331.15ee3c51.js +1 -0
- package/docs/.vuepress/dist/assets/js/{491.c183eba3.js → 491.17a98f38.js} +0 -0
- package/docs/.vuepress/dist/assets/js/619.8ba1b1f6.js +2 -0
- package/docs/.vuepress/dist/assets/js/{812.79dad458.js.LICENSE.txt → 619.8ba1b1f6.js.LICENSE.txt} +0 -0
- package/docs/.vuepress/dist/assets/js/811.6a3392d5.js +1 -0
- package/docs/.vuepress/dist/assets/js/app.b705176c.js +1 -0
- package/docs/.vuepress/dist/assets/js/runtime~app.47f4f812.js +1 -0
- package/docs/.vuepress/dist/assets/js/{v-0607240a.661e1808.js → v-0607240a.a57c2199.js} +0 -0
- package/docs/.vuepress/dist/assets/js/{v-08683c60.a6b9cf5b.js → v-08683c60.ccafdcab.js} +0 -0
- package/docs/.vuepress/dist/assets/js/{v-0aca7ba6.b42fad7f.js → v-0aca7ba6.25903946.js} +0 -0
- package/docs/.vuepress/dist/assets/js/v-0b5e3c8c.a6a015b4.js +1 -0
- package/docs/.vuepress/dist/assets/js/{v-1ad821fa.6e2194d0.js → v-1ad821fa.5978386f.js} +0 -0
- package/docs/.vuepress/dist/assets/js/{v-1e2b191e.98cc227b.js → v-1e2b191e.88dc5555.js} +0 -0
- package/docs/.vuepress/dist/assets/js/v-29504124.4aca27d5.js +1 -0
- package/docs/.vuepress/dist/assets/js/{v-30acb564.f2fcd69f.js → v-30acb564.529a3c16.js} +0 -0
- package/docs/.vuepress/dist/assets/js/v-4637f9e4.703b1d96.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-510ed0d4.7b142a81.js +1 -0
- package/docs/.vuepress/dist/assets/js/{v-5954bcb2.182daf70.js → v-5954bcb2.937005d0.js} +0 -0
- package/docs/.vuepress/dist/assets/js/{v-5db8da3a.f2de6cb9.js → v-5db8da3a.3de3588d.js} +1 -1
- package/docs/.vuepress/dist/assets/js/{v-61f728ca.6fdbbb92.js → v-61f728ca.21d432fe.js} +1 -1
- package/docs/.vuepress/dist/assets/js/{v-677dfaed.0013f083.js → v-677dfaed.44a653b9.js} +0 -0
- package/docs/.vuepress/dist/assets/js/v-7446a652.74b21d0b.js +1 -0
- package/docs/.vuepress/dist/assets/js/v-7c87f26e.ee5be992.js +1 -0
- package/docs/.vuepress/dist/assets/js/{v-8daa1a0e.dde202c9.js → v-8daa1a0e.c63afc2b.js} +1 -1
- package/docs/.vuepress/dist/assets/js/{v-b4a42144.9e5f9728.js → v-b4a42144.733e4e7c.js} +0 -0
- package/docs/.vuepress/dist/assets/js/{v-e8c55052.8384b053.js → v-e8c55052.ab0a79ec.js} +0 -0
- package/docs/.vuepress/dist/assets/js/v-fffb8e28.525be02a.js +1 -0
- package/docs/.vuepress/dist/changelog/index.html +5 -5
- package/docs/.vuepress/dist/contribute/index.html +5 -5
- package/docs/.vuepress/dist/examples/example-next-schedule-entity.html +6 -6
- package/docs/.vuepress/dist/examples/example-nordpool-current-state.html +6 -7
- package/docs/.vuepress/dist/examples/example-nordpool-events-state.html +6 -6
- package/docs/.vuepress/dist/examples/example-tibber-mqtt.html +6 -7
- package/docs/.vuepress/dist/examples/index.html +5 -5
- package/docs/.vuepress/dist/faq/best-save-viewer.html +15 -0
- package/docs/.vuepress/dist/faq/index.html +5 -5
- package/docs/.vuepress/dist/guide/index.html +6 -6
- package/docs/.vuepress/dist/index.html +5 -5
- package/docs/.vuepress/dist/nodes/index.html +5 -5
- package/docs/.vuepress/dist/nodes/old-power-saver-doc.html +7 -7
- package/docs/.vuepress/dist/nodes/power-saver.html +5 -5
- package/docs/.vuepress/dist/nodes/ps-elvia-add-tariff.html +5 -5
- package/docs/.vuepress/dist/nodes/ps-general-add-tariff.html +5 -5
- package/docs/.vuepress/dist/nodes/ps-receive-price.html +8 -8
- package/docs/.vuepress/dist/nodes/ps-strategy-best-save.html +22 -8
- package/docs/.vuepress/dist/nodes/ps-strategy-lowest-price.html +17 -7
- package/docs/.vuepress/dist/nodes/strategy-input.html +5 -5
- package/docs/README.md +4 -1
- package/docs/changelog/README.md +23 -0
- package/docs/contribute/README.md +3 -3
- package/docs/examples/example-nordpool-current-state.md +0 -1
- package/docs/examples/example-tibber-mqtt.md +0 -1
- package/docs/faq/README.md +28 -1
- package/docs/faq/best-save-viewer.md +61 -0
- package/docs/images/best-save-config.png +0 -0
- package/docs/images/copy-payload-best-save.png +0 -0
- package/docs/nodes/ps-strategy-best-save.md +95 -8
- package/docs/nodes/ps-strategy-lowest-price.md +57 -0
- package/package.json +7 -3
- package/src/general-add-tariff-functions.js +0 -1
- package/src/general-add-tariff.js +2 -4
- package/src/handle-input.js +31 -9
- package/src/strategy-best-save.html +0 -21
- package/src/strategy-best-save.js +8 -11
- package/test/commands-input.test.js +47 -0
- package/test/data/best-save-result.json +1 -2
- package/test/data/current-undefined-prices.json +197 -0
- package/test/data/current-undefined-result.json +208 -0
- package/test/data/lowest-price-result-missing-end.json +2 -1
- package/test/data/reconfigResult.js +56 -294
- package/test/data/reconfigResult_old2.js +75 -0
- package/test/data/tibber-result-end-0-24h.json +1 -0
- package/test/data/tibber-result-end-0.json +1 -0
- package/test/send-config-input.test.js +3 -37
- package/test/strategy-best-save-test-utils.js +2 -1
- package/test/strategy-best-save.test.js +14 -8
- package/test/test-utils.js +1 -7
- package/test/utils.test.js +0 -33
- package/docs/.vuepress/dist/assets/img/best-save-config.93fa3c21.png +0 -0
- package/docs/.vuepress/dist/assets/js/812.79dad458.js +0 -2
- package/docs/.vuepress/dist/assets/js/app.46f7644a.js +0 -1
- package/docs/.vuepress/dist/assets/js/runtime~app.714a526c.js +0 -1
- package/docs/.vuepress/dist/assets/js/v-0b5e3c8c.3b37457f.js +0 -1
- package/docs/.vuepress/dist/assets/js/v-4637f9e4.b320f5e8.js +0 -1
- package/docs/.vuepress/dist/assets/js/v-510ed0d4.9d35e3e3.js +0 -1
- package/docs/.vuepress/dist/assets/js/v-7446a652.d05e2648.js +0 -1
- package/docs/.vuepress/dist/assets/js/v-7c87f26e.1127dcf5.js +0 -1
- package/docs/.vuepress/dist/assets/js/v-fffb8e28.3406fd88.js +0 -1
- package/test/data/adjustedResult.js +0 -302
- package/test/data/adjustedResult_old.js +0 -154
|
@@ -19,7 +19,6 @@ The picture at the bottom of the page, under [Integration with MagicMirror](#int
|
|
|
19
19
|
| Max per sequence | Maximum number of hours to turn off in a sequence. |
|
|
20
20
|
| Min recover | Minimum hours to turn on immediately after a period when turned off the maximum number of hours that is allowed to be turned off |
|
|
21
21
|
| Min saving | Minimum amount to save per kWh in order to bother turning it off. It is recommended to have some amount here, e.g. 2 cents / 2 øre. No point in saving 0.001, is it? |
|
|
22
|
-
| Schedule for | Select to schedule for the whole data set or only from the current hour. |
|
|
23
22
|
| Send when rescheduling | Check this to make sure on or off output is sent immediately after rescheduling |
|
|
24
23
|
| If no schedule, send | What to do if there is no valid schedule any more (turn on or off). |
|
|
25
24
|
|
|
@@ -27,10 +26,6 @@ The picture at the bottom of the page, under [Integration with MagicMirror](#int
|
|
|
27
26
|
NB! The `Min recover` only has effect if the previous save-period is of length `Max per sequence`. If the save-period is shorter, the following on-period may be as short as one hour.
|
|
28
27
|
:::
|
|
29
28
|
|
|
30
|
-
::: tip Legionella
|
|
31
|
-
Many people ask if there is a danger that legionella bacteria will grow and become dangerous when the temperature of the water heater is lowered. As long as the water is heated to at least 65 °C every day, or at least every week, the risk of infection is not considered significant, according to the norwegian [FHI](https://www.fhi.no/nettpub/legionellaveilederen/).
|
|
32
|
-
:::
|
|
33
|
-
|
|
34
29
|
### Dynamic config
|
|
35
30
|
|
|
36
31
|
It is possible to change config dynamically by sending a config message to the node. The config messages has a payload with a config object like this example:
|
|
@@ -43,7 +38,6 @@ It is possible to change config dynamically by sending a config message to the n
|
|
|
43
38
|
"minSaving": 0.02,
|
|
44
39
|
"sendCurrentValueWhenRescheduling": true,
|
|
45
40
|
"outputIfNoSchedule": true,
|
|
46
|
-
"scheduleOnlyFromCurrentTime": false
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
```
|
|
@@ -54,11 +48,72 @@ The config sent like this will be valid until a new config is sent the same way,
|
|
|
54
48
|
|
|
55
49
|
When a config is sent like this, and without price data, the schedule will be replanned based on the last previously received price data. If no price data has been received, no scheduling is done.
|
|
56
50
|
|
|
57
|
-
However, you can send config and price data in the same message. Then both will be used
|
|
51
|
+
However, you can send config and price data in the same message. Then both will be used.
|
|
52
|
+
|
|
53
|
+
### Dynamic commands
|
|
54
|
+
|
|
55
|
+
You can dynamically send some commands to the node via its input, by using a `commands` object in the payload as described below.
|
|
56
|
+
|
|
57
|
+
Commands can be sent together with config and/or price data, but the exact behavior is not defined.
|
|
58
|
+
|
|
59
|
+
#### sendSchedule
|
|
60
|
+
|
|
61
|
+
You can get the schedule sent to output 3 any time by sending a message like this to the node:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
"payload": {
|
|
65
|
+
"commands": {
|
|
66
|
+
"sendSchedule": true,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
When you do this, the current schedule is actually recalculated based on the last received data, and then sent to output 3 the same way as when it was originally planned.
|
|
72
|
+
|
|
73
|
+
#### sendOutput
|
|
74
|
+
|
|
75
|
+
You can get the node to send the current output to output 1 or 2 any time by sending a message like this to the node:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
"payload": {
|
|
79
|
+
"commands": {
|
|
80
|
+
"sendOutput": true,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
When you do this, the current schedule is actually recalculated based on the last received data. The current output is sent to output 1 or 2, and the schedule is sent to output 3.
|
|
86
|
+
|
|
87
|
+
#### reset
|
|
88
|
+
|
|
89
|
+
You can reset data the node has saved in context by sending this message:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
"payload": {
|
|
93
|
+
"commands": {
|
|
94
|
+
"reset": true,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
When you do this, all historical data the node has saved is deleted, including the current schedule, so the result will be
|
|
100
|
+
that the node shows status "No price data". When new price data is received, a schedule is calculated without considering any history.
|
|
101
|
+
|
|
102
|
+
The nodes config is not deleted, as the node depends on it to work.
|
|
103
|
+
|
|
104
|
+
::: warning
|
|
105
|
+
This operation cannot be undone.
|
|
106
|
+
|
|
107
|
+
However, it is normally not a big loss, as you can just feed the node with new price data and start from scratch.
|
|
108
|
+
:::
|
|
58
109
|
|
|
59
110
|
## Input
|
|
60
111
|
|
|
61
|
-
The input is the [common strategy input format](./strategy-input.md)
|
|
112
|
+
The input is the [common strategy input format](./strategy-input.md).
|
|
113
|
+
|
|
114
|
+
In addition to the prices sent as input,
|
|
115
|
+
the node is using the schedule for the day before it receives data for,
|
|
116
|
+
so that it can calculate the schedule in the beginning of the day according to the configured rules. This requires of course that the node was run the day before.
|
|
62
117
|
|
|
63
118
|
## Output
|
|
64
119
|
|
|
@@ -125,6 +180,12 @@ Example of output:
|
|
|
125
180
|
|
|
126
181
|
The `schedule` array shows every time the switch is turned on or off. The `hours` array shows values per hour containing the price (received as input), whether that hour is on or off, the start time of the hour and the amount per kWh that is saved on hours that are turned off, compared to the next hour that is on.
|
|
127
182
|
|
|
183
|
+
### Data saved in context
|
|
184
|
+
|
|
185
|
+
The node saves some data in the nodes context, so that it can be used on restarts and also taken into consideration when calculating the schedule over midnight.
|
|
186
|
+
|
|
187
|
+
You can see the saved data if you select the node in Node-RED, and view "Context data", and refresh the Node context.
|
|
188
|
+
|
|
128
189
|
## Algorithm
|
|
129
190
|
|
|
130
191
|
The calculation that decides what hours to turn off works as follows:
|
|
@@ -139,6 +200,28 @@ The calculation that decides what hours to turn off works as follows:
|
|
|
139
200
|
|
|
140
201
|
I say "in most cases", because there is a chance that a group of two or more sequences combined can give a better plan than a single sequence preceeding those two, but where the selection of the one sequence causes the group to be discarded. If anyone encounters this situation, I would be happy to receive the price data set, and try to improve the algorithm even further.
|
|
141
202
|
|
|
203
|
+
## Data used for calculation
|
|
204
|
+
|
|
205
|
+
Normally data is received for one or two whole days, and all this data is used to do the calculation. In addition, if the node has run before, so there is historical data, the last period on or off before the period data is received for, is considered in the calculation, so that the rules in the configuration are followed also between days.
|
|
206
|
+
|
|
207
|
+
## Restarts
|
|
208
|
+
|
|
209
|
+
The node saves data in the nodes context, so if Node-RED is configured to save context between restarts, the node will replan with the last received data when it restarts.
|
|
210
|
+
|
|
211
|
+
::: warning
|
|
212
|
+
In Home Assistant, Node-RED is by default configured to save context between restarts. However, if you run Node-RED another way, this may not be the case by default. If context is only stored in memory, it is lost between restarts, and even between re-deployments. This can be changed in the `settings.js` file for Node-RED like this:
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
contextStorage: {
|
|
216
|
+
default: {
|
|
217
|
+
module: "localfilesystem"
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Please read the [Node-RED documentation](https://nodered.org/docs/user-guide/context) for more details about this.
|
|
223
|
+
:::
|
|
224
|
+
|
|
142
225
|
## Integration with MagicMirror
|
|
143
226
|
|
|
144
227
|
Are you using [MagicMirror](https://magicmirror.builders/)? Are you also using [Tibber](https://tibber.com/)? If so, there is a module for MM called [MMM-Tibber](https://github.com/ottopaulsen/MMM-Tibber), that easily can be used to show savings from this node.
|
|
@@ -148,3 +231,7 @@ Are you using [MagicMirror](https://magicmirror.builders/)? Are you also using [
|
|
|
148
231
|
The purple lines show savings per kWh.
|
|
149
232
|
|
|
150
233
|
Read more about this in the [MMM-Tibber documentation](https://github.com/ottopaulsen/MMM-Tibber#show-savings).
|
|
234
|
+
|
|
235
|
+
## Viewer
|
|
236
|
+
|
|
237
|
+
If you like to analyze the data output by the node, take a look at the [Best Save Viewer](../faq/best-save-viewer.md).
|
|
@@ -74,6 +74,63 @@ When a config is sent like this, and without price data, the schedule will be re
|
|
|
74
74
|
|
|
75
75
|
However, you can send config and price data in the same message. Then both will be used .
|
|
76
76
|
|
|
77
|
+
### Dynamic commands
|
|
78
|
+
|
|
79
|
+
You can dynamically send some commands to the node via its input, by using a `commands` object in the payload as described below.
|
|
80
|
+
|
|
81
|
+
Commands can be sent together with config and/or price data, but the exact behavior is not defined.
|
|
82
|
+
|
|
83
|
+
#### sendSchedule
|
|
84
|
+
|
|
85
|
+
You can get the schedule sent to output 3 any time by sending a message like this to the node:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
"payload": {
|
|
89
|
+
"commands": {
|
|
90
|
+
"sendSchedule": true,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
When you do this, the current schedule is actually recalculated based on the last received data, and then sent to output 3 the same way as when it was originally planned.
|
|
96
|
+
|
|
97
|
+
#### sendOutput
|
|
98
|
+
|
|
99
|
+
You can get the node to send the current output to output 1 or 2 any time by sending a message like this to the node:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
"payload": {
|
|
103
|
+
"commands": {
|
|
104
|
+
"sendOutput": true,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
When you do this, the current schedule is actually recalculated based on the last received data. The current output is sent to output 1 or 2, and the schedule is sent to output 3.
|
|
110
|
+
|
|
111
|
+
#### reset
|
|
112
|
+
|
|
113
|
+
You can reset data the node has saved in context by sending this message:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
"payload": {
|
|
117
|
+
"commands": {
|
|
118
|
+
"reset": true,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
When you do this, all historical data the node has saved is deleted, including the current schedule, so the result will be
|
|
124
|
+
that the node shows status "No price data". When new price data is received, a schedule is calculated without considering any history.
|
|
125
|
+
|
|
126
|
+
The nodes config is not deleted, as the node depends on it to work.
|
|
127
|
+
|
|
128
|
+
::: warning
|
|
129
|
+
This operation cannot be undone.
|
|
130
|
+
|
|
131
|
+
However, it is normally not a big loss, as you can just feed the node with new price data and start from scratch.
|
|
132
|
+
:::
|
|
133
|
+
|
|
77
134
|
## Input
|
|
78
135
|
|
|
79
136
|
The input is the [common strategy input format](./strategy-input.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-power-saver",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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": {
|
|
@@ -40,15 +40,19 @@
|
|
|
40
40
|
"url": "https://github.com/ottopaulsen/node-red-contrib-power-saver.git"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@vuepress/plugin-register-components": "^2.0.0-beta.33",
|
|
44
|
+
"@vuepress/utils": "^2.0.0-beta.27",
|
|
43
45
|
"expect": "^27.0.2",
|
|
44
46
|
"mocha": "^6.2.1",
|
|
45
47
|
"node-red": "^1.3.5",
|
|
46
48
|
"node-red-node-test-helper": "^0.2.7",
|
|
49
|
+
"patch-vue-directive-ssr": "^0.0.1",
|
|
47
50
|
"vuepress": "^2.0.0-beta.27"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
53
|
+
"floating-vue": "^2.0.0-beta.3",
|
|
50
54
|
"lodash.clonedeep": "^4.5.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
55
|
+
"luxon": "^1.27.0",
|
|
56
|
+
"node-fetch": "^2.6.6"
|
|
53
57
|
}
|
|
54
58
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const cloneDeep = require("lodash.clonedeep");
|
|
2
|
-
const {
|
|
3
|
-
const {
|
|
4
|
-
const { roundPrice } = require("./utils");
|
|
5
|
-
const { extractPlanForDate, getEffectiveConfig, validationFailure } = require("./utils");
|
|
2
|
+
const { addTariffToPrices } = require("./general-add-tariff-functions");
|
|
3
|
+
const { getEffectiveConfig } = require("./utils");
|
|
6
4
|
|
|
7
5
|
module.exports = function (RED) {
|
|
8
6
|
function PsGeneralAddTariffNode(config) {
|
package/src/handle-input.js
CHANGED
|
@@ -8,8 +8,17 @@ function handleStrategyInput(node, msg, doPlanning) {
|
|
|
8
8
|
if (!validateInput(node, msg)) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
if (msg.payload.commands && msg.payload.commands.reset) {
|
|
12
|
+
node.warn("Resetting node context by command");
|
|
13
|
+
// Reset all saved data
|
|
14
|
+
node.context().set(["lastPlan", "lastPriceData", "lastSource"], [undefined, undefined, undefined]);
|
|
15
|
+
deleteSavedScheduleBefore(node, DateTime.now().plus({ days: 1 }), 100);
|
|
16
|
+
}
|
|
17
|
+
const { priceData, source } = getPriceData(node, msg);
|
|
12
18
|
if (!priceData) {
|
|
19
|
+
const message = "No price data";
|
|
20
|
+
node.warn(message);
|
|
21
|
+
node.status({ fill: "yellow", shape: "dot", text: message });
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
15
24
|
const planFromTime = msg.payload.time ? DateTime.fromISO(msg.payload.time) : DateTime.now();
|
|
@@ -32,6 +41,8 @@ function handleStrategyInput(node, msg, doPlanning) {
|
|
|
32
41
|
node.context().set("lastPlan", plan);
|
|
33
42
|
dates.forEach((d) => saveDayData(node, d, extractPlanForDate(plan, d)));
|
|
34
43
|
|
|
44
|
+
const sentOnCommand = !!msg.payload.commands?.sendSchedule;
|
|
45
|
+
|
|
35
46
|
// Prepare output
|
|
36
47
|
let output1 = null;
|
|
37
48
|
let output2 = null;
|
|
@@ -39,8 +50,9 @@ function handleStrategyInput(node, msg, doPlanning) {
|
|
|
39
50
|
payload: {
|
|
40
51
|
schedule: plan.schedule,
|
|
41
52
|
hours: plan.hours,
|
|
42
|
-
source
|
|
53
|
+
source,
|
|
43
54
|
config: effectiveConfig,
|
|
55
|
+
sentOnCommand,
|
|
44
56
|
time: planFromTime.toISO(),
|
|
45
57
|
version,
|
|
46
58
|
},
|
|
@@ -49,9 +61,9 @@ function handleStrategyInput(node, msg, doPlanning) {
|
|
|
49
61
|
// Find current output, and set output (if configured to do)
|
|
50
62
|
const pastSchedule = plan.schedule.filter((entry) => DateTime.fromISO(entry.time) <= planFromTime);
|
|
51
63
|
|
|
52
|
-
const sendNow = node.sendCurrentValueWhenRescheduling && pastSchedule.length > 0;
|
|
64
|
+
const sendNow = !!node.sendCurrentValueWhenRescheduling && pastSchedule.length > 0 && !sentOnCommand;
|
|
53
65
|
const currentValue = pastSchedule[pastSchedule.length - 1]?.value;
|
|
54
|
-
if (sendNow) {
|
|
66
|
+
if (sendNow || !!msg.payload.commands?.sendOutput) {
|
|
55
67
|
output1 = currentValue ? { payload: true } : null;
|
|
56
68
|
output2 = currentValue ? null : { payload: false };
|
|
57
69
|
}
|
|
@@ -69,13 +81,18 @@ function handleStrategyInput(node, msg, doPlanning) {
|
|
|
69
81
|
|
|
70
82
|
function getPriceData(node, msg) {
|
|
71
83
|
const isConfigMsg = !!msg?.payload?.config;
|
|
84
|
+
const isCommandMsg = !!msg?.payload?.commands;
|
|
72
85
|
const isPriceMsg = !!msg?.payload?.priceData;
|
|
73
|
-
if (isConfigMsg && !isPriceMsg) {
|
|
74
|
-
|
|
86
|
+
if ((isConfigMsg || isCommandMsg) && !isPriceMsg) {
|
|
87
|
+
const priceData = node.context().get("lastPriceData");
|
|
88
|
+
const source = node.context().get("lastSource");
|
|
89
|
+
return { priceData, source };
|
|
75
90
|
}
|
|
76
91
|
const priceData = msg.payload.priceData;
|
|
92
|
+
const source = msg.payload.source;
|
|
77
93
|
node.context().set("lastPriceData", priceData);
|
|
78
|
-
|
|
94
|
+
node.context().set("lastSource", source);
|
|
95
|
+
return { priceData, source };
|
|
79
96
|
}
|
|
80
97
|
|
|
81
98
|
function runSchedule(node, schedule, time, currentSent = false) {
|
|
@@ -106,12 +123,14 @@ function runSchedule(node, schedule, time, currentSent = false) {
|
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
|
|
109
|
-
function deleteSavedScheduleBefore(node, day) {
|
|
126
|
+
function deleteSavedScheduleBefore(node, day, checkDays = 0) {
|
|
110
127
|
let date = day;
|
|
128
|
+
let count = 0;
|
|
111
129
|
do {
|
|
112
130
|
date = date.plus({ days: -1 });
|
|
113
131
|
data = node.context().set(date.toISO(), undefined);
|
|
114
|
-
|
|
132
|
+
count++;
|
|
133
|
+
} while (data || count <= checkDays);
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
function saveDayData(node, date, plan) {
|
|
@@ -136,6 +155,9 @@ function validateInput(node, msg) {
|
|
|
136
155
|
if (msg.payload.config !== undefined) {
|
|
137
156
|
return true; // Got config msg
|
|
138
157
|
}
|
|
158
|
+
if (msg.payload.commands !== undefined) {
|
|
159
|
+
return true; // Got command msg
|
|
160
|
+
}
|
|
139
161
|
if (msg.payload.priceData === undefined) {
|
|
140
162
|
validationFailure(node, "Payload is missing priceData");
|
|
141
163
|
return;
|
|
@@ -26,11 +26,6 @@
|
|
|
26
26
|
align: "left",
|
|
27
27
|
},
|
|
28
28
|
outputIfNoSchedule: { value: "true", required: true, align: "left" },
|
|
29
|
-
scheduleOnlyFromCurrentTime: {
|
|
30
|
-
value: "true",
|
|
31
|
-
required: true,
|
|
32
|
-
align: "left",
|
|
33
|
-
},
|
|
34
29
|
},
|
|
35
30
|
inputs: 1,
|
|
36
31
|
outputs: 3,
|
|
@@ -52,17 +47,6 @@
|
|
|
52
47
|
},
|
|
53
48
|
],
|
|
54
49
|
});
|
|
55
|
-
$("#node-input-scheduleOnlyFromCurrentTime").typedInput({
|
|
56
|
-
types: [
|
|
57
|
-
{
|
|
58
|
-
value: "nowOrStart",
|
|
59
|
-
options: [
|
|
60
|
-
{ value: "false", label: "Whole data set" },
|
|
61
|
-
{ value: "true", label: "From current hour" },
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
});
|
|
66
50
|
},
|
|
67
51
|
});
|
|
68
52
|
</script>
|
|
@@ -88,11 +72,6 @@
|
|
|
88
72
|
<label for="node-input-minSaving"><i class="fa fa-eur"></i> Min saving</label>
|
|
89
73
|
<input type="text" id="node-input-minSaving" placeholder="Minimum to save for turning off" style="width: 80px">
|
|
90
74
|
</div>
|
|
91
|
-
<div class="form-row">
|
|
92
|
-
<label for="node-input-scheduleOnlyFromCurrentTime">Schedule for</label>
|
|
93
|
-
<input type="text" id="node-input-scheduleOnlyFromCurrentTime" style="width: 160px">
|
|
94
|
-
</label>
|
|
95
|
-
</div>
|
|
96
75
|
<h3>Output</h3>
|
|
97
76
|
<div class="form-row">
|
|
98
77
|
<label for="node-input-sendCurrentValueWhenRescheduling" style="width:240px">
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { countAtEnd, makeSchedule, getSavings,
|
|
1
|
+
const { countAtEnd, makeSchedule, getSavings, getDiff } = require("./utils");
|
|
2
2
|
const { handleStrategyInput } = require("./handle-input");
|
|
3
3
|
const { loadDayData } = require("./utils");
|
|
4
4
|
|
|
@@ -15,7 +15,6 @@ module.exports = function (RED) {
|
|
|
15
15
|
minSaving: parseFloat(config.minSaving),
|
|
16
16
|
sendCurrentValueWhenRescheduling: config.sendCurrentValueWhenRescheduling,
|
|
17
17
|
outputIfNoSchedule: config.outputIfNoSchedule === "true",
|
|
18
|
-
scheduleOnlyFromCurrentTime: config.scheduleOnlyFromCurrentTime === "true",
|
|
19
18
|
};
|
|
20
19
|
node.context().set("config", originalConfig);
|
|
21
20
|
|
|
@@ -43,20 +42,18 @@ function adjustSavingsPassedHours(plan, includeFromLastPlanHours) {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
function loadDataJustBefore(node, dateDayBefore
|
|
45
|
+
function loadDataJustBefore(node, dateDayBefore) {
|
|
47
46
|
const dataDayBefore = loadDayData(node, dateDayBefore);
|
|
48
|
-
const dataToday = loadDayData(node, dateToday);
|
|
49
47
|
return {
|
|
50
|
-
schedule: [...dataDayBefore.schedule
|
|
51
|
-
hours: [...dataDayBefore.hours
|
|
48
|
+
schedule: [...dataDayBefore.schedule],
|
|
49
|
+
hours: [...dataDayBefore.hours],
|
|
52
50
|
};
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
function doPlanning(node,
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const startTimes = priceData.map((d) => d.start).slice(startAtIndex);
|
|
53
|
+
function doPlanning(node, _, priceData, _, dateDayBefore, _) {
|
|
54
|
+
const dataJustBefore = loadDataJustBefore(node, dateDayBefore);
|
|
55
|
+
const values = priceData.map((d) => d.value);
|
|
56
|
+
const startTimes = priceData.map((d) => d.start);
|
|
60
57
|
const onOffBefore = dataJustBefore.hours.map((h) => h.onOff);
|
|
61
58
|
const lastPlanHours = node.context().get("lastPlan")?.hours ?? [];
|
|
62
59
|
const plan = makePlan(node, values, startTimes, onOffBefore);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const expect = require("expect");
|
|
2
|
+
const helper = require("node-red-node-test-helper");
|
|
3
|
+
const bestSave = require("../src/strategy-best-save.js");
|
|
4
|
+
const prices = require("./data/converted-prices.json");
|
|
5
|
+
const result = require("./data/best-save-result.json");
|
|
6
|
+
const { testPlan, equalPlan } = require("./test-utils");
|
|
7
|
+
const { makeFlow, makePayload } = require("./strategy-best-save-test-utils");
|
|
8
|
+
|
|
9
|
+
helper.init(require.resolve("node-red"));
|
|
10
|
+
|
|
11
|
+
describe("send command as input", () => {
|
|
12
|
+
beforeEach(function (done) {
|
|
13
|
+
helper.startServer(done);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(function (done) {
|
|
17
|
+
helper.unload().then(function () {
|
|
18
|
+
helper.stopServer(done);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should send output on command", function (done) {
|
|
23
|
+
const flow = makeFlow(3, 2, true);
|
|
24
|
+
let pass = 1;
|
|
25
|
+
helper.load(bestSave, flow, function () {
|
|
26
|
+
const n1 = helper.getNode("n1");
|
|
27
|
+
const n2 = helper.getNode("n2");
|
|
28
|
+
n1.sendCurrentValueWhenRescheduling = true;
|
|
29
|
+
n2.on("input", function (msg) {
|
|
30
|
+
switch (pass) {
|
|
31
|
+
case 1:
|
|
32
|
+
pass++;
|
|
33
|
+
expect(equalPlan(result, msg.payload)).toBeTruthy();
|
|
34
|
+
expect(msg.payload.sentOnCommand).toBeFalsy();
|
|
35
|
+
n1.receive({ payload: { commands: { sendSchedule: true } } });
|
|
36
|
+
break;
|
|
37
|
+
case 2:
|
|
38
|
+
expect(equalPlan(result, msg.payload)).toBeTruthy();
|
|
39
|
+
expect(msg.payload.sentOnCommand).toBeTruthy();
|
|
40
|
+
done();
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
n1.receive({ payload: makePayload(prices, testPlan.time) });
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|