Example Formulas


ExampleResultDescriptions
Mathematical Expression1+1*23

2/2+12

(2+2)/22




String operations"a" + 1a1

"a" + "b"ab




With Functionsbase64Encode("a")YQ==




With device attributes"${firstName}" + " " + "${lastName}"If firstName is Tyler
If lastName is Griffith
result = Tyler Griffith


${a} + ${b}if a is 1
if b is 2
result =3


"${a}" + "${b}"if a is 1
if b is 2
result =12





Self referencing formula${a} + 1If the old value of a is 1, then the new value is 2This can be used count the number of times an object got updated




Conditional Logic(${a} == 1)? "Success" : "Failure"


(${a} == 1 || ${b} == 1)? "Success" : "Failure"


(${a} == 1 && ${b} == 1)? "Success" : "Failure"


equals("${a}", "true") ? "Success" : "Failure"





Conditional ActionsexecuteAction(${updateAvailable} == 1 ? "<actionId>" : "")
Here actionId may represent the deviceId of a Global Action




Old and new value of an attributeexecuteAction($OLD{a} != ${a} ? "<actionId>" : "<anotherActionId>")
executing an action if the value of "a" has changed otherwise executing another action




Counting the number of times a filed is updated, reseting counter to zero after a specified count value$OLD{temperature} != ${temperatures} ? ${a}+1: (${a} > 20 ? 0: ${a})

Formulas with Timestamps or Longs${last_mqtt_timestamp}l / 1000         or                                                       timestamp_to_datetime(${last_mqtt_timestamp}l,  "MM/dd/yyyy hh:mm:ss a")                                                Add L after {}








Using attributes from a referenced object${referenceObjectAttributeJSONKey__r.attributeJsonKey}  Ex ${token__r.refresh_token}



Supported Functions

 



FunctionDescriptionArguments
1toString(Object arg)Converts to stringargument can be a literal or a field name in a object type
2timestamp_to_datetime(long ts, String format, String timeZone)returns String representation of date time in the specifid format1. 13 digit timestamp
2. Format - it can be any java supported date time format string
3. timeZone - Examples of timeZone strings - "PST", "America/Los_Angeles", "GMT-8:00"
3timestamp_to_datetime(long ts, String format)returns String representation of date time in the specifid format in GMT timezone1. 13 digit timestamp
2. Format - it can be any java supported date time format string
4timestamp_to_datetime(long ts)returns String representation of date time in the "MM/dd/yyyy HH:mm:ss" format in GMT timezone1. 13 digit timestamp
5epoch_to_datetime(long ts, String format, String timeZone)returns String representation of date time in the specifid format1. 10 digit timestamp
2. Format - it can be any java supported date time format string
3. timeZone - Examples of timeZOne strings - "PST", "America/Los_Angeles", "GMT-8:00"
6epoch_to_datetime(long ts, String format)returns String representation of date time in the specifid format in GMT timezone1. 10 digit timestamp
2. Format - it can be any java supported date time format string
7epoch_to_datetime(long ts)returns String representation of date time in the "MM/dd/yyyy HH:mm:ss" format in GMT timezone1. 13 digit timestamp
8epoch()returns current epoch (miliseconds)
9now()returns current time miliseconds
10today(String format, String timeZone)returns Today's date in String in specified format1. Format - it can be any java supported date time format string
2. timeZone - Examples of timeZone strings - "PST", "America/Los_Angeles", "GMT-8:00"
11today(String format)returns Today's date in String in specified format. Time zone defaults to GMT
12base64Encode(String str)returns base64 encoding of any string
13base64Decode(String base64Str)returns decoded string
14equals(String a, String b)returns Boolean - true / false
15executeAction(String actionId)executes an action
an action can be -
1. a mqtt publish to a topic with place holders with a json payload with placeholders
2. HTTP post with a json body with placeholders
3. invoking a lambda function to perform any custom task
actionId - it is the id of the action to be performed
16All java.lang.Math static methods can be used in formula fields

17Render Colors$
{status}
== 0 ? "renderColor(\"red\")" : "renderColor(\"green\")"

18Render a Link"renderLink(\"${scent_machine__r.name}\", \"/deviceDetails?device=$
{scent_machine}
\")"
Here is a sample formula that renders a link to the detail page of the reference field
19startsWith(String str1, String str2)-returns true if str1 starts with str2
20endsWith(String str1, String str2)-returns true if str1 ends with str2
21contains(String str1, String str2)-returns true if str1 contains str2
22equalsIgnoreCase(String str1, String str2)-returns true if str1 and str2 are identical while ignoring the case
23toLower(String str)

24toUpper(String str)

25subString(String str, int beginIndex)

26subString(String str, int beginIndex, int endIndex)





Using References and Account Attributes


 



Account FieldJSON Key
1Account Id${accountId}
2Name${accountId__r.name}
3Parent Id${accountId__r.parent_id}
4Address${accountId__r.address}
5City${accountId__r.city}
6State${accountId__r.state}
7Country${accountId__r.country}
8Postal Code${accountId__r.postal_code}
9Phone Number${accountIdr.phone_number}