Datacake Docs
  • Welcome
  • Get Started
  • Changelog
  • Best practices
    • Best practices: Getting started
    • Best practices: Resolution (Timeframe)
    • Best practices: Dashboards
    • Best practices: Reports
    • Best practices: Grouping Devices
  • Datacake LNS
    • Getting Started
    • Gateways
      • Milesight LoRaWAN Gateway - UG6x
      • RAKwireless WisGate Edge Light 2
    • Devices
    • Add Devices without Gateway
  • Device
    • Product
    • Configuration
    • Claiming
    • Historical Data
    • Database
      • Configuration Fields
      • Fields
        • Manual input
        • Field Roles
        • Formulas
        • Mapping Fields
      • Data retention & Datapoints
      • Examples
        • Mapping 4-20mA Signals
        • Converting Units
  • Dashboards
    • Global Dashboards
      • Setting Homepage
    • Device Dashboards
    • Multi-Device Dashboards
    • Widgets
      • Value Widget
      • Chart Widget
      • Image Map
      • Map Widget
      • Text Widget
      • SOS Widget
      • Boolean Widget
      • iFrame Widget
      • Downlink Widget
      • Set Value Widget
      • Measurement List Widget
      • Heatmap Widget
      • Table Widget
      • Image Widget
  • Portal
    • Multi-Tenancy (Workspaces)
    • Reports
      • Energy Report
    • Administrators
    • Members
      • API Users
    • Security & Privacy
    • Billing
      • Support Packages
      • VAT Exemption / Tax ID
      • SMS Credits
      • Access Invoices
      • Unused time and Remaining time in Invoices (Prorations)
      • Codes
    • White Label
    • Rules
      • Legacy Rule Engine
        • Sending notifications via Telegram
      • New Rule Engine
        • Rule Engine Table Overview
        • Copy/Paste and Template Functionality
        • Advanced Rule Engine E-Mail and Webhook Templates
        • Time Restrictions
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
    • Configuring LNS
      • The Things Stack (TTN / TTI) Automated Setup
      • The Things Stack (TTN / TTI) Manual Setup
      • Loriot
      • Kerlink Wanesy
      • Helium
      • ChirpStack
      • Tektelic
      • Actility ThingPark
      • Senet
      • Milesight Gateway
      • KPN
    • Downlinks (LoRaWAN)
      • Set Time Frame
    • Securing Webhooks
    • Payload Decoders
      • Location and GPS
      • Access Gateway Metadata
      • Access Measurements
      • Global Variables
    • Using Cayenne LPP
    • Converting Payload
  • Generic API Devices
    • HTTP Downlinks
  • Integrations
    • MQTT
    • Particle
      • Get Started
      • Adding Integrations
      • Decoding Payloads
      • Calling Functions
      • Templates
        • Particle Tracker One
    • Incoming Webhooks
    • Outgoing Webhooks
      • Securing Outgoing Webhooks in Datacake
    • Golioth
    • Blues Wireless Notecard
    • Sigfox
    • Swarm Asset Tracker
    • Grandcentrix Modbus Cloud Connect
    • YuDash LYNX IoT Gateway
    • Dragino NB-IoT
      • Changing NB-IoT Bands
    • Hardwario CHESTER
    • 1NCE OS
  • API
    • Exporting Data
    • Record Measurements via API
    • Node RED to Datacake
    • Generate Access Token
    • Internal MQTT
      • Get Started
      • MQTT Documentation
      • MQTT over WebSocket
      • Example Code
    • GraphQL API
      • Using GraphQL
      • Device Creation
      • Tutorials
        • Read Group via Tags
  • Guides
    • Python
    • Send Slack Notifications
    • Forward Data to Cake Red
    • Multiple Data Feeds
    • Automated Dynamic Downlinks
    • Ingesting JSON Data into Datacake API Devices
    • Working with Default HTTP Decoder on API Devices and Code Examples
    • Accessing Measurements in Decoders
    • Connecting Datacake to Notion Using Zapier
    • How to set up and use location on non-GPS devices
    • How to integrate with AWS IoT Core
    • How to Schedule Mass-Downlinks (Multicast) using Datacake Rule Engine
    • How to Map Sensor Values to Ranges or Booleans, Strings using Mapping Fields
    • Understanding Internal vs. External MQTT Brokers on Datacake
    • Sending UDP Messages between 1NCE OS and Datacake
    • Concepts of LoRaWAN Payload Decoders on Datacake
    • How to check if a value stays above or below limits for given time
Powered by GitBook
On this page
  • Steps:
  • Creating the Rule:
  • Select the Product:
  • Set Trigger
  • Condition Setup
  • Select Trigger:
  • Configure the Email Notification Action:
  • Example Email Notification Content:
  • How it works
  • Explanation of Timerange "Min" and "Max" Operations
  • How to Use "Min" and "Max" for Continuous Conditions
  • Why This Method Works
  • Important Notes for Customers
  • Rule Templates
  • Template: Alert for Temperature Between 6°C and 10°C Persisting for 30 Minutes
  • Template: Alert if Temperature is Above 10°C for 30 Minutes

Was this helpful?

  1. Guides

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 5 months ago

Was this helpful?

Documentation for Datacake Rule Engine: Monitoring a Temperature Field for Values Below -10°C for at Least 15 Minutes

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.

Steps:

Creating the Rule:

  • 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).

Select the Product:

  • 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.

Set Trigger

  • 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.

Condition Setup

  • 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.

Select Trigger:

  • 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.

