Implement global room configuration for Node-RED integration

- Introduced a single global room configuration file to streamline the management of rooms and lights, reducing redundancy in configuration.
- Updated various integration scripts to utilize the global configuration, enhancing maintainability and clarity.
- Improved documentation to reflect the new configuration approach, including instructions for loading and modifying the room configuration.

This update simplifies the integration process and improves the overall user experience for managing lights and rooms in Node-RED.
This commit is contained in:
2026-02-08 17:49:07 +02:00
parent 714aa84504
commit c049a28c97
7 changed files with 118 additions and 19 deletions

View File

@@ -1,6 +1,9 @@
// Writes to state.rooms.cmd_livingroom (same as HA to NVL). Zigbee action → zigbee_sw1..6.
const ROOM_NAME = 'cmd_livingroom';
// Writes to state.rooms.<roomKey>. Room from Zigbee device via global roomConfig.deviceToRoom. See /root/.node-red/room-config.js.
const actionToSwitch = { single: 1, double: 2, hold: 3, release: 4, triple: 5, quad: 6 };
const config = global.get('roomConfig');
const deviceToRoom = (config && config.deviceToRoom) ? config.deviceToRoom : { 'Office Switch': 'cmd_livingroom' };
const friendlyName = (msg.payload && msg.payload.friendly_name) ? msg.payload.friendly_name : '';
const ROOM_NAME = deviceToRoom[friendlyName] || 'cmd_livingroom';
const payload = msg.payload || {};
const actionRaw = (payload.action || payload.click || '').toLowerCase();
// Support "1_single", "2_double" etc. (button_number + action) or plain "single", "double"
@@ -25,7 +28,7 @@ if (!state.rooms[ROOM_NAME]) state.rooms[ROOM_NAME] = {};
state.rooms[ROOM_NAME]['zigbee_sw' + swIndex] = true;
flow.set('nvlInState', state);
node.warn('[Zigbee to NVL] cmd_livingroom zigbee_sw' + swIndex + '=true (action=' + actionRaw + '), buildAndSend + zigbeeClear');
node.warn('[Zigbee to NVL] ' + ROOM_NAME + ' zigbee_sw' + swIndex + '=true (action=' + actionRaw + '), buildAndSend + zigbeeClear');
msg.payload = { buildAndSend: true };
msg.zigbeeClear = { room: ROOM_NAME, key: 'zigbee_sw' + swIndex };