Send multiple point value in alarm text
-
Hi sky_watcher,
That is because the list you are iterating in the FTL is the
renderedHtmlPointValues
which is included in the model for the point that triggered the event. Instead, you would want to iterate over the lists you added to the model (and probably separately), so<#if pressureValues??> <#list pressureValues as index,value> ${additionalContext.pressure.deviceName} - ${additionalContext.pressure.name} - ${value.value} - ${value.time}<br/> </#list> </#if>
We have to <#list> over
index, value
because a JavaScript list is backed by a Map with the natural numbers as the keys, so it's more like looping over a map. -
@phildunlap Thank you Phil, your example works but it is a way to format the value?
For value I have to many decimals and for time it in a wired format. -
You'll have to manually get the values rendered as desired. Presumably that'll be the point's text renderer, so you could have a function like this, perhaps in a global script:
function getRenderedValues(variableName, limit) { var renderedValues = []; var textRenderer = CONTEXT_POINTS[variableName].getVO().getTextRenderer(); if(textRenderer === null || textRenderer === undefined) return renderedValues; var rawValues = p.last(10); for(var k = 0; k < rawValues.length; k+=1) { //See com.serotonin.m2m2.view.text.TextRenderer // for understanding the second argument renderedValues.push(textRenderer.getText(rawValues[k], 2)); } return renderedValues; } //Remove the print portion if a global script, or after testing print(getRenderedValues("p", 10));
-
Alternatively look into Freemarkers format options
https://freemarker.apache.org/docs/ref_builtins_date.html
https://freemarker.apache.org/docs/ref_builtins_number.html -
@phildunlap Thanks Phil, I see that the script works grate but I'm not quite sure how to transfer the result of the function to the model.put("temperatureValues", temperature.last(5));
And how can I render the time?
Thank you!
-
@jared-wiltshire I've seen your post after writing to Phil...
I'll look into the docs and come with an answer.
Thank you Jared!
-
Remove the print statement and do,
model.put("temperatureValues", getRenderedValues("temperature", 5));
-
@phildunlap I tried this before, but without removing print statement and did not worked. I tried again now after I've removed the print statement and is not working.
-
My mistake! The function probably should be doing,
function getRenderedValues(variableName, limit) { var renderedValues = []; var textRenderer = CONTEXT_POINTS[variableName].getVO().getTextRenderer(); if(textRenderer === null || textRenderer === undefined) return renderedValues; var rawValues = p.last(10); for(var k = 0; k < rawValues.length; k+=1) { //See com.serotonin.m2m2.view.text.TextRenderer // for understanding the second argument in getText renderedValues.push( {"value": textRenderer.getText(rawValues[k], 2), "time": rawValues[k].time} ); } return renderedValues; }
It was making rendered values as a list of strings, so there was not a .value or .time property for the FTL to refer to. Instead will make it a list of objects with those properties.
-
@phildunlap Still doesn't work, I don't receive any email after this modification.
-
Whoops, FTL issues,
<#if pressureValues??> <#list pressureValues as index, value> ${additionalContext.pressure.deviceName} - ${additionalContext.pressure.name} - ${value.value} - ${value.time}<br/> </#list> </#if>
There were related messages in the log file.
-
@phildunlap Yes, now work perfect for value, but the time is still in that weird format.
-
Maybe you can try
${value.time?number_to_datetime}
in the FTL or you could use a SimpleDateFormatter in the script to store it in the format you want. -
@phildunlap Yes, is working now.
Thank you a lot! Have a great day!
-
@phildunlap Hi Phil, I have to reopen this discussion, today when I played around with the email feature, I was trying to customize the email and I've noticed that the time when the alarm was triggered is not the same with the time for the values, and this make sense because I record that values in the database every minute.
So I have a question, can I print there the instant value, not a recorded value from my data base? Because when the alarm is triggered that point can have another value that the one that is last recorded in my database.
-
I think what you're looking for could be found in the Mango/ftl/ files. The eventData.ftl files shows you can do
${evt.prettyActiveTimestamp}
evt
is a https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/serotonin/m2m2/rt/event/EventInstance.java so you can use those getter functions in the FTL, as prettyActiveTimestamp does. -
@phildunlap Thank's, if I put this line I get the same time for all the points.
${evt.prettyActiveTimestamp}
But my question is the value in real time or is last value from my database?
-
Are you saying you put that in the loop?
But my question is the value in real time or is last value from my database?
I don't understand what you're asking.
-
@phildunlap Ok, let say that my temperature point is recorded in my database every 3 minutes, but my point is updated form PLC at every 5 seconds, (the record at every 3 minutes is made by an average off all readings between those 3 minutes, correct?).
If my alarm point occurs somewhere between those 3 minutes intervals which value is displayed for T0? Instant value or the last value recorded?
I came with this problem when I saw that the timestamp for the alarm trigger point and T0 are different.
I hope I was clear enough :)
-
The answer has some to do with the configuration of the event detector. For instance, if you have a high limit detector and it does not have a duration, then the timestamp of the event should be the time that the polling got a value above the limit. If it did have a duration, then it should be the time that the polling was above the limit, provided it stayed above the reset limit for the duration, plus the duration. This is why the event text would include that the duration was exceeded.
Interval logging is not the driver of the event detectors for the point they are on. If you wish to have event detectors on the interval logged average, you can use a meta point with its context event set to
Logged
.