Configure Email Body for Email Node

Hello! I am using an Email Node that sends out an email whenever an event of any level is generated. I would like to have the body of the email include the name of the device that generated the event, as well as why the event was generated.

I looked for documentation on how to do this but could not find any. Any feedback on how to include info like this and others?

Assuming the data you wish to include is available on your workflow payload, this should be as simple as referencing the values with templates as is done with our other workflow nodes.

For example, if your payload looks like the following (shortened for legibility) …

  "event": {
    "subject": "Temperature Too High",
    "data": {
      "temp": 95
  "device": {
    "name": "My Great Device"

… and an email body of …

<p>The device <strong>{{}}</strong> created the event "{{event.subject}}" with the following data:</p>

… that would output the following in the email body …

<p>The device <strong>My Great Device</strong> created the event "Temperature Too High" with the following data:</p>
  "temp": 95

Our built-in template tester is a great resource for testing out your string templates within the workflow editor. I recommend utilizing this to get the results you are looking for out of your sample payloads.

And a follow-up I thought of before trying what you just suggested is, right now the emails are generated by an event caused by any device, whereas I want it to be localized solely to events generated by devices in a specific user experience group. How can this be achieved using a conditional node?

I appreciate all the help you have provided on these forums and for all the questions I have had, being a new user to Losant it has been very beneficial.

Instead of a Conditional Node, I would use a Device: Verify Node. You can pass in a device ID (which I assume would come from the initial payload of your Event Trigger) and compare that device ID against an Experience Group to verify association. The true path leads to your Email Node. The false path is a dead end.

I have that Device: Verify Node set up, but is there a way to streamline this process for a large number of devices to compare against? It seems that this node is only comparing one device to the group, I need to compare between 20-150 devices against a group.

Sorry, but now I’m a little confused given where we started.

An event can be associated with 0 or 1 devices. If set on event creation, the deviceId property is stored on the event object, and that is available on a workflow payload fired from an Event Trigger at the payload path of data.deviceId.

As I suggested before, that single device can be checked for association with an Experience Group using the Device: Verify Node.

So what is the use case where you are trying to compare multiple devices in a single workflow execution against an Experience Group?

I may have a different suggestion based on what you are trying to do but at a high level, you could achieve this by …

  • Returning a set of devices using a Device: Get Node.
  • Using a Loop Node in serial mode, iterate over all the devices.
  • Inside the loop, use a Device: Verify Node to check if the current iteration is associated with the group.
  • If all devices must be associated with the group and you encounter one that is not …
    • Connect a Mutate Node to the false path of the Device: Verify Node and set a value (i.e. dissociationEncountered = true).
    • Use a Break Node to exit the loop early and return the value set on the payload with the Mutate Node.
  • After the Loop Node (outside the loop), use a Conditional Node to check for the presence of that property you set with the Mutate Node.

My apologies for the confusion.

My end goal is to have a system in place that will send emails when events are generated by devices in a specific experience group. The devices are sending data at different increments, and so some values would send emails to a couple users, while higher values would send emails to more users.

I was just starting out by triggering the emails off of the event node for practice.

Please advise if you have any other questions.

Thank you,

Based on that, I think everything I’ve recommended so far is the way to go. Think of this as three separate processes.

First, your devices all report state through whatever means you have in place - by reporting to our MQTT broker, through our REST API, or through a workflow using the Device State Node.

Second, you have a short workflow that fires off of a Device State Trigger, configured to fire for a set of devices you define through IDs and/or tags. That workflow looks at the incoming values and determines if an event should be recorded, and if so, does so using an Event: Create Node (with the event associated with the device that caused the workflow execution). This workflow fires whenever any of your target devices reports state, regardless of when or how often that happens per device.

Third, you have an additional workflow that fires off an Event Trigger (which would execute immediately after an event is logged in your previous workflow). Based on the data provided in the event, that workflow decides if an email should be sent by checking if the device ID associated with the event is associated with the Experience Group in question using a Device: Verify Node. Based on other data you pass through the event (i.e. the event “level” or some arbitrary data), you can also write in some logic determining if the email should go to additional users.

Hello Dylan,

I think where I am getting tripped up is where the “experience group filter” should be placed. I would think that the email workflow (which seems to be the third workflow that you described) only needs to include an event node such that everytime an event occurs → check to make sure it is part of the proper experience group → send an email to the necessary parties with the information from the event with the associated device information. I am still a little lost on how this should be done.

@Kyle_Wisbrock The Device: Verify Node is what serves as the filter.

  1. An event comes in with a device ID attached to it.
  2. The Device: Verify Node compares that device ID to an Experience Group of your choosing.
  3. If there is an association, the true path is taken out of the node and then you can send an email to the people of your choosing.

Because of this confusion, I took a look in your account and I cannot find any workflow in any application where you have implemented the suggestions I’ve made so far. If you can give me a workflow ID where you’ve attempted to set this up and are running into issues, I may be able to pinpoint where this is not working for you as expected.

The workflow where I am trying to implement the Email feature is: 620e75b9b19bac31e7142efc. Right now it is just an event node, a device: verify node, and an email node. In an ideal setting, the device: verify node would look for devices part of a specific experience group only, but from what I can tell I can only set it to a single specific device, which is then compared to an experience group. I do not think it needs to be much more complex than this to achieve what I need.

I see now, thanks. When I looked before it was just an Event Trigger and an Email Node.

In your Device: Verify Node, you are choosing an explicit device from your application. Instead, you want that to be a variable from your payload - specifically, in the “Device ID Template” field, enter a value of “{{data.deviceId}}”, which will pull the device ID from the event that fired the workflow. Now you are dynamically comparing the event’s associated device to your Experience Group.

If you’re not comfortable working with templates (variables) in workflows, we have a number of resources in our documentation; in Losant University; and a Deeper Dive on Advanced Templating. I recommend checking those out.

Yeah, I filled in a specific device just so that the workflow could be saved and shown to you with the verify node in place. I was not sure how to include the variable as you explained, and I will certainly take a look at those additional resources to learn more, as I am still getting my feet wet with Losant and do not have a programming background which I feel would help.

Kyle, the way we do this is by creating a data table which is indexed by the lookup key (experience group, tag value, etc). The table contains the email addresses to send the notification too. The body itself is pretty generic based on the event and device types. The event handler grabs the information from the device (tags, group, etc), then does the data table lookup to find the addresses.

-Dave Kjendal (Senet)