How to check if a value stays above or below limits for given time
Learn how to configure Datacake to monitor if a sensor value remains above or below a specified limit for a set duration, ensuring accurate, time-based condition alerts.
Last updated
Learn how to configure Datacake to monitor if a sensor value remains above or below a specified limit for a set duration, ensuring accurate, time-based condition alerts.
Last updated
This guide outlines how to set up a rule in Datacake to monitor the internal temperature of a device and trigger an email notification if the temperature remains below -10°C for at least 15 minutes.
Go to the Rules section in Datacake.
Click on New Rule.
Name the rule (e.g., "Temperature below -10°C for 15 Minutes").
Select the appropriate Timezone (e.g., Amsterdam, Berlin).
Choose the Branding option for the email notification (e.g., Default Datacake branding).
Under the FOR section, choose the Product you want this rule to apply to (e.g., Fridge).
Decide if the rule should apply to all devices of this product or only specific devices.
Select "New Measurement" as trigger (this triggers the rule and the time-based checking of conditions) based on new measurement of any devices associated to the product.
Important Hint on Trigger Selection:
When using the New Measurement trigger, keep in mind that this trigger only works if the device sends measurements consistently. For example, if you want to check if the temperature is above 10°C for at least 15 minutes, the device needs to send data at least every 15 minutes (or more frequently). If the sending interval is longer than the condition’s time range, the rule may not activate as expected. Ensure the time range you set for checking conditions is longer than or equal to the device’s sending interval for accurate monitoring.
Click on Add Condition.
Set the Measurement Field to (for example) Temperature
.
For Timerange Operation, select Max
.
Specify the time range as from 15 minutes ago until now.
Under Operation, choose < (Less than)
.
Set the Comparison Value to -10°C
.
This condition checks if the maximum temperature over the last 15 minutes was below -10°C, ensuring the temperature has stayed below this threshold consistently.
Under the WHEN section, choose New Measurement.
This trigger will activate the rule each time a new measurement is received for the internal temperature field.
Click on Add New Action and select E-Mail Action.
In the Receivers field, add the recipient's email addresses.
Set a Subject for the email, such as Fridge {{triggering_device["name"]}} is below -10°C for 15 minutes
.
Write a Message that includes relevant information about the triggering device and rule (e.g., "This is an automatic notification to inform you that the device {{triggering_device["name"]}} activated the rule {{rule["name"]}}"
).
Save and Enable the Rule:
Once configured, save the rule and ensure it is Enabled to start monitoring.
Subject: Fridge Device Name
is below -10°C for 15 minutes
Message:
This setup will monitor the temperature and alert designated recipients if the temperature remains below -10°C for the specified duration, ensuring prompt response to critical temperature changes.
In the Datacake Rule Engine, the concept of "min" and "max" for timeranges can be a bit tricky to understand when you're trying to set up conditions like "Temperature above 10°C for at least 30 minutes" or "Temperature below -10°C for at least 60 minutes." Here’s how it works:
The Min and Max operations allow you to check the minimum or maximum value of a field (like temperature) over a specified time range, such as the last 30 minutes or 60 minutes. However, these operations don’t directly check if a condition (like “above 10°C” or “below -10°C”) is continuously true for the entire time period. Instead:
Max checks the highest value recorded in the selected time range.
Min checks the lowest value recorded in the selected time range.
Because of this, we can still use Min and Max to simulate conditions like "above 10°C for 30 minutes" or "below -10°C for 60 minutes," but it requires a slight shift in thinking.
To check if the temperature has been above or below a certain threshold for an entire duration, we set a condition based on the Min or Max value across that period. Here’s how this translates for each scenario:
Temperature above 10°C for at least 30 minutes:
Set the Timerange Operation to "Min."
Specify the range as "from 30 minutes ago until now."
Condition: If the Min temperature over the last 30 minutes is greater than 10°C, it means that the temperature has been continuously above 10°C for the entire duration.
Why This Works: If the lowest recorded temperature in the last 30 minutes is still above 10°C, then all measurements within this range were above 10°C, meeting your condition.
Temperature below -10°C for at least 60 minutes:
Set the Timerange Operation to "Max."
Specify the range as "from 60 minutes ago until now."
Condition: If the Max temperature over the last 60 minutes is less than -10°C, it means that the temperature has been continuously below -10°C for the entire period.
Why This Works: If the highest recorded temperature over the last 60 minutes is still below -10°C, then all measurements within this range were below -10°C, satisfying your condition.
By using "Min" and "Max," you’re effectively setting a rule that requires all measurements within the specified time range to stay above or below the threshold. This way, Min or Max indirectly ensures that the condition was met continuously over the entire time period.
Temperature above 10°C for 30 minutes
Min
From 30 minutes ago until now
Min temperature > 10°C
Temperature below -10°C for 60 minutes
Max
From 60 minutes ago until now
Max temperature < -10°C
Conceptual Shift: Think of "Min" and "Max" as a way to ensure the temperature stayed within a certain range for the entire period. If the Min is above a threshold, it means the temperature never went below that threshold. Similarly, if the Max is below a threshold, the temperature never rose above it.
Limitation: This approach does not directly check for the duration of a single measurement but instead verifies that every measurement within the range meets the condition, effectively fulfilling the "continuous" requirement.
This method allows you to set up rules that monitor conditions over time, even though the terms “Min” and “Max” don’t directly imply continuous monitoring at first glance.
You can copy the following JSON templates for the rule engine and paste those on a new rule. This will allow you to work with ready-to-go example rules for the complex setup.