Introduction to Expressions

Expressions are a powerful way to perform calculations and manipulate data within rules. Expressions are commonly used to execute math operations as well as date, string, and boolean functions. These operations and functions can either be performed on their own or combined with data from variables

📄 Are you already familiar with expressions and searching for a list of functions? Consult our date functions and general functions documentation.

Using Expressions

The primary approach for using expressions is the 'Expression' source when using the Set Variable action in a rule. 

After selecting 'Expression' as the source type for your Set Variable action, the Expression Editor will be displayed. You can type basic math expressions in the editor and then tap the 'Tap to Evaluate' text just below the editor which will perform the calculation and display the result. 

Inline Expressions

You can also use 'inline expressions' in any text field that offers a +VARIABLE button to the right of the text field. This is commonly found in Notifications and HTTP Actions. When you add a variable, you may notice that the variable is between two squiggly brackets {{ }}  when you edit the text field. These squiggly brackets indicate an inline expression and you can enter an expression using math operators or date functions here as well. 

If you want the full expression editing experience, including the ability to test your expression with 'Tap to Evaluate', be sure to use the expression source mentioned above. 

Here's an example of a simple expression that adds '10' to a current temperature variable. 

Assuming the temperature is 100, the final text would be

The new limit is: 110

Keep in mind that you can use the main Expression Editor to evaluate an expression and store it in a variable, then a separate action to inject the variable into a text field. This is a great approach that combines the functionality of the expression editor with the ease and flexibility of being able to inject variables into text fields, like notifications.

Math Operators

Many of the traditional math operators you are accustomed to are available:

Operator Name Example
( ) Grouping 2 * (3 + 4)
+- Addition, Subtraction 10 + 2 - 1
*/ Multiply, Divide (5 * 4) / 10
^ Power 2 ^ 10
% Modulus 20 % 10

Variables

The expression feature is also capable of including variables within your calculations. When using the main expression editor, you can begin typing the  $  symbol and an autocompletion menu will come up displaying a list of your variables.

You can either continue typing to narrow the list of variables down or you can use the up/down arrow keys on your keyboard and press Enter to select a variable. 

You can then use the full suite of math operators (or date functions) combined with your variables to perform creative calculations. For example, you could average two values with a simple expression:

($temperature1 + $temperature2) / 2

Date Functions

There's also a number of date related functions including features for formatting dates and performing basic math on dates. You can find the full set of documentation on date functions in the following article:

Be sure to click through the reference format values link within the article to better understand what kind of formats can be used in formatting functions such as formatDate()  and for parsing functions like date() .

Some quick examples:

formatDate(now(), 'YYYY-MM-DD') //2022-09-23 (en-US default locale)
formatDate(now(), 'LLL', 'pl')  //23 września 2022 17:58 (Polish locale)
humanizeDuration(60 * 60 * 1000, true) // "in an hour"
addDays(now(), 1)   //tomorrow (at the current time)
endOfDate(now(), 1) //23:59 tonight
setDatePart(startOfDate(now()), 'hour', 4) //4:00 AM today

Note that timezone information is pulled from your location(s) that have a geolocation set. If you don’t have a timezone set on any of your locations, the system falls back to UTC.

Other Features

Expressions support a broad range of data types including numbers, booleans, strings, arrays, and objects. If you’re looking for specific features or functions, please let us know as we’re still working on building out documentation. 

Documentation on general numeric, string, boolean, and array functions is available here:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.