node-red-contrib-knx-ultimate 2.2.34 → 2.2.36

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 CHANGED
@@ -6,6 +6,12 @@
6
6
 
7
7
  # CHANGELOG
8
8
 
9
+ **Version 2.2.36** - December 2023<br/>
10
+ - HUE Light Node: Ensure at least one liht belonging to a group was on before switching to nighttime. Otherwise turn all lights on at daytime.<br/>
11
+
12
+ **Version 2.2.35** - December 2023<br/>
13
+ - NEW: HUE Light Node: now it resumes the old status of all lights belonging to the selected group.<br/>
14
+
9
15
  **Version 2.2.34** - December 2023<br/>
10
16
  - NEW: HUE Light Node: there is a new tab that auto-generates the light entity for Home Assistant.<br/>
11
17
  - HUE Light: resuming the last daytime status after nighttime, if the switch on behaviour at daytime is set to None.<br/>
@@ -242,6 +242,32 @@ module.exports = (RED) => {
242
242
  } catch (error) { }
243
243
  };
244
244
 
245
+ // Return an array of light belonging to the groupID
246
+ node.getAllLightsBelongingToTheGroup = async function getAllLightsBelongingToTheGroup(_groupID) {
247
+ if (node.hueAllResources === undefined || node.hueAllResources === null) return;
248
+ const retArr = [];
249
+ try {
250
+ await node.loadResourcesFromHUEBridge();
251
+ node.hueAllResources.forEach((res) => {
252
+ if (res.services !== undefined && res.services.length > 0) {
253
+ res.services.forEach((serv) => {
254
+ if (serv.rid === _groupID) {
255
+ if (res.children !== undefined) {
256
+ const children = res.children.filter((a) => a.rtype === "light");
257
+ for (let index = 0; index < children.length; index++) {
258
+ const element = children[index];
259
+ const oLight = node.hueAllResources.filter((a) => a.id === element.rid);
260
+ if (oLight !== null && oLight !== undefined) retArr.push({ groupID: _groupID, light: oLight });
261
+ }
262
+ }
263
+ }
264
+ });
265
+ }
266
+ });
267
+ return retArr;
268
+ } catch (error) { /* empty */ }
269
+ };
270
+
245
271
  // Returns the cached devices (node.hueAllResources) by type.
