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

@@ -116,25 +116,28 @@ const lightNum = parseInt((name.match(/_(\d+)$/) || [,'1'])[1], 10) || 1;
Then set `state.rooms[roomKey]['ha_l' + lightNum + '_on']` or `_off` as you do now. So one HA to NVL function can serve all entities if you pass the right `msg.topic` and use a consistent naming (e.g. `room_light_N`).
### 3.3 Zigbee → PLC: which room?
### 3.3 Zigbee → PLC: which light does each button control?
- Each **zigbee2mqtt-in** is one physical switch.
- **Zigbee to NVL** must know which **room** that switch belongs to.
- Either: **one Zigbee to NVL per room** (each has `ROOM_NAME = 'kitchen'` etc.) and wire each switch to the right one, or **one Zigbee to NVL** that gets **device/entity** from `msg` and uses a **device → room** map (e.g. `friendly_name` or `device_id` → room key).
Each **button** (1..6) is mapped to a specific **(room, light)** so e.g. Office switch button 1 → cmd_livingroom light 1, button 2 → cmd_out light 2. Config is in **room-config.js****`switchBindings`**:
Example map in Zigbee to NVL:
- Key: Zigbee device **friendly_name**.
- Value: object mapping **button index** (1..6) to **`{ room, light }`** or to an array **`[ { room, light }, ... ]`** (one button can control several lights).
- The PLC receives `zigbee_sw<light>` set in the given **room** for each target.
**Example in `room-config.js`:**
```javascript
const DEVICE_TO_ROOM = {
'Living Room Door Switch': 'livingRoom',
'Office Switch': 'livingRoom', // or 'office' if you add that room
'Kitchen Switch': 'kitchen',
// ...
};
const roomKey = DEVICE_TO_ROOM[msg.payload?.friendly_name || ''] || 'livingRoom';
switchBindings: {
'Office Switch': {
1: { room: 'cmd_livingroom', light: 1 }, // button 1 → light 1 in cmd_livingroom
2: { room: 'cmd_out', light: 2 }, // button 2 → light 2 in cmd_out
// One button, multiple lights:
// 3: [ { room: 'kitchen', light: 1 }, { room: 'hallway', light: 1 } ],
},
},
```
Then use `roomKey` instead of a fixed `ROOM_NAME` when writing to `state.rooms[roomKey]`.
Add every **room** you use (e.g. `cmd_out`) to **`roomNames`** so NVL SEND includes it. If a device has no `switchBindings` entry, Zigbee to NVL falls back to **`deviceToRoom`** and uses the button index as the light number in that single room. Use **[clear-zigbee-edge.js](clear-zigbee-edge.js)** in the Clear zigbee edge node so it supports an array of `{ room, key }` (multi-target).
### 3.4 PLC → HA: NVL to HA Sync (LIGHT_ENTITY_MAP)
@@ -263,7 +266,7 @@ Use a **consistent pattern** so you can derive room + light in Node-RED and in Y
| 2 | **HA** | Create all entities (YAML package or UI). Use a clear naming scheme (e.g. `room_light_N`). |
| 3 | **Node-RED NVL SEND** | Set **`roomNames`** in `state-to-nvl-send-payload.js` to the full list of room keys (same order as PLC). |
| 4 | **Node-RED HA to NVL** | Either duplicate the flow per room (Option A) or use one flow and derive **room + light** from `msg.topic` (Option B). Ensure every HA entity is mapped to a room key and light index. |
| 5 | **Node-RED Zigbee to NVL** | Map each Zigbee device (by name or id) to a **room key** so the correct `state.rooms[roomKey]` is updated. |
| 5 | **Node-RED Zigbee to NVL** | In **room-config.js** set **switchBindings** (device → button → `{ room, light }` or array) so each button controls the right room+light; add those rooms to **roomNames**. Use **clear-zigbee-edge.js** for the 80 ms clear. |
| 6 | **Node-RED NVL to HA Sync** | Fill **LIGHT_ENTITY_MAP** with one entry per light: `room` (payload key from nvl-receive), `light` (1..6), `entityId` (HA entity). |
| 7 | **Action nodes** | Keep one Action node (or two for on/off) with **Block Input Overrides** off so the syncs `payload.action` and `payload.target.entity_id` are used for all entities. |