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
  • Wireless IoT Hub
    • Overview
    • Datasheet
    • Getting Started
  • 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
        • Actions
          • Set Value
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
        • How to create a device without a product template
    • 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
  • Introduction
  • Why Use Template Language?
  • What Can You Do with Template Language in Notifications?
  • Getting Started
  • Including Sensor Data
  • Including Measurement Timestamp in UTC
  • Including Measurement Timestamp in Local Timezone
  • Custom Date Formatting
  • Combining Information
  • Including Hyperlinks

Was this helpful?

  1. Portal
  2. Rules
  3. New Rule Engine

Advanced Rule Engine E-Mail and Webhook Templates

This guide shows you how you can use the rule engines template language to create custom alerting messages that include sensor information.

Introduction

The Rule Engine in our Datacake IoT platform is a powerful feature that enables you to automate actions and send notifications based on data from your IoT devices. As of July 4, 2023, our Rule Engine supports the inclusion of measurement timestamps in notifications. This document guides you through the utilization of the Django Template Language within the Rule Engine for crafting highly informative and customized notification content.

Why Use Template Language?

When sending notifications, whether it's an email, SMS, or webhook, it’s often necessary to include data from sensors, and timestamps, and sometimes perform some conditional logic. This might include formatting dates, displaying values, or sending different messages based on sensor readings. The Django Template Language allows for dynamic inclusion and manipulation of content, based on the data and logic you specify.

What Can You Do with Template Language in Notifications?

  • Dynamic Content: Include real-time sensor data and timestamps in your notifications.

  • Formatting: Customize the formatting of timestamps to make them more readable or to conform to specific standards.

  • Conditional Logic: Use if-else statements to send different messages depending on the data.

  • Loops: Loop through lists of data, such as multiple sensor readings.

  • Combining Information: Craft comprehensive messages by combining multiple pieces of information.

  • Adding Hyperlinks: Include links to dashboards or additional resources.

Getting Started

This document contains examples and syntax that will help you get started with using the Django Template Language in Rule Engine notifications. From simply displaying sensor data to more advanced conditional logic, these examples will guide you through creating informative and dynamic notifications.

Please proceed through the examples to understand the various features and possibilities. Keep in mind that while this documentation provides a strong foundation, the Django Template Language is very versatile and you may find even more creative ways to utilize it in your notifications.

Including Sensor Data

Include the value of a sensor measurement in your notification. When writing templates for webhooks or emails, it’s important to use the correct path to access your device data. Some ways of referencing the measured values of your devices is:

Temperature: {{ triggering_device["values"]["TEMPERATURE"] }}°C

But it could also be:

Temperature: {{ triggering_device["measurements"]["TEMPERATURE"] }}°C

💡 Tip: Use debug_keys to Inspect Your Data

To figure out the correct paths for your template, add a temporary key to your payload that prints the entire triggering_device object or a subset like measurements. Add "debug_keys": "{{ triggering_device }}" to your webhook to include the full device object in your outgoing webhook or email, so you can visually confirm the structure and keys available at runtime.

Once you’ve identified the correct paths, you can safely remove the debug line.

Including Measurement Timestamp in UTC

Include the timestamp of the measurement in UTC ISO format.

Measurement Time (UTC): {{ triggering_device["timestamps"]["TEMPERATURE"] }}

Including Measurement Timestamp in Local Timezone

Include the timestamp of the measurement in the rule's timezone using the datetime filter.

Measurement Time (Local): {{ triggering_device["timestamps"]["TEMPERATURE"] | datetime }}

Timestamp is provided in the time zone you selected on your rule! Make sure to select the correct one.

Custom Date Formatting

Customize the date format using strftime syntax.

Measurement Time (Formatted): {{ triggering_device["timestamps"]["TEMPERATURE"] | datetime("%A, %B %d, %Y %I:%M %p") }}

Combining Information

Combine multiple pieces of information into a single message.

Temperature is {{ triggering_device["values"]["TEMPERATURE"] }}°C, measured at {{ triggering_device["timestamps"]["TEMPERATURE"] | datetime }} ({{ triggering_device['timestamps']['TEMPERATURE']|date:"c"|timesince }} ago).

Including Hyperlinks

Include a hyperlink, possibly to a dashboard or additional resources.

For more details, visit the <a href="https://example.com/dashboard">dashboard</a>.

Note: You can combine these examples and syntax to create complex and informative notifications according to your requirements.

Last updated 2 months ago

Was this helpful?