Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
Create an Email Template for Event Handler
-
Hi all,
I'm trying to create a nice email template for event handler, but I really don't know hot to use it.
I need to add additional context to an binary data point trigger, showing last data of two additional data point.
Looking the documentation, I found this:
butwhen I try to replicate to my template isn't working.
Could someone help me this this? Thanks!!
-
Hi Matias,
isn't working
Should always be accompanied by a description of the failure.
Even though... that image has some issues, and I see you got it from the help.infiniteautomation.com page about custom email handlers. I will put something better there, since that image is riddled with problems.
For now, try,
<@subject>Hey - Stuff is happening with the automation system and I think you should know</@subject> <#if renderedHtmlPointValues??> <#list renderedHtmlPointValues as renderedPvt> ${additionalContext.temperature.deviceName} - ${additionalContext.temperature.name} - ${renderedPvt.value} - ${renderedPvt.time}<br/> </#list> </#if>
And be sure to add a point into the context with the key 'temperature'
Also it should be noted the renderedHtmlPointValues and renderedPointValues items are only added to the model if it's a point event and the point that generated the event is running.
You could add recent values into the model yourself in the script by doing something like,
model.put("temperatureValues", temperature.last(10));
And then using the <#list> to iterate over that, instead.
-
Thanks for your help Philip !
Putting "additionalContext" to variables works! But I have some doubts about :
model.put("temperatureValues", temperature.last(10));
If I use this code in the script windows, I have to call the "temperatureValues" variable into the code, like:
${temperatureValues.value}
Works in that way? And I need to put this variable inside the
<#list renderedHtmlPointValues as renderedPvt>
or isn't necessary?Thanks in advance!
-
You would loop over it, like,
<#list temperatureValues as pvt> <#-- do stuff with pvt, pvt.value, pvt.time --> </#list>
It's a List<PointValueTime> similar to renderedHtmlPointValues. It wouldn't have the rendering done to it, though.
-
Nice!! It worked pretty well. Thanks!
-
One more question.
How can I work with the results?
For example, when I use pvt.time, I get the timestamp only, and I need to show date and time format.
-
You may find this StackOverflow thread interesting: https://stackoverflow.com/questions/7846105/freemarker-model-convert-timestamp-in-milliseconds-to-date
TLDR
${pvt.time?number_to_datetime?string("YYYY-MM-dd HH:mm:ss")}
Didn't test again just now, but the number_to_date, number_to_time, number_to_datetime functions are what you're looking for.
-
Thanks !! That did the trick...