@haydendonald/node-red-contrib-hass-stuff 1.2.8 → 1.3.0

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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haydendonald/node-red-contrib-hass-stuff",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
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",