smart-nodes 0.3.15 → 0.3.22
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/central/central.js +2 -0
- package/delay/delay.js +4 -4
- package/hysteresis/hysteresis.js +20 -8
- package/light-control/light-control.js +15 -5
- package/package.json +1 -1
- package/scene-control/scene-control.js +8 -0
- package/shutter-complex-control/shutter-complex-control.js +2 -0
- package/shutter-control/shutter-control.js +2 -0
- package/smart_helper.js +36 -0
- package/text-exec/text-exec.js +11 -5
package/central/central.js
CHANGED
package/delay/delay.js
CHANGED
|
@@ -137,7 +137,7 @@ module.exports = function (RED)
|
|
|
137
137
|
// No delay if 0 or smaller
|
|
138
138
|
if (delayMs <= 0)
|
|
139
139
|
{
|
|
140
|
-
node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" +
|
|
140
|
+
node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" + +msg.topic + "' msg.payload = '" + msg.payload + "'" });
|
|
141
141
|
nodeSettings.lastMessage = msg
|
|
142
142
|
|
|
143
143
|
if (config.save_state)
|
|
@@ -148,11 +148,11 @@ module.exports = function (RED)
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
// start new timeout
|
|
151
|
-
node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "Forward msg.topic = '" +
|
|
151
|
+
node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "Forward msg.topic = '" + msg.topic + "' msg.payload = '" + msg.payload + "' in " + helper.formatMsToStatus(delayMs, "at") });
|
|
152
152
|
timeout = setTimeout(() =>
|
|
153
153
|
{
|
|
154
154
|
timeout = null;
|
|
155
|
-
node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" +
|
|
155
|
+
node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" + msg.topic + "' msg.payload = '" + msg.payload + "'" });
|
|
156
156
|
nodeSettings.lastMessage = msg
|
|
157
157
|
|
|
158
158
|
if (config.save_state)
|
|
@@ -166,7 +166,7 @@ module.exports = function (RED)
|
|
|
166
166
|
{
|
|
167
167
|
setTimeout(() =>
|
|
168
168
|
{
|
|
169
|
-
node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" +
|
|
169
|
+
node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" + nodeSettings.lastMessage.topic + "' msg.payload = '" + nodeSettings.lastMessage.payload + "'" });
|
|
170
170
|
node.send(nodeSettings.lastMessage);
|
|
171
171
|
}, 10000);
|
|
172
172
|
}
|
package/hysteresis/hysteresis.js
CHANGED
|
@@ -12,6 +12,8 @@ module.exports = function (RED)
|
|
|
12
12
|
var nodeSettings = {
|
|
13
13
|
active: null,
|
|
14
14
|
lastMessage: null,
|
|
15
|
+
setpoint: parseFloat(config.setpoint),
|
|
16
|
+
hysteresis: parseFloat(config.hysteresis)
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
if (config.save_state)
|
|
@@ -42,8 +44,6 @@ module.exports = function (RED)
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
// dynamic config
|
|
45
|
-
let setpoint = parseFloat(config.setpoint);
|
|
46
|
-
let hysteresis = parseFloat(config.hysteresis);
|
|
47
47
|
let out_higher = helper.evaluateNodeProperty(RED, config.out_higher, config.out_higher_type);
|
|
48
48
|
let out_lower = helper.evaluateNodeProperty(RED, config.out_lower, config.out_lower_type);
|
|
49
49
|
|
|
@@ -63,7 +63,7 @@ module.exports = function (RED)
|
|
|
63
63
|
switch (realTopic)
|
|
64
64
|
{
|
|
65
65
|
case "setpoint":
|
|
66
|
-
setpoint = value;
|
|
66
|
+
nodeSettings.setpoint = value;
|
|
67
67
|
node.status({ fill: nodeSettings.active ? "green" : "red", shape: "ring", text: (new Date()).toLocaleString() + ": New setpoint: " + value + "" });
|
|
68
68
|
|
|
69
69
|
if (config.save_state)
|
|
@@ -71,7 +71,7 @@ module.exports = function (RED)
|
|
|
71
71
|
break;
|
|
72
72
|
|
|
73
73
|
case "hysteresis":
|
|
74
|
-
hysteresis = value;
|
|
74
|
+
nodeSettings.hysteresis = value;
|
|
75
75
|
node.status({ fill: nodeSettings.active ? "green" : "red", shape: "ring", text: (new Date()).toLocaleString() + ": New hysteresis: " + value + "" });
|
|
76
76
|
|
|
77
77
|
if (config.save_state)
|
|
@@ -96,22 +96,22 @@ module.exports = function (RED)
|
|
|
96
96
|
break;
|
|
97
97
|
|
|
98
98
|
default:
|
|
99
|
-
if (value >= setpoint + hysteresis && nodeSettings.active !== true)
|
|
99
|
+
if (value >= nodeSettings.setpoint + nodeSettings.hysteresis && nodeSettings.active !== true)
|
|
100
100
|
{
|
|
101
101
|
node.status({ fill: "green", shape: "dot", text: (new Date()).toLocaleString() + ": Turned higher by value " + value + "" });
|
|
102
102
|
nodeSettings.active = true;
|
|
103
|
-
nodeSettings.lastMessage = out_higher ?? msg;
|
|
103
|
+
nodeSettings.lastMessage = createMessage(out_higher ?? msg, value);
|
|
104
104
|
|
|
105
105
|
if (config.save_state)
|
|
106
106
|
smartContext.set(node.id, nodeSettings);
|
|
107
107
|
|
|
108
108
|
node.send([nodeSettings.lastMessage, null]);
|
|
109
109
|
}
|
|
110
|
-
else if (value <= setpoint - hysteresis && nodeSettings.active !== false)
|
|
110
|
+
else if (value <= nodeSettings.setpoint - nodeSettings.hysteresis && nodeSettings.active !== false)
|
|
111
111
|
{
|
|
112
112
|
node.status({ fill: "red", shape: "dot", text: (new Date()).toLocaleString() + ": Turned lower by value " + value + "" });
|
|
113
113
|
nodeSettings.active = false;
|
|
114
|
-
nodeSettings.lastMessage = out_lower ?? msg;
|
|
114
|
+
nodeSettings.lastMessage = createMessage(out_lower ?? msg, value);
|
|
115
115
|
|
|
116
116
|
if (config.save_state)
|
|
117
117
|
smartContext.set(node.id, nodeSettings);
|
|
@@ -130,6 +130,18 @@ module.exports = function (RED)
|
|
|
130
130
|
{
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
let createMessage = (msg, value) =>
|
|
134
|
+
{
|
|
135
|
+
return Object.assign({}, msg, {
|
|
136
|
+
smart_info: {
|
|
137
|
+
active: nodeSettings.active,
|
|
138
|
+
hysteresis: nodeSettings.hysteresis,
|
|
139
|
+
setpoint: nodeSettings.setpoint,
|
|
140
|
+
last_value: value
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
};
|
|
144
|
+
|
|
133
145
|
if (config.save_state && config.resend_on_start && nodeSettings.active != null && nodeSettings.lastMessage != null)
|
|
134
146
|
{
|
|
135
147
|
setTimeout(() =>
|
|
@@ -27,7 +27,7 @@ module.exports = function (RED)
|
|
|
27
27
|
let max_time_on_timeout = null;
|
|
28
28
|
let isPermanent = false;
|
|
29
29
|
let isMotion = false;
|
|
30
|
-
let
|
|
30
|
+
let timeout_end_date = null;
|
|
31
31
|
let alarm_active = false;
|
|
32
32
|
|
|
33
33
|
// central handling
|
|
@@ -62,7 +62,9 @@ module.exports = function (RED)
|
|
|
62
62
|
case "status":
|
|
63
63
|
// Make sure it is bool
|
|
64
64
|
msg.payload = !!msg.payload;
|
|
65
|
-
|
|
65
|
+
|
|
66
|
+
if (nodeSettings.last_value == msg.payload && max_time_on_timeout != null)
|
|
67
|
+
doRestartTimer = false;
|
|
66
68
|
|
|
67
69
|
nodeSettings.last_value = msg.payload;
|
|
68
70
|
break;
|
|
@@ -178,7 +180,9 @@ module.exports = function (RED)
|
|
|
178
180
|
timeMs = max_time_on;
|
|
179
181
|
}
|
|
180
182
|
|
|
181
|
-
|
|
183
|
+
// calculate end date for status message
|
|
184
|
+
timeout_end_date = new Date();
|
|
185
|
+
timeout_end_date.setMilliseconds(timeout_end_date.getMilliseconds() + timeMs);
|
|
182
186
|
|
|
183
187
|
// Stop if any timeout is set
|
|
184
188
|
stopAutoOff();
|
|
@@ -216,10 +220,10 @@ module.exports = function (RED)
|
|
|
216
220
|
}
|
|
217
221
|
else if (nodeSettings.last_value)
|
|
218
222
|
{
|
|
219
|
-
if (isPermanent || isMotion ||
|
|
223
|
+
if (isPermanent || isMotion || timeout_end_date == null)
|
|
220
224
|
node.status({ fill: "green", shape: "dot", text: (new Date()).toLocaleString() + ": On" });
|
|
221
225
|
else if (max_time_on_timeout)
|
|
222
|
-
node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": Wait " + helper.
|
|
226
|
+
node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": Wait " + helper.formatDateToStatus(timeout_end_date, "until") + " for auto off" });
|
|
223
227
|
}
|
|
224
228
|
else
|
|
225
229
|
{
|
|
@@ -234,10 +238,16 @@ module.exports = function (RED)
|
|
|
234
238
|
|
|
235
239
|
config.links.forEach(link =>
|
|
236
240
|
{
|
|
241
|
+
// console.log(node.id + " -> " + link);
|
|
242
|
+
// console.log({ source: node.id, state: state });
|
|
237
243
|
RED.events.emit("node:" + link, { source: node.id, state: state });
|
|
238
244
|
});
|
|
239
245
|
}
|
|
240
246
|
|
|
247
|
+
// After node red restart, start also the timeout
|
|
248
|
+
if (nodeSettings.last_value)
|
|
249
|
+
startAutoOffIfNeeded(helper.getTimeInMsFromString(max_time_on));
|
|
250
|
+
|
|
241
251
|
setStatus();
|
|
242
252
|
}
|
|
243
253
|
|
package/package.json
CHANGED
|
@@ -263,9 +263,17 @@ module.exports = function (RED)
|
|
|
263
263
|
|
|
264
264
|
config.links.forEach(link =>
|
|
265
265
|
{
|
|
266
|
+
// console.log(node.id + " -> " + link);
|
|
267
|
+
// console.log({ source: node.id, state: state });
|
|
266
268
|
RED.events.emit("node:" + link, { source: node.id, state: state });
|
|
267
269
|
});
|
|
268
270
|
}
|
|
271
|
+
|
|
272
|
+
// After node red restart, start also the timeout
|
|
273
|
+
if (getCurrentScene() != 0)
|
|
274
|
+
startAutoOffIfNeeded(helper.getTimeInMsFromString(max_time_on));
|
|
275
|
+
|
|
276
|
+
status();
|
|
269
277
|
}
|
|
270
278
|
RED.nodes.registerType("smart_scene-control", SceneControlNode);
|
|
271
279
|
};
|
|
@@ -388,6 +388,8 @@ module.exports = function (RED)
|
|
|
388
388
|
|
|
389
389
|
config.links.forEach(link =>
|
|
390
390
|
{
|
|
391
|
+
// console.log(node.id + " -> " + link);
|
|
392
|
+
// console.log({ source: node.id, state: state });
|
|
391
393
|
RED.events.emit("node:" + link, { source: node.id, state: state });
|
|
392
394
|
});
|
|
393
395
|
};
|
|
@@ -206,6 +206,8 @@ module.exports = function (RED)
|
|
|
206
206
|
|
|
207
207
|
config.links.forEach(link =>
|
|
208
208
|
{
|
|
209
|
+
// console.log(node.id + " -> " + link);
|
|
210
|
+
// console.log({ source: node.id, state: state });
|
|
209
211
|
RED.events.emit("node:" + link, { source: node.id, state: state });
|
|
210
212
|
});
|
|
211
213
|
};
|
package/smart_helper.js
CHANGED
|
@@ -151,6 +151,42 @@ module.exports = {
|
|
|
151
151
|
if (value > 0)
|
|
152
152
|
result = value + "." + result;
|
|
153
153
|
|
|
154
|
+
return result;
|
|
155
|
+
},
|
|
156
|
+
formatDateToStatus(date, timeConcatWord = null)
|
|
157
|
+
{
|
|
158
|
+
let result = "";
|
|
159
|
+
|
|
160
|
+
if (timeConcatWord)
|
|
161
|
+
result = " " + timeConcatWord + " " + date.getHours() + ":" + ("" + date.getMinutes()).padStart(2, "0") + ":" + ("" + date.getSeconds()).padStart(2, "0");
|
|
162
|
+
|
|
163
|
+
let value = date - new Date();
|
|
164
|
+
if (value <= 0)
|
|
165
|
+
return "0:00" + result;
|
|
166
|
+
|
|
167
|
+
// value in sec
|
|
168
|
+
value = parseInt(value / 1000, 10);
|
|
169
|
+
result = (value % 60) + result;
|
|
170
|
+
if (value % 60 < 10)
|
|
171
|
+
result = "0" + result;
|
|
172
|
+
|
|
173
|
+
// value in min
|
|
174
|
+
value = parseInt(value / 60, 10);
|
|
175
|
+
result = (value % 60) + ":" + result;
|
|
176
|
+
if (value % 60 < 10)
|
|
177
|
+
result = "0" + result;
|
|
178
|
+
|
|
179
|
+
// value in hour
|
|
180
|
+
value = parseInt(value / 60, 10);
|
|
181
|
+
result = (value % 24) + ":" + result;
|
|
182
|
+
if (value % 24 < 10)
|
|
183
|
+
result = "0" + result;
|
|
184
|
+
|
|
185
|
+
// value in days
|
|
186
|
+
value = parseInt(value / 24, 10);
|
|
187
|
+
if (value > 0)
|
|
188
|
+
result = value + "." + result;
|
|
189
|
+
|
|
154
190
|
return result;
|
|
155
191
|
}
|
|
156
192
|
};
|
package/text-exec/text-exec.js
CHANGED
|
@@ -286,12 +286,12 @@ module.exports = function (RED)
|
|
|
286
286
|
{
|
|
287
287
|
if (action != null && affectedNodes.length > 0)
|
|
288
288
|
{
|
|
289
|
-
for (const
|
|
289
|
+
for (const targetNode of affectedNodes)
|
|
290
290
|
{
|
|
291
|
-
if (mode == "light" && !["smart_light-control", "smart_scene-control"].includes(
|
|
291
|
+
if (mode == "light" && !["smart_light-control", "smart_scene-control"].includes(targetNode.type))
|
|
292
292
|
continue;
|
|
293
293
|
|
|
294
|
-
if (mode == "shutter" && !["smart_shutter-control", "smart_shutter-complex-control"].includes(
|
|
294
|
+
if (mode == "shutter" && !["smart_shutter-control", "smart_shutter-complex-control"].includes(targetNode.type))
|
|
295
295
|
continue;
|
|
296
296
|
|
|
297
297
|
// node.log("Notify node " + node.id);
|
|
@@ -299,11 +299,17 @@ module.exports = function (RED)
|
|
|
299
299
|
{
|
|
300
300
|
// console.log({ "topic": action, "payload": number });
|
|
301
301
|
if (number != null)
|
|
302
|
-
|
|
302
|
+
{
|
|
303
|
+
// console.log(node.id + " -> " + targetNode.id);
|
|
304
|
+
// console.log({ "topic": action, "payload": number });
|
|
305
|
+
RED.events.emit("node:" + targetNode.id, { "topic": action, "payload": number });
|
|
306
|
+
}
|
|
303
307
|
}
|
|
304
308
|
else
|
|
305
309
|
{
|
|
306
|
-
|
|
310
|
+
// console.log(node.id + " -> " + targetNode.id);
|
|
311
|
+
// console.log({ "topic": action });
|
|
312
|
+
RED.events.emit("node:" + targetNode.id, { "topic": action });
|
|
307
313
|
}
|
|
308
314
|
}
|
|
309
315
|
|