user29594847
user29594847

Reputation: 1

ThingsBoard per-device alarms, way to fetch multiple shared attributes in rule chains?

I’m currently working on an alarm system proof of concept in ThingsBoard where each device sends telemetry data (metrics) like temperature, humidity in the following Sparkplug like format:

{"timestamp": 1676118000000,"metrics": [{"name": "temperature","value": 23.5,"timestamp": 1676118000000,"dataType": "FLOAT",},{"name": "humidity","value": 60.3,"timestamp": 1676118000000,"dataType": "FLOAT",}]}

Users must be able to dynamically create per device alarms on any metric and be able to specify a threshold (all actions will be performed by an external React based app which communicates with Thingsboard REST API). From my understanding the only way is to create shared attributes for each metric's alarm, like "shared_temperature", "shared_humidity", etc. These shared attributes store the threshold value for triggering alarms and ThingsBoard evaluates the incoming telemetry data against these thresholds and triggers alarms if the conditions are met.

thingsboard rule chain

The current rule chain to do the above is as follows:

  1. a "transform script" node (get-shared-attribute) which creates for each incoming metric a comma separated list of shared attributes stored inside the outgoing metadata message in a variable attributeList.
  2. an "originator attribute" node (get-originator-attributes) which gets the potentially stored shared attributes with the template ${attributeList} to extract the shared attributes values from the metadata. This template does not recognize a comma separated list of shared attribute names (shared_temperature,shared_humidity) but only a single "shared_humidity".
  3. a "transform script" node (process-telemetry) which checks the metric value with its threshold value and sends success to the next create-alarm node
  4. the create-alarm node which raises the alarm

Now the question:

  1. is there a better approach for creating per device alarms dynamically (metric name and threshold not known in advance)?
  2. how to fetch multiple shared attributes with custom names in the rule engine?

Upvotes: 0

Views: 25

Answers (0)

Related Questions