I am trying to create a flow which uses a node from the module node-red-contrib-knx-ultimate
The flow uses a trigger, a function node, a knx device node and finally another function node.
The first function should Initialize an array to store the knx group addresses.
Where I enter the total number of address to be looped through, lets say 70.
This function should then send a message to the knx device node to read that group address. The knx device node then loops back to the input of the first function to trigger it to read the next group address. It does this until it has looped through the total number of addresses.
The second function is also linked to the output of the knx device node. This function is to create a table which records the group address and the result from the knx read telegram which is a 6 byte value
I have attached an image of the flow.
My code for the first function is below
// Initialize an array of group addresses
let totalAddresses = 5;
let groupAddresses = Array.from({ length: totalAddresses }, (_, i) => `1/1/${i}`);
// Store the current index in flow context (to keep track of progress)
let currentIndex = flow.get('currentIndex') || 0;
// Create a message with necessary information
if (currentIndex < groupAddresses.length) {
msg.payload = {
groupAddress: groupAddresses[currentIndex],
dataType: 'DPT-9.001', // Adjust as needed for your specific data type
controlCommand: 'Read' // Use "Read" for a read request
};
flow.set('currentIndex', currentIndex + 1); // Increment index
return msg;
} else {
// All addresses processed, reset index for next run
flow.set('currentIndex', 0);
}
This code does send the following message on first trigger
{"groupAddress":"1/1/0","dataType":"DPT-9.001","controlCommand":"Read"}
The problem is the KNX Device Node does nothing. I know the node is working because if I enter properties and set a specified group address in the parameters then it works. I assume I have formatted the message incorrectly.
I also know there is an error in my flow that because I have looped the output back from the knx device node to the function node input the cycle will never end so I need a way to stop it after the 70 group addresses.
Im hoping someone knows how to adjust my function code so that the KNX Device node responds and how to stop the loop when it reads the 70th group address
There is most likely a much more efficient way to do this so I am also open to that suggestion.