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

@@ -0,0 +1,13 @@
// Paste this into a Function node named "Load room config".
// Connect an Inject node (once after 0.5 s) to it so it runs at startup.
//
// Since functionExternalModules is true in settings.js, you can require files.
// room-config.js must be on the Node-RED server at /root/.node-red/room-config.js
// Delete cached version so changes to the file are picked up on redeploy
delete require.cache[require.resolve('/root/.node-red/room-config.js')];
const ROOM_CONFIG = require('/root/.node-red/room-config.js');
global.set('roomConfig', ROOM_CONFIG);
node.warn('[Load room config] loaded: ' + ROOM_CONFIG.roomNames.length + ' rooms, ' + ROOM_CONFIG.lightEntityMap.length + ' light mappings');
return null;

69
node-red/room-config.js Normal file
View File

@@ -0,0 +1,69 @@
/**
* Single source of truth for rooms and lights.
* Lives on the Node-RED server at /root/.node-red/room-config.js
* All function nodes use: global.get('roomConfig')
* Loaded at startup by room-config-loader.js (Function node + Inject once).
*
* When you add a room or light, edit ONLY this file, upload to the server, and restart Node-RED (or redeploy).
*/
const ROOM_CONFIG = {
// Order must match CODESYS NVL_In. Used by NVL SEND (state-to-nvl-send-payload).
roomNames: [
'cmd_livingroom', // test slot — replace with 'livingRoom' when moving to production
'masterBedroom',
'masterBathroom',
'bedroom_1',
'bedroom_2',
'bathroom',
'guestWc',
'kitchen',
'pantry',
'livingRoom',
'dinningRoom',
'entrance',
'hallway',
'outVeranda',
'outFront',
'outBack',
'outSide',
],
// PLC → HA sync. room = key in nvl-receive payload, light = 1..6, entityId = HA entity.
lightEntityMap: [
{ room: 'light_livingRoom', light: 1, entityId: 'input_boolean.living_room_new' },
// { room: 'light_livingRoom', light: 2, entityId: 'input_boolean.living_room_2' },
// { room: 'l_kitchen', light: 1, entityId: 'input_boolean.kitchen_1' },
],
// HA entity_id substring (after domain.) without trailing _N → NVL room key. For HA to NVL.
entityToRoom: {
living_room: 'livingRoom',
living_room_new: 'cmd_livingroom',
kitchen: 'kitchen',
master_bedroom: 'masterBedroom',
bathroom: 'bathroom',
bedroom_1: 'bedroom_1',
bedroom_2: 'bedroom_2',
dinning_room: 'dinningRoom',
entrance: 'entrance',
hallway: 'hallway',
pantry: 'pantry',
guest_wc: 'guestWc',
out_veranda: 'outVeranda',
out_front: 'outFront',
out_back: 'outBack',
out_side: 'outSide',
},
// Zigbee device friendly_name → NVL room key. For Zigbee to NVL.
deviceToRoom: {
'Living Room Door Switch': 'livingRoom',
'Office Switch': 'cmd_livingroom',
'Kitchen Switch': 'kitchen',
'Master Bedroom Switch': 'masterBedroom',
// Add each Zigbee switch friendly_name and the room key it controls.
},
};
module.exports = ROOM_CONFIG;