@haydendonald/node-red-contrib-hass-stuff 1.2.7 → 1.2.9

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.
@@ -329,54 +329,62 @@ module.exports = function LightControlConfigNode(RED) {
329
329
  }
330
330
  };
331
331
  const runAdaptive = (transitionSec, turnLightsOn, forceSend) => {
332
- let entitiesOn;
333
- let entitiesOff;
334
- //Decide what scene to send
335
- let scene = scenes["concentrate"];
336
- if (nightModeState === "on") {
337
- scene = scenes["night"];
338
- entitiesOn = entitiesOnDuringNight;
339
- entitiesOff = entitiesOffDuringNight;
340
- }
341
- else {
342
- if (sunState == "above_horizon") {
343
- scene = scenes["concentrate"];
332
+ function run(transitionSec, turnLightsOn, forceSend) {
333
+ let entitiesOn;
334
+ let entitiesOff;
335
+ //Decide what scene to send
336
+ let scene = scenes["concentrate"];
337
+ if (nightModeState === "on") {
338
+ scene = scenes["night"];
339
+ entitiesOn = entitiesOnDuringNight;
340
+ entitiesOff = entitiesOffDuringNight;
344
341
  }
345
342
  else {
346
- const currentHour = new Date().getHours();
347
- if (currentHour >= 23 || currentHour < 6) {
348
- scene = scenes["nightLight"];
349
- }
350
- else if (currentHour >= 6 && currentHour < 7) {
351
- scene = scenes["rest"];
352
- }
353
- else if (currentHour >= 7 && currentHour < 8) {
354
- scene = scenes["relax"];
355
- }
356
- else if (currentHour >= 8 && currentHour < 10) {
357
- scene = scenes["read"];
358
- }
359
- else if (currentHour >= 10 && currentHour < 15) {
343
+ if (sunState == "above_horizon") {
360
344
  scene = scenes["concentrate"];
361
345
  }
362
- else if (currentHour >= 15 && currentHour < 19) {
363
- scene = scenes["read"];
364
- }
365
- else if (currentHour >= 19 && currentHour < 22) {
366
- scene = scenes["relax"];
367
- }
368
- else if (currentHour >= 22 && currentHour < 23) {
369
- scene = scenes["rest"];
346
+ else {
347
+ const currentHour = new Date().getHours();
348
+ if (currentHour >= 23 || currentHour < 6) {
349
+ scene = scenes["nightLight"];
350
+ }
351
+ else if (currentHour >= 6 && currentHour < 7) {
352
+ scene = scenes["rest"];
353
+ }
354
+ else if (currentHour >= 7 && currentHour < 8) {
355
+ scene = scenes["relax"];
356
+ }
357
+ else if (currentHour >= 8 && currentHour < 10) {
358
+ scene = scenes["read"];
359
+ }
360
+ else if (currentHour >= 10 && currentHour < 15) {
361
+ scene = scenes["concentrate"];
362
+ }
363
+ else if (currentHour >= 15 && currentHour < 19) {
364
+ scene = scenes["read"];
365
+ }
366
+ else if (currentHour >= 19 && currentHour < 22) {
367
+ scene = scenes["relax"];
368
+ }
369
+ else if (currentHour >= 22 && currentHour < 23) {
370
+ scene = scenes["rest"];
371
+ }
370
372
  }
371
373
  }
374
+ //Send it
375
+ activateScene(scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff, forceSend);
372
376
  }
373
- //Send it
374
- activateScene(scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff, forceSend);
377
+ run(transitionSec, turnLightsOn, forceSend);
375
378
  //Start our interval to update the adaptive scene every minute
376
- clearTimeout(adaptiveInterval);
377
- adaptiveInterval = setTimeout(() => {
378
- runAdaptive(300, false, true);
379
- }, 300000);
379
+ const runAdaptiveInterval = () => {
380
+ clearTimeout(adaptiveInterval);
381
+ if (currentSceneState == "Adaptive") {
382
+ run(300, false, true);
383
+ }
384
+ //Reschedule
385
+ adaptiveInterval = setTimeout(runAdaptiveInterval, 1000);
386
+ };
387
+ runAdaptiveInterval();
380
388
  };
381
389
  };
382
390
  RED.nodes.registerType("light-control-config-node", register);
@@ -9,8 +9,15 @@ module.exports = function PIRControlConfigNode(RED) {
9
9
  let enabledState;
10
10
  let detectedTimeout;
11
11
  let notDetectedTimeout;
12
+ let sentOnState = false;
12
13
  RED.nodes.createNode(this, config);
13
14
  (0, baseConfigNode_1.assignBaseConfigNode)(this);
15
+ //When NodeRED redeploys
16
+ self.on("close", function (done) {
17
+ clearTimeout(detectedTimeout);
18
+ clearTimeout(notDetectedTimeout);
19
+ done();
20
+ });
14
21
  const connectionsConfigNode = RED.nodes.getNode(config.connectionsConfigNode);
15
22
  let errored = false;
16
23
  if (!config.connectionsConfigNode || !connectionsConfigNode) {
@@ -73,11 +80,11 @@ module.exports = function PIRControlConfigNode(RED) {
73
80
  return;
74
81
  }
75
82
  //Don't do anything if the luminance is not enough
76
- if (config.minBrightnessLevel && parseInt(luminanceState.state) < parseInt(config.minBrightnessLevel)) {
83
+ if (sentOnState == false && config.minBrightnessLevel && parseInt(luminanceState.state) < parseInt(config.minBrightnessLevel)) {
77
84
  return;
78
85
  }
79
86
  //Don't do anything if the luminance is too much
80
- if (config.maxBrightnessLevel && parseInt(luminanceState.state) > parseInt(config.maxBrightnessLevel)) {
87
+ if (sentOnState == false && config.maxBrightnessLevel && parseInt(luminanceState.state) > parseInt(config.maxBrightnessLevel)) {
81
88
  return;
82
89
  }
83
90
  const msg = {
@@ -113,9 +120,11 @@ module.exports = function PIRControlConfigNode(RED) {
113
120
  }
114
121
  }
115
122
  function sendDetectedMsg(msg) {
123
+ sentOnState = true;
116
124
  self.sendMsg([msg]);
117
125
  }
118
126
  function sendNotDetectedMsg(msg) {
127
+ sentOnState = false;
119
128
  self.sendMsg([undefined, msg]);
120
129
  }
121
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haydendonald/node-red-contrib-hass-stuff",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "A collection of stuff I use on my Node Red + Home Assistant server. This could be of use for others, i don't know..",
5
5
  "devDependencies": {
6
6
  "@types/node": "^18.14.0",