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 """
checkRule
functionThe 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.
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 devicechannelMap
- a map of the device's measurement channelsHelper functions:
getValue(measurement)
- retrieves the last value of the indicated measurement for the current deviceget_measurementIndex(eui, measurement, deviceChannelMap)
- returns the index of the measurement in the data structureget_value(eui, measurement, values, deviceChannelMap)
- retrieves the measurement value for the indicated deviceget_delta(eui, measurement, values, deviceChannelMap)
- retrieves the increment (delta) of the measurement value for the indicated deviceconditionsMet(measurement, value)
- returns the formatted result when the condition is metconditionsMetWithCommand(measurement, value, commandTarget, command)
- as above, with an additional commandconditionsNotMet()
- returns an empty result when the condition is not metcheckRule
functionconditionsMet(...)
or conditionsMetWithCommand(...)
conditionsNotMet()
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()
def checkRule(): temp = getValue("temperature") if temp is not None and temp > 30: return conditionsMetWithCommand("temperature", temp, "fan", "ON") return conditionsNotMet()
javaLogger.info("...")
to log information while the script is running.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.