246
272
  node.getResources = function getResources(_rtype) {
247
273
  try {
@@ -34,6 +34,7 @@ module.exports = function (RED) {
34
34
  node.formatdecimalsvalue = 2;
35
35
  node.currentHUEDevice = undefined; // At start, this value is filled by a call to HUE api. It stores a value representing the current light status.
36
36
  node.HUEDeviceWhileDaytime = null;// This retains the HUE device status while daytime, to be restored after nighttime elapsed.
37
+ node.HUELightsBelongingToGroupWhileDaytime = null; // Array contains all light belonging to the grouped_light (if grouped_light is selected)
37
38
  node.DayTime = true;
38
39
  node.isGrouped_light = config.hueDevice.split("#")[1] === "grouped_light";
39
40
  node.hueDevice = config.hueDevice.split("#")[0];
@@ -107,11 +108,49 @@ module.exports = function (RED) {
107
108
  // If you try and control multiple conflicting parameters at once e.g. {"color": {"xy": {"x":0.5,"y":0.5}}, "color_temperature": {"mirek": 250}}
108
109
  // the lights can only physically do one, for this we apply the rule that xy beats ct. Simple.
109
110
  // color_temperature.mirek: color temperature in mirek is null when the light color is not in the ct spectrum
110
- if (node.DayTime === true && config.specifySwitchOnBrightness === "no" && node.HUEDeviceWhileDaytime !== null) {
111
- // The DayNight has switched into day, so restore the previous light status
112
- state = { on: { on: true }, dimming: node.HUEDeviceWhileDaytime.dimming, color: node.HUEDeviceWhileDaytime.color, color_temperature: node.HUEDeviceWhileDaytime.color_temperature };
113
- if (node.HUEDeviceWhileDaytime.color_temperature.mirek === null) delete state.color_temperature; // Otherwise the lamp will not turn on due to an error. color_temperature.mirek: color temperature in mirek is null when the light color is not in the ct spectrum
114
- node.HUEDeviceWhileDaytime = null; // Nullize the object.
111
+ if ((node.DayTime === true && config.specifySwitchOnBrightness === "no") && ((node.isGrouped_light === false && node.HUEDeviceWhileDaytime !== null) || (node.isGrouped_light === true && node.HUELightsBelongingToGroupWhileDaytime !== null))) {
112
+ if (node.isGrouped_light === false && node.HUEDeviceWhileDaytime !== null) {
113
+ // The DayNight has switched into day, so restore the previous light status
114
+ state = { on: { on: true }, dimming: node.HUEDeviceWhileDaytime.dimming, color: node.HUEDeviceWhileDaytime.color, color_temperature: node.HUEDeviceWhileDaytime.color_temperature };
115
+ if (node.HUEDeviceWhileDaytime.color_temperature.mirek === null) delete state.color_temperature; // Otherwise the lamp will not turn on due to an error. color_temperature.mirek: color temperature in mirek is null when the light color is not in the ct spectrum
116
+ node.serverHue.hueManager.writeHueQueueAdd(node.hueDevice, state, node.isGrouped_light === false ? "setLight" : "setGroupedLight");
117
+ node.setNodeStatusHue({
118
+ fill: "green",
119
+ shape: "dot",
120
+ text: "KNX->HUE",
121
+ payload: "Restore light status",
122
+ });
123
+ node.HUEDeviceWhileDaytime = null; // Nullize the object.
124
+ } else if (node.isGrouped_light === true && node.HUELightsBelongingToGroupWhileDaytime !== null) {
125
+ // The DayNight has switched into day, so restore the previous light state, belonging to the group
126
+ let bAtLeastOneIsOn = false;
127
+ for (let index = 0; index < node.HUELightsBelongingToGroupWhileDaytime.length; index++) { // Ensure, at least 1 lamp was on, otherwise turn all lamps on
128
+ const element = node.HUELightsBelongingToGroupWhileDaytime[index].light[0];
129
+ if (element.on.on === true) {
130
+ bAtLeastOneIsOn = true;
131
+ break;
132
+ }
133
+ }
134
+ for (let index = 0; index < node.HUELightsBelongingToGroupWhileDaytime.length; index++) {
135
+ const element = node.HUELightsBelongingToGroupWhileDaytime[index].light[0];
136
+ if (bAtLeastOneIsOn === true) {
137
+ state = { on: element.on, dimming: element.dimming, color: element.color, color_temperature: element.color_temperature };
138
+ } else {
139
+ // Failsafe all on
140
+ state = { on: { on: true }, dimming: element.dimming, color: element.color, color_temperature: element.color_temperature };
141
+ }
142
+ if (element.color_temperature.mirek === null) delete state.color_temperature; // Otherwise the lamp will not turn on due to an error. color_temperature.mirek: color temperature in mirek is null when the light color is not in the ct spectrum
143
+ node.serverHue.hueManager.writeHueQueueAdd(element.id, state, "setLight");
144
+ }
145
+ node.setNodeStatusHue({
146
+ fill: "green",
147
+ shape: "dot",
148
+ text: "KNX->HUE",
149
+ payload: "Resuming all group's light",
150
+ });
151
+ node.HUELightsBelongingToGroupWhileDaytime = null; // Nullize the object.
152
+ return;
153
+ }
115
154
  } else {
116
155
  let colorChoosen;
117
156
  let temperatureChoosen;
@@ -219,11 +258,19 @@ module.exports = function (RED) {
219
258
  if (config.specifySwitchOnBrightness === "no") {
220
259
  // This retains the HUE device status while daytime, to be restored after nighttime elapsed. https://github.com/Supergiovane/node-red-contrib-knx-ultimate/issues/298
221
260
  if (node.DayTime === false) {
222
- // DayTime has switched to false: save the currentHUEDevice into the HUEDeviceWhileDaytime
223
- node.HUEDeviceWhileDaytime = cloneDeep(node.currentHUEDevice);
261
+ if (node.isGrouped_light === false) node.HUEDeviceWhileDaytime = cloneDeep(node.currentHUEDevice); // DayTime has switched to false: save the currentHUEDevice into the HUEDeviceWhileDaytime
262
+ if (node.isGrouped_light === true) {
263
+ (async () => {
264
+ try {
265
+ const retLights = await node.serverHue.getAllLightsBelongingToTheGroup(node.hueDevice);
266
+ node.HUELightsBelongingToGroupWhileDaytime = cloneDeep(retLights); // DayTime has switched to false: save the lights belonging to the group into the HUELightsBelongingToGroupWhileDaytime array
267
+ } catch (error) { }
268
+ })();
269
+ }
224
270
  }
225
271
  } else {
226
272
  node.HUEDeviceWhileDaytime = null;
273
+ node.HUELightsBelongingToGroupWhileDaytime = null;
227
274
  }
228
275
  node.setNodeStatusHue({
229
276
  fill: "green",
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "engines": {
4
4
  "node": ">=16.0.0"
5
5
  },
6
- "version": "2.2.34",
6
+ "version": "2.2.36",
7
7
  "description": "Control your KNX intallation via Node-Red! A bunch of KNX nodes, with integrated Philips HUE control and ETS group address importer. Easy to use and highly configurable.",
8
8
  "dependencies": {
9
9
  "binary-parser": "2.2.1",