Variables
A variable is a placeholder in an action's text that is filled in from the event when the rule runs. Write it in double braces:
{{iotnode.name}} reported {{diff.temperature}} degrees
That one message serves a thousand devices. Without variables you would need a rule per device, each with the device's name typed into it.
Variables work in every text field of an action: an email title and body, an SMS body, an MQTT topic and payload, an HTTP body, headers and params, a log message, and a LoRaWAN downlink payload.
The settings panel lists the common ones under Available variables, and clicking one inserts it.
What you can reference
| Start the path with | And you get |
|---|---|
iotnode | The device document - its name, its contextual parameters, the latest value of every field |
diff | Only the values that changed in the report that started the rule |
updateDoc | The update as it was written |
condition | The condition that led here, and whether it entered or exited |
resourceId | The id of the device the run is for |
ruleV2 | The rule itself: name, description, _id, enabled, createdAt, updatedAt |
user | The id of the user the rule runs as |
actionNodeId | The id of the action block that is running |
Nothing else resolves. A path starting anywhere else comes out empty, which is deliberate - it stops a message reaching into parts of the platform it has no business quoting.
The ones you will use
| Variable | Resolves to |
|---|---|
{{iotnode.name}} | The device name |
{{iotnode._id}} | The device id |
{{ruleV2.name}} | The rule name |
{{diff.<field>}} | A value from this report, for example {{diff.temperature}} |
{{iotnode.contextMap.<key>}} | A contextual parameter, for example the floor or the room |
diff against iotnode is the same distinction the conditions page
makes. {{diff.temperature}} is the temperature just reported; {{iotnode.temperature}} is whatever
the device currently holds, reported now or last week.
An example
An email body for a temperature alert:
{{iotnode.name}} in {{iotnode.contextMap.room}} is at {{diff.temperature}} degrees.
Reported {{iotnode.reportedAt}} by rule "{{ruleV2.name}}".
What happens to the value
- A number or a string is inserted as it is.
- An object or a list is inserted as JSON.
- A path the event does not carry resolves to an empty string.
That last one is worth watching. An email that arrives reading "is at degrees" is a mistyped path, not a missing reading, and the run history shows what the event actually contained.
The exception is the LoRaWAN downlink payload. A downlink is a byte frame rather than prose, so an unresolved variable fails the action instead of quietly sending a shorter, different command.