Configure the Email Notification Action:

  • 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"]}}").

  1. Save and Enable the Rule:

    • Once configured, save the rule and ensure it is Enabled to start monitoring.

Example Email Notification Content:

  • Subject: Fridge Device Name is below -10°C for 15 minutes

  • Message:

    Dear recipient,
    
    This is an automatic notification to inform you that the device `Device Name` has been below -10°C for 15 minutes, activating the rule `Temperature below -10°C for 15 Minutes`.

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.

How it works

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:

Explanation of Timerange "Min" and "Max" Operations

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.

How to Use "Min" and "Max" for Continuous Conditions

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:

  1. 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.

  2. 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.

Why This Method Works

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.

Summary Table

Desired Condition
Timerange Operation
Time Range
Condition

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

Important Notes for Customers

  • 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.

Rule Templates

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.

Template: Alert for Temperature Between 6°C and 10°C Persisting for 30 Minutes

{"name":"Rule: Alert for Temperature Between 6°C and 10°C Persisting for 30 Minutes","enabled":true,"tagsFilter":[],"timezone":"Europe/Berlin","productId":"5c2700ee-f046-4810-ac01-5d7aa70aff87","tagsFilterConjunction":"","triggerOnMeasurement":true,"triggerOnSchedule":false,"triggerOnDeviceGoesOffline":false,"triggerOnDeviceGoesOnline":false,"scheduleTriggerCrontab":"","triggerOnZoneEntry":false,"triggerOnZoneExit":false,"triggerOnZoneLengthOfStay":false,"zoneLengthOfStayTriggerMinutes":null,"zoneTagsFilter":[],"zoneTagsFilterConjunction":"","conditions":[{"rightOperand":{"hysteresis":0,"numberValue":6,"kind":"STATIC_NUMBER_VALUE"},"kind":"GREATER_THAN_OR_EQUAL","leftOperand":{"kind":"TRIGGERING_DEVICE_FIELD_VALUE","fieldId":"40fb7707-f315-42b3-b050-efae81a62335","timerangeOperation":{"start":"30 minutes ago","end":"now","kind":"MIN"}},"id":"3442a021-1f35-4b92-9cc2-6c28320b2f1e","conjunction":"AND","description":""},{"rightOperand":{"hysteresis":0,"numberValue":10,"kind":"STATIC_NUMBER_VALUE"},"kind":"LESS_THAN_OR_EQUAL","leftOperand":{"kind":"TRIGGERING_DEVICE_FIELD_VALUE","fieldId":"40fb7707-f315-42b3-b050-efae81a62335","timerangeOperation":{"start":"30 minutes ago","end":"now","kind":"MAX"}},"id":"a054728b-ea4d-4497-a52f-a16a69d03733","conjunction":"AND","description":""}],"whitelabelSiteId":"","createActions":[{"kind":"EMAIL","emailSubject":"Fridge {{ triggering_device[\"name\"] }} - Temperature Between 6°C and 10°C Persisting for 30 Minutes","emailReceivers":["simon+datacake@datacake.de"],"emailBody":"Dear recipient,\n\nthis is an automatic notification to inform you that the device **{{ triggering_device[\"name\"] }}** activated the rule {{ rule[\"name\"] }}.","description":"","fireWhenConditionsBecomeHot":true,"fireWhenConditionsStayHot":true,"minSecondsBetweenHotConditions":0,"fireWhenConditionsBecomeCold":false}],"updateActions":[]}

Template: Alert if Temperature is Above 10°C for 30 Minutes

{"name":"Rule: Alert if Temperature is Above 10°C for 30 Minutes","enabled":true,"timezone":"Europe/Berlin","tagsFilter":[],"tagsFilterConjunction":"","triggerOnMeasurement":true,"triggerOnDeviceGoesOffline":false,"triggerOnDeviceGoesOnline":false,"triggerOnSchedule":false,"scheduleTriggerCrontab":"","triggerOnZoneEntry":false,"triggerOnZoneExit":false,"triggerOnZoneLengthOfStay":false,"zoneTagsFilter":[],"zoneTagsFilterConjunction":"","productId":"5c2700ee-f046-4810-ac01-5d7aa70aff87","zoneLengthOfStayTriggerMinutes":null,"conditions":[{"leftOperand":{"kind":"TRIGGERING_DEVICE_FIELD_VALUE","fieldId":"40fb7707-f315-42b3-b050-efae81a62335","timerangeOperation":{"kind":"MIN","start":"30 minutes ago","end":"now"}},"rightOperand":{"kind":"STATIC_NUMBER_VALUE","numberValue":10,"hysteresis":0},"id":"229418d8-a235-4ae4-9b0a-f5e09d1e1338","description":"","conjunction":"AND","kind":"GREATER_THAN"}],"createActions":[],"updateActions":[{"kind":"EMAIL","emailBody":"Dear recipient,\n\nthis is an automatic notification to inform you that the device **{{ triggering_device[\"name\"] }}** activated the rule {{ rule[\"name\"] }}.","emailReceivers":["noreply@datacake.de"],"emailSubject":"Fridge {{ triggering_device[\"name\"] }} - Temperature is Above 10°C for 30 Minutes","id":"cbe7fe40-f097-4d0f-8eae-7acb49a5176a","description":"","fireWhenConditionsBecomeHot":true,"fireWhenConditionsStayHot":true,"fireWhenConditionsBecomeCold":false,"minSecondsBetweenHotConditions":0}],"deleteActions":[],"whitelabelSiteId":""}