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 ""
checkRule functionThe 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.
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 – map of the device’s measurement channelsUtility functions:
getValue(measurement) – retrieves the latest value of the specified measurement for the current deviceget_measurementIndex(eui, measurement, deviceChannelMap) – returns the measurement index in the data structureget_value(eui, measurement, values, deviceChannelMap) – retrieves the measurement value for the specified deviceget_delta(eui, measurement, values, deviceChannelMap) – retrieves the change (delta) in the measurement value for the specified deviceconditionsMet(measurement, value) – returns a 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 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.