Rule scripts

If the "Use script" option is checked when defining a rule, the user can enter his own code for the function that will be executed within the rule. The Python language function must be named checkRule, take no arguments and return a value of string type.

def checkRule(): return """

Documentation for the programmer: Implementation of the checkRule function

Purpose of the function

The checkRule function is the main place to implement the logic for checking alarm conditions or rules for an IoT device in Signomix Sentinel. This function should use the provided tools to retrieve the measurement values and return the result in a specified format.


Context and available tools

In the scripting environment, you have access to the following variables and helper functions:

  • Global objects:

    • config - sentinel configuration (e.g. rule parameters)
    • device - device object (e.g. device.EUI)
    • valuesArr - list of measurement values for the device
    • channelMap - a map of the device's measurement channels
  • Helper functions:

    • getValue(measurement) - retrieves the last value of the indicated measurement for the current device
    • get_measurementIndex(eui, measurement, deviceChannelMap) - returns the index of the measurement in the data structure
    • get_value(eui, measurement, values, deviceChannelMap) - retrieves the measurement value for the indicated device
    • get_delta(eui, measurement, values, deviceChannelMap) - retrieves the increment (delta) of the measurement value for the indicated device
    • conditionsMet(measurement, value) - returns the formatted result when the condition is met
    • conditionsMetWithCommand(measurement, value, commandTarget, command) - as above, with an additional command
    • conditionsNotMet() - returns an empty result when the condition is not met

Requirements for the checkRule function

  • The function does not accept arguments.
  • The function must return a string
    • If conditions are met: use conditionsMet(...) or conditionsMetWithCommand(...)
    • If conditions are not met: use conditionsNotMet()
  • The function should use helper functions to retrieve measurement values.
  • You can implement any conditional logic, such as comparisons, mathematical operations, complex rules.

An example of a simple implementation

def checkRule(): v1 = getValue("temperature") v2 = getValue("humidity") if v1 is None or v2 is None: return conditionsNotMet() if v2 - v1 > 10: return conditionsMet("temperature", v1) return conditionsNotMet()

Example with command

def checkRule(): temp = getValue("temperature") if temp is not None and temp > 30: return conditionsMetWithCommand("temperature", temp, "fan", "ON") return conditionsNotMet()

Notes

  • The function should be clean - do not modify global structures, except for reading data.
  • If you need other measurements or logic, you can use the passed objects and functions.
  • The result of the function is interpreted by the system - the format of the string is important.

Debugging

  • You can use javaLogger.info("...") to log information while the script is running.
  • If the function does not return the expected result, check if the retrieved values are None.

Summary:
Your task is to implement the checkRule function, which, based on the measurement data and business logic, returns the corresponding string informing the system that the condition is met or not met. Use the available helper functions and keep the code readable.

© 2023-2025 Grzegorz Skorupa