Rule Scripts

If the "Use script" option is selected when defining a rule, the user can enter their own function code, which will be executed as part of the rule. The Python function must be named checkRule, take no arguments, and return a string value.

def checkRule():
    return ""

Developer documentation: Implementation of the checkRule function

Purpose of the function

The checkRule function is the primary location where you should implement the logic for checking alarm conditions or rules for an IoT device in the Signomix Sentinel system. This function should use the provided tools to retrieve 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 – map of the device’s measurement channels
  • Utility functions:

    • getValue(measurement) – retrieves the latest value of the specified measurement for the current device
    • get_measurementIndex(eui, measurement, deviceChannelMap) – returns the measurement index in the data structure
    • get_value(eui, measurement, values, deviceChannelMap) – retrieves the measurement value for the specified device
    • get_delta(eui, measurement, values, deviceChannelMap) – retrieves the change (delta) in the measurement value for the specified device
    • conditionsMet(measurement, value) – returns a 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 accepts no arguments.
  • The function must return a string:
    • If the conditions are met: use conditionsMet(...) or conditionsMetWithCommand(...)
    • If the 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, or complex rules.

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 a 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 pure —do not modify global structures, except for reading data.
  • If you need other measurements or logic, you can use the passed-in objects and functions.
  • The function’s return value is interpreted by the system—the string format 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 that the retrieved values are not ` None`.

Summary:
Your task is to implement the checkRule function, which, based on measurement data and business logic, returns an appropriate string informing the system whether a condition is met or not. Use the available helper functions and ensure your code is readable.

© 2023-2025 Grzegorz Skorupa