Enhance Zigbee to NVL integration with button mapping and configuration updates

- Updated documentation to clarify the mapping of Zigbee buttons to specific (room, light) pairs using `switchBindings`.
- Improved the Zigbee to NVL function to support both single-device and multi-device payloads, enhancing flexibility in handling actions.
- Revised the room configuration to include detailed switch bindings and fallback mechanisms for device identification, streamlining the integration process.

This update improves the usability and functionality of the Zigbee integration within Node-RED, facilitating better control of lighting systems.
This commit is contained in:
2026-02-08 22:30:19 +02:00
parent c049a28c97
commit d64d0f8923
10 changed files with 396 additions and 87 deletions

View File

@@ -2,31 +2,31 @@
* 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).
* Loaded at startup from settings.js (functionGlobalContext). To reload without restart, use the
* "Reload room config" flow: see node-red/reload-room-config-docs.md
*/
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',
'cmd_livingroom',
'cmd_out', // add other NVL room keys as needed
// '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.
@@ -38,31 +38,49 @@ const ROOM_CONFIG = {
// HA entity_id substring (after domain.) without trailing _N → NVL room key. For HA to NVL.
entityToRoom: {
living_room: 'livingRoom',
// 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',
// 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.
// Zigbee: friendly_name → single room (fallback when switchBindings missing).
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.
},
// When using a multi-device Zigbee node, payload is keyed by IEEE (e.g. 0xa4c138a5b9771b05). Map IEEE → friendly name so switchBindings by name still works.
deviceIdToName: {
// '0xa4c138a5b9771b05': 'Office Switch', // uncomment and add your device IEEE from the payload
},
// Optional: bind by IEEE instead of friendly name (same shape as switchBindings). Use if the node never sends friendly_name.
// switchBindingsByDeviceId: {
// '0xa4c138a5b9771b05': { 1: { room: 'cmd_livingroom', light: 1 }, 2: { room: 'cmd_out', light: 2 } },
// },
/**
* Which (room, light) each physical button controls. Key = button number (1..6), value = { room, light }.
* Button and light are independent: e.g. button 2 can control light 1, or light 2 in another room.
* One button can target one { room, light } or an array for multiple lights.
*/
switchBindings: {
'Office Switch': {
1: { room: 'cmd_livingroom', light: 1 }, // button 1 → light 1
2: { room: 'cmd_livingroom', light: 1 }, // button 2 → light 1 (same light; other switches could do button 2 → light 2)
},
},
};