@haydendonald/node-red-contrib-hass-stuff 1.2.0 → 1.2.1

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/README.md CHANGED
@@ -502,12 +502,12 @@ A node that controls lights with general scenes that adjust throughout the day w
502
502
 
503
503
  ### Features
504
504
  * Adaptive scenes depending on what time of the day it is
505
- * Adaptive scenes depending on luminance sensor *TODO*
505
+ * Adaptive scenes depending on luminance sensor
506
506
  * Night mode entity to force the adaptive scene to be in "night mode"
507
507
  * Ability to turn off entities in night mode
508
508
 
509
509
  ### Dependencies
510
- 1. [Adaptive Lighting](https://github.com/basnijholt/adaptive-lighting)
510
+ 1. [Hue Scene Presets](https://github.com/Hypfer/hass-scene_presets)
511
511
  2. [HASS Sun](https://www.home-assistant.io/integrations/sun/)
512
512
 
513
513
  ## PIR
@@ -53,7 +53,7 @@
53
53
  <p>
54
54
  The following settings define what the scenes should do. They follow the syntax of [scene] [brightnessPercent]
55
55
  where scene is the scene name, if the same as below values will use the
56
- <a style="font-weight: bold;" href="https://github.com/basnijholt/adaptive-lighting">Adaptive Lighting HACS plugin</a>
56
+ <a style="font-weight: bold;" href="https://github.com/Hypfer/hass-scene_presets">Hue Scene Presets HACS plugin</a>
57
57
  otherwise will send to scene.apply. The brightnessPercent is the brightness percentage to set
58
58
  </p>
59
59
  <ul>
@@ -106,4 +106,19 @@
106
106
  </script>
107
107
 
108
108
  <script type="text/html" data-help-name="light-control-config-node">
109
+ <p>A node that controls lights with general scenes that adjust throughout the day with sleep mode and other features.</p>
110
+
111
+ <h2>Features</h2>
112
+ <ul>
113
+ <li>Adaptive scenes depending on what time of the day it is</li>
114
+ <li>Adaptive scenes depending on luminance sensor</li>
115
+ <li>Night mode entity to force the adaptive scene to be in "night mode"</li>
116
+ <li>Ability to turn off entities in night mode</li>
117
+ </ul>
118
+
119
+ <h2>Dependencies</h2>
120
+ <ul>
121
+ <li><a href="https://github.com/Hypfer/hass-scene_presets" target="_blank">Hue Scene Presets</a></li>
122
+ <li><a href="https://www.home-assistant.io/integrations/sun/" target="_blank">Sun Integration</a></li>
123
+ </ul>
109
124
  </script>
@@ -10,6 +10,7 @@ module.exports = function LightControlConfigNode(RED) {
10
10
  let nightModeState;
11
11
  let currentSceneState;
12
12
  let sunState;
13
+ let lastSentScene;
13
14
  let entitiesOnDuringNight = [];
14
15
  let entitiesOffDuringNight = [];
15
16
  let adaptiveInterval;
@@ -229,11 +230,16 @@ module.exports = function LightControlConfigNode(RED) {
229
230
  };
230
231
  //When we get a message from a node on the NodeRED flows
231
232
  this.msgReceived = function (msg, senderIds) { };
232
- const activateScene = (scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff) => {
233
+ const activateScene = (scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff, forceSend) => {
233
234
  //If the lights are off and we are not to turn the lights on don't do anything
234
235
  if (turnLightsOn == false && currentState.state == "off") {
235
236
  return;
236
237
  }
238
+ //Don't send the same scene again
239
+ if (forceSend != true && scene.sceneName == lastSentScene) {
240
+ return;
241
+ }
242
+ lastSentScene = scene.sceneName;
237
243
  //Is not a scene preset scene if we have a entity id
238
244
  if (scene.sceneName.includes(".")) {
239
245
  //Run via hass scene.turn_on
@@ -242,6 +248,14 @@ module.exports = function LightControlConfigNode(RED) {
242
248
  }, {
243
249
  transition: transitionSec
244
250
  });
251
+ //Send to the node output
252
+ self.sendMsg({
253
+ topic: "sceneSent",
254
+ payload: {
255
+ scene,
256
+ transitionSec
257
+ }
258
+ });
245
259
  }
246
260
  //Is a scene preset
247
261
  else {
@@ -250,8 +264,7 @@ module.exports = function LightControlConfigNode(RED) {
250
264
  self.error(`Scene preset not found for ${scene.sceneName}. Please use scene.<presetname> if this is not a scene i know about`);
251
265
  return;
252
266
  }
253
- //Run via adaptive lights
254
- connectionsConfigNode.sendHASSAction("scene_presets.apply_preset", undefined, {
267
+ const msg = {
255
268
  brightness: (scene.brightnessPct / 100.0) * 255,
256
269
  transition: transitionSec,
257
270
  preset_id: sceneId,
@@ -260,7 +273,9 @@ module.exports = function LightControlConfigNode(RED) {
260
273
  targets: {
261
274
  entity_id: entitiesOn ? entitiesOn : [config.groupEntityId]
262
275
  }
263
- }, undefined);
276
+ };
277
+ //Run via adaptive lights
278
+ connectionsConfigNode.sendHASSAction("scene_presets.apply_preset", undefined, msg, undefined);
264
279
  //Run any lights off that need to be off
265
280
  if (entitiesOff && entitiesOff.length > 0) {
266
281
  connectionsConfigNode.sendHASSAction("light.turn_off", {
@@ -269,6 +284,14 @@ module.exports = function LightControlConfigNode(RED) {
269
284
  transition: transitionSec
270
285
  });
271
286
  }
287
+ //Send to the node output
288
+ self.sendMsg({
289
+ topic: "sceneSent",
290
+ payload: {
291
+ scene,
292
+ transitionSec
293
+ }
294
+ });
272
295
  }
273
296
  };
274
297
  const runLights = (transitionSec, turnLightsOn) => {
@@ -284,7 +307,7 @@ module.exports = function LightControlConfigNode(RED) {
284
307
  activateScene(scene, transitionSec, turnLightsOn);
285
308
  }
286
309
  };
287
- const runAdaptive = (transitionSec, turnLightsOn) => {
310
+ const runAdaptive = (transitionSec, turnLightsOn, forceSend) => {
288
311
  let entitiesOn;
289
312
  let entitiesOff;
290
313
  //Decide what scene to send
@@ -327,12 +350,12 @@ module.exports = function LightControlConfigNode(RED) {
327
350
  }
328
351
  }
329
352
  //Send it
330
- activateScene(scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff);
353
+ activateScene(scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff, forceSend);
331
354
  //Start our interval to update the adaptive scene every minute
332
355
  clearTimeout(adaptiveInterval);
333
356
  adaptiveInterval = setTimeout(() => {
334
- runAdaptive(300, false);
335
- }, 60000);
357
+ runAdaptive(300, false, true);
358
+ }, 300000);
336
359
  };
337
360
  };
338
361
  RED.nodes.registerType("light-control-config-node", register);
@@ -2,7 +2,7 @@
2
2
  RED.nodes.registerType("light-control-node", {
3
3
  category: "HASS Stuff",
4
4
  color: "#ffcc00",
5
- inputs: 1,
5
+ inputs: 0,
6
6
  outputs: 1,
7
7
  icon: "bulb.svg",
8
8
  paletteLabel: "Light Control",
@@ -28,4 +28,36 @@
28
28
  </div>
29
29
  </script>
30
30
  <script type="text/html" data-help-name="light-control-node">
31
+ <p>A node that controls lights with general scenes that adjust throughout the day with sleep mode and other features.</p>
32
+
33
+ <h2>Features</h2>
34
+ <ul>
35
+ <li>Adaptive scenes depending on what time of the day it is</li>
36
+ <li>Adaptive scenes depending on luminance sensor</li>
37
+ <li>Night mode entity to force the adaptive scene to be in "night mode"</li>
38
+ <li>Ability to turn off entities in night mode</li>
39
+ </ul>
40
+
41
+ <h2>Dependencies</h2>
42
+ <ul>
43
+ <li><a href="https://github.com/Hypfer/hass-scene_presets" target="_blank">Hue Scene Presets</a></li>
44
+ <li><a href="https://www.home-assistant.io/integrations/sun/" target="_blank">Sun Integration</a></li>
45
+ </ul>
46
+
47
+ <h2>Output</h2>
48
+ <p>This node can output the following messages</p>
49
+ <ul>
50
+ <li>Scene Sent - A scene has been sent to the lights</li>
51
+ <pre><code>
52
+ {
53
+ topic: "sceneSent",
54
+ payload: {
55
+ friendlyName: "Concentrate",
56
+ sceneName: "sunFlare",
57
+ brightnessPct: 100
58
+ }
59
+ }
60
+ </code></pre>
61
+ </ul>
62
+
31
63
  </script>
@@ -9,10 +9,6 @@ module.exports = function LightControlNode(RED) {
9
9
  lightControlConfigNode.addMsgCallback(this.id, (msg) => {
10
10
  this.send(msg);
11
11
  });
12
- //When an input message is received
13
- this.on("input", (msg, send, done) => {
14
- lightControlConfigNode.msgReceived(msg, [this.id]);
15
- });
16
12
  }
17
13
  RED.nodes.registerType("light-control-node", register);
18
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haydendonald/node-red-contrib-hass-stuff",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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",