Hello everyone,
We were recently asked how an Open Source Rule can address a case of repeating fields such as ZigBee Home Automation Attributes.
A ‘normal’ field in a message appears only once.
The Network Layer Frame Type appears only once in a message.
Therefore in an Open Source Rule we can access this field by using:
packet.Field(“NwlHeaderFctlFrameType”).Value (or any other desired property of the field such as meaning, hint etc.).
However, some fields may be included in a message more than once.
For example, the following message is ZigBee Home Automation Shade Cluster – Read Attribute Response.
It holds 3 attributes: Physical Closed Limit (PCL), Motor Step Size (MSS) and Closed Limit (CL).
Assume that we want to see if a message contains the Closed Limit attribute, and if it does, see what its value is.
Using the packet.Field(“ProfileCmdAttributeId”).Meaning will not work in this case, because this variable can hold only one out of the three attributes.
In this case what we need to do is the following:
The variable packet.Field(“ProfileCmdAttributeId”).Meanings hold a list of three elements (for this example) with the values “PCL”, “MSS” and “CL”.
We should add this into a List<string> variable,
List<string> attributeIds = packet.Field( “ProfileCmdAttributeId”).Meanings;
we can also store all attributes values in another list
List<long> attributeValues = packet.Field(“ProfileCmdAttributeDataValue).Values;
And see if any of its elements contain the attribute we are looking for:
if (attributeIds .Contains(“CL”))
If it does, we need to find the relevant attribute number:
int value = (int)attributeValues[attributeIds.IndexOf(“CL”